1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = 
27  * outPack = glgtk
28  * outFile = GLCapability
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = 
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * omit structs:
41  * omit prefixes:
42  * omit code:
43  * omit signals:
44  * imports:
45  * structWrap:
46  * module aliases:
47  * local aliases:
48  * overrides:
49  */
50 
51 module glgtk.GLCapability;
52 
53 public  import gtkglc.glgtktypes;
54 
55 private import gtkglc.glgtk;
56 private import glib.ConstructionException;
57 private import gobject.ObjectG;
58 
59 
60 
61 
62 
63 
64 // SNEAKY MIXIN PROBLEM:
65 //
66 // These need to be public imports
67 // or GLCompatibility will not compile
68 // as a mixin in other modules!
69 
70 // May as well be explicit about it:
71 
72 public import cairo.Context;
73 public import glgtk.GLWidget;
74 public import glgtk.GLWidget : widgetSetGLCapability = setGLCapability;
75 public import glgdk.GLWindow;
76 public import gdk.Event;
77 
78 version(Tango) {
79 	private import tango.core.Memory;
80 	} else version(D_Version2) {
81 	private import core.memory;
82 	} else {
83 	private import std.gc;
84 }
85 
86 
87 template GLCapability()
88 {
89 	
90 	GLfloat width = 0;
91 	GLfloat height = 0;
92 	
93 	GLfloat getGLWidth()
94 	{
95 		return width;
96 	}
97 	GLfloat getGLHeight()
98 	{
99 		return height;
100 	}
101 	
102 	
103 	/**
104 	 * Sets the GL capabilities for the widget
105 	 */
106 	bool setGLCapability(GLConfig glConfig = null, int renderType = GLRenderType.RGBA_TYPE)
107 	{
108 		if ( glConfig is null )
109 		{
110 			glConfig = new GLConfig(
111 			GLConfigMode.MODE_RGB
112 			| GLConfigMode.MODE_DEPTH
113 			| GLConfigMode.MODE_DOUBLE,
114 			GLConfigMode.MODE_RGB
115 			| GLConfigMode.MODE_DEPTH
116 			);
117 		}
118 		bool ok = setGLCapability(this, glConfig, null, true, renderType);
119 		
120 		return ok;
121 	}
122 	
123 	/**
124 	 * Set the GL capabilities for the widget
125 	 */
126 	bool setGLCapability(Widget widget, GLConfig glConfig, GLContext shareList, bool direct, int renderType)
127 	{
128 		widgetSetGLCapability(widget, glConfig, shareList, direct, renderType);
129 		
130 		addOnRealize(&realizeFrame);
131 		addOnUnrealize(&realizeFrame);
132 		addOnDraw(&drawFrame);
133 		addOnConfigure(&configureFrame);
134 		addOnMap(&mapFrame);
135 		addOnUnmap(&unmapFrame);
136 		addOnVisibilityNotify(&visibilityFrame);
137 		return true;
138 	}
139 	
140 	/**
141 	 * The widget should use this method to redraw it self at any time
142 	 */
143 	bool drawFrame()
144 	{
145 		return drawFrame(null, this);
146 	}
147 	
148 	bool alreadyRealized;
149 	
150 	bool getAlreadyRealized()
151 	{
152 		return alreadyRealized;
153 	}
154 	
155 	void realizeFrame(Widget widget)
156 	{
157 		alreadyRealized = true;
158 		
159 		//printf("GLCapabilityT.realizeFrame \n" );
160 		GLContext context = getGLContext(widget);
161 		GLWindow drawable = getGLWindow(widget);
162 		
163 		/*** OpenGL BEGIN ***/
164 		if ( !context.makeCurrent(drawable, drawable) )
165 		{
166 			return;
167 		}
168 		
169 		/*** do user actions ***/
170 		typeof(this).initGL();
171 		
172 		/*** flush ***/
173 		if ( drawable.isDoubleBuffered() )
174 		{
175 			drawable.swapBuffers();
176 		}
177 		else
178 		{
179 			glFlush ();
180 		}
181 		
182 		context.releaseCurrent();
183 		/*** OpenGL END ***/
184 	}
185 	
186 	bool drawFrame(Context cr, Widget widget)
187 	{
188 		//printf("GLCapabilityT.exposeFrame exposeFrame\n" );
189 		GLContext context = getGLContext(widget);
190 		GLWindow drawable = getGLWindow(widget);
191 		
192 		/*** OpenGL BEGIN ***/
193 		if ( !context.makeCurrent(drawable, drawable) )
194 		{
195 			return false;
196 		}
197 		
198 		/*** do user actions ***/
199 		bool consumeEvent = typeof(this).drawGL();
200 		
201 		/*** flush ***/
202 		if ( drawable.isDoubleBuffered() )
203 		{
204 			drawable.swapBuffers();
205 		}
206 		else
207 		{
208 			glFlush ();
209 		}
210 		
211 		context.releaseCurrent();
212 		/*** OpenGL END ***/
213 		
214 		return consumeEvent;
215 	}
216 	
217 	bool configureFrame(Event event, Widget widget)
218 	{
219 		if ( event.type == GdkEventType.CONFIGURE )
220 		{
221 			width = event.configure.width;
222 			height = event.configure.height;
223 		}
224 		
225 		GLContext context = getGLContext(widget);
226 		GLWindow drawable = getGLWindow(widget);
227 		
228 		/*** OpenGL BEGIN ***/
229 		if ( !context.makeCurrent(drawable, drawable) )
230 		{
231 			return false;
232 		}
233 		
234 		/*** do user actions ***/
235 		bool consumeEvent = typeof(this).resizeGL(event);
236 		
237 		/*** Seems to be the default on Linux, but not on Windows ***/
238 		version(Windows)
239 		{
240 			typeof(this).drawGL();
241 		}
242 		
243 		/*** flush ***/
244 		if ( drawable.isDoubleBuffered() )
245 		{
246 			drawable.swapBuffers();
247 		}
248 		else
249 		{
250 			glFlush ();
251 		}
252 		
253 		context.releaseCurrent();
254 		/*** OpenGL END ***/
255 		
256 		return consumeEvent;
257 	}
258 	
259 	void mapFrame(Widget widget)
260 	{
261 		GLContext context = getGLContext(widget);
262 		GLWindow drawable = getGLWindow(widget);
263 		
264 		/*** OpenGL BEGIN ***/
265 		if ( !context.makeCurrent(drawable, drawable) )
266 		{
267 			return;
268 		}
269 		
270 		/*** do user actions ***/
271 		typeof(this).onMap();
272 		
273 		/*** flush ***/
274 		if ( drawable.isDoubleBuffered() )
275 		{
276 			drawable.swapBuffers();
277 		}
278 		else
279 		{
280 			glFlush ();
281 		}
282 		
283 		context.releaseCurrent();
284 		/*** OpenGL END ***/
285 	}
286 	
287 	void unmapFrame(Widget widget)
288 	{
289 		GLContext context = getGLContext(widget);
290 		GLWindow drawable = getGLWindow(widget);
291 		
292 		/*** OpenGL BEGIN ***/
293 		if ( !context.makeCurrent(drawable, drawable) )
294 		{
295 			return;
296 		}
297 		
298 		/*** do user actions ***/
299 		typeof(this).onUnmap();
300 		
301 		/*** flush ***/
302 		if ( drawable.isDoubleBuffered() )
303 		{
304 			drawable.swapBuffers();
305 		}
306 		else
307 		{
308 			glFlush ();
309 		}
310 		
311 		context.releaseCurrent();
312 		/*** OpenGL END ***/
313 	}
314 	
315 	bool visibilityFrame(Event event, Widget widget)
316 	{
317 		GLContext context = getGLContext(widget);
318 		GLWindow drawable = getGLWindow(widget);
319 		
320 		/*** OpenGL BEGIN ***/
321 		if ( !context.makeCurrent(drawable, drawable) )
322 		{
323 			return false;
324 		}
325 		
326 		/*** do user actions ***/
327 		bool consumeEvent = typeof(this).onVisibility(event);
328 		
329 		/*** flush ***/
330 		if ( drawable.isDoubleBuffered() )
331 		{
332 			drawable.swapBuffers();
333 		}
334 		else
335 		{
336 			glFlush ();
337 		}
338 		
339 		context.releaseCurrent();
340 		/*** OpenGL END ***/
341 		
342 		return consumeEvent;
343 	}
344 	
345 	void onMap()
346 	{
347 		return;
348 	}
349 	
350 	void onUnmap()
351 	{
352 		return;
353 	}
354 	
355 	bool onVisibility(Event event)
356 	{
357 		return true;
358 	}
359 }
360 
361 /**
362  */
363