PageRenderTime 55ms CodeModel.GetById 37ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/platform/unix/scaffold/view.d

http://github.com/wilkie/djehuty
D | 207 lines | 122 code | 61 blank | 24 comment | 2 complexity | 62753e0150e0eeca6384ef93724ca248 MD5 | raw file
  1/*
  2 * view.d
  3 *
  4 * This Scaffold holds the View implementations for the Linux platform
  5 *
  6 * Author: Dave Wilkinson
  7 *
  8 */
  9
 10module scaffold.view;
 11
 12import platform.vars.view;
 13import platform.vars.window;
 14
 15import platform.unix.common;
 16import platform.unix.main;
 17
 18import graphics.view;
 19import graphics.bitmap;
 20import graphics.graphics;
 21
 22import core.string;
 23import core.main;
 24import core.definitions;
 25
 26import io.file;
 27
 28import gui.window;
 29
 30//import console.main;
 31
 32// views
 33void ViewCreate(ref View view, ViewPlatformVars*viewVars)
 34{
 35	// code to create a view
 36
 37	viewVars.surface = Cairo.cairo_image_surface_create(Cairo.cairo_format_t.CAIRO_FORMAT_ARGB32, view.width(), view.height());
 38	viewVars.cr = Cairo.cairo_create(viewVars.surface);
 39
 40	viewVars.attr_list_opaque = Pango.pango_attr_list_new();
 41	viewVars.attr_list_transparent = Pango.pango_attr_list_new();
 42
 43	viewVars.attr_bg = Pango.pango_attr_background_new(0xFFFF, 0xFFFF, 0xFFFF);
 44
 45	viewVars.attr_bg.start_index = 0;
 46	viewVars.attr_bg.end_index = -1;
 47
 48	Pango.pango_attr_list_insert(viewVars.attr_list_opaque, viewVars.attr_bg);
 49}
 50
 51void ViewDestroy(ref View view, ViewPlatformVars*viewVars)
 52{
 53	// code to destroy a view
 54	Cairo.cairo_destroy(viewVars.cr);
 55	X.XFreePixmap(_pfvars.display, viewVars.pixmap);
 56
 57	if (viewVars.gc !is null)
 58	{
 59		X.XFreeGC(_pfvars.display, viewVars.gc);
 60		viewVars.gc = null;
 61	}
 62}
 63
 64void ViewCreateDIB(ref Bitmap view, ViewPlatformVars*viewVars)
 65{
 66	// code to create a DIB view
 67	viewVars.surface = Cairo.cairo_image_surface_create(Cairo.cairo_format_t.CAIRO_FORMAT_ARGB32, view.width(), view.height());
 68	viewVars.cr = Cairo.cairo_create(viewVars.surface);
 69
 70	viewVars.attr_list_opaque = Pango.pango_attr_list_new();
 71	viewVars.attr_list_transparent = Pango.pango_attr_list_new();
 72
 73	viewVars.attr_bg = Pango.pango_attr_background_new(0xFFFF, 0xFFFF, 0xFFFF);
 74
 75	viewVars.attr_bg.start_index = 0;
 76	viewVars.attr_bg.end_index = -1;
 77
 78	viewVars.bits_length = view.width() * view.height() * 4;
 79}
 80
 81void ViewCreateForWindow(ref WindowView view, ViewPlatformVars*viewVars, ref Window window, WindowPlatformVars* windowVars)
 82{
 83	// code to create a view for a window
 84
 85	int screen, depth;
 86
 87	windowVars.destroy_called = false;
 88
 89	screen = X.DefaultScreen(_pfvars.display);
 90	depth = X.DefaultDepth(_pfvars.display, screen);
 91
 92	int _width = window.width;
 93	int _height = window.height;
 94
 95	//create the back buffer
 96	viewVars.pixmap = X.XCreatePixmap(
 97		_pfvars.display, windowVars.window,
 98		_width, _height, depth);
 99
100	X.XSetWindowBackgroundPixmap(_pfvars.display, windowVars.window, X.None);
101
102	viewVars.gc = X.XCreateGC(_pfvars.display, viewVars.pixmap, 0, null);
103
104	//Set the buffer's window back reference
105	viewVars.cur_window = windowVars.window;
106
107	viewVars.surface = CairoX.cairo_xlib_surface_create(
108		_pfvars.display, viewVars.pixmap,
109		_pfvars.visual, _width, _height);
110
111	viewVars.cr = Cairo.cairo_create(viewVars.surface);
112
113	viewVars.layout = Pango.pango_cairo_create_layout(viewVars.cr);
114
115	viewVars.attr_list_opaque = Pango.pango_attr_list_new();
116	viewVars.attr_list_transparent = Pango.pango_attr_list_new();
117
118	viewVars.attr_bg = Pango.pango_attr_background_new(0xFFFF, 0, 0xFFFF);
119
120	viewVars.attr_bg.start_index = 0;
121	viewVars.attr_bg.end_index = -1;
122
123	Pango.pango_attr_list_insert(viewVars.attr_list_opaque, viewVars.attr_bg);
124
125	//Pango.pango_attribute_destroy(viewVars.attr_bg);
126}
127
128void ViewResizeForWindow(ref WindowView view, ViewPlatformVars*viewVars, ref Window window, WindowPlatformVars* windowHelper)
129{
130}
131
132void ViewResize(ref View view, ViewPlatformVars*viewVars)
133{
134	// code to Size a view, no concern needs to be taken
135	// to preserve the view's contents and the image within the view
136	// this is because of performance concerns, you don't necessarily care
137	// about such things...it is also similar to resizing anything dynamic
138
139	int _width = view.width();
140	int _height = view.height();
141
142	//make the buffer
143	X.XFreePixmap(_pfvars.display, viewVars.pixmap);
144
145	//create the Pixmap
146	viewVars.pixmap = X.XCreatePixmap(
147		_pfvars.display, viewVars.cur_window,
148		_width,
149		_height, X.DefaultDepth(_pfvars.display, X.DefaultScreen(_pfvars.display)));
150
151	//attach to cairo and pango
152	Pango.g_object_unref(viewVars.layout);
153
154	Cairo.cairo_surface_destroy(viewVars.surface);
155	Cairo.cairo_destroy(viewVars.cr);
156
157	viewVars.surface = CairoX.cairo_xlib_surface_create(
158		_pfvars.display, viewVars.pixmap,
159		_pfvars.visual, _width, _height);
160
161	viewVars.cr = Cairo.cairo_create(viewVars.surface);
162
163	viewVars.layout = Pango.pango_cairo_create_layout(viewVars.cr);
164
165	X.XFreeGC(_pfvars.display, viewVars.gc);
166
167	viewVars.gc = X.XCreateGC(_pfvars.display,
168		viewVars.pixmap, 0, null);
169}
170
171void* ViewGetBytes(ViewPlatformVars*viewVars, ref ulong length)
172{
173	length = viewVars.bits_length;
174	return Cairo.cairo_image_surface_get_data(viewVars.surface);
175}
176
177void* ViewGetBytes(ViewPlatformVars*viewVars)
178{
179	return Cairo.cairo_image_surface_get_data(viewVars.surface);
180}
181
182void ViewUnlockBytes(ViewPlatformVars* viewVars) {
183}
184
185uint ViewRGBAToInt32(ref bool _forcenopremultiply, ViewPlatformVars*_pfvars, ref uint r, ref uint g, ref uint b, ref uint a)
186{
187	if (!_forcenopremultiply)
188	{
189		float anew = a;
190		anew /= cast(float)0xFF;
191
192		r = cast(ubyte)(anew * cast(float)r);
193		g = cast(ubyte)(anew * cast(float)g);
194		b = cast(ubyte)(anew * cast(float)b);
195 }
196	return (r << 16) | (g << 8) | (b) | (a << 24);
197}
198
199uint ViewRGBAToInt32(ViewPlatformVars*_pfvars, ref uint r, ref uint g, ref uint b)
200{
201	return (r << 16) | (g << 8) | (b) | 0xFF000000;
202}
203
204
205
206
207