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 
73 public import glgtk.GLWidget;
74 private import glgdk.GLDrawable;
75 public import gdk.Event;
76 
77 version(Tango) {
78 	private import tango.core.Memory;
79 	} else version(D_Version2) {
80 	private import core.memory;
81 	} else {
82 	private import std.gc;
83 }
84 
85 
86 template GLCapability()
87 {
88 	
89 	GLfloat width = 0;
90 	GLfloat height = 0;
91 	
92 	GLfloat getGLWidth()
93 	{
94 		return width;
95 	}
96 	GLfloat getGLHeight()
97 	{
98 		return height;
99 	}
100 	
101 	
102 	/**
103 	 * Sets the GL capabilities for the widget
104 	 */
105 	bool setGLCapability(GLConfig glConfig = null, int renderType = GLRenderType.RGBA_TYPE)
106 	{
107 		if ( glConfig is null )
108 		{
109 			glConfig = new GLConfig(
110 			GLConfigMode.MODE_RGB
111 			| GLConfigMode.MODE_DEPTH
112 			| GLConfigMode.MODE_DOUBLE,
113 			GLConfigMode.MODE_RGB
114 			| GLConfigMode.MODE_DEPTH
115 			);
116 		}
117 		bool ok = setGLCapability(this, glConfig, null, true, renderType);
118 		
119 		return ok;
120 	}
121 	
122 	/**
123 	 * Set the GL capabilities for the widget
124 	 */
125 	bool setGLCapability(Widget widget, GLConfig glConfig, GLContext shareList, bool direct, int renderType)
126 	{
127 		GLWidget.setGLCapability(widget, glConfig, shareList, direct, renderType);
128 		
129 		addOnRealize(&realizeFrame);
130 		addOnUnrealize(&realizeFrame);
131 		addOnExpose(&exposeFrame);
132 		addOnConfigure(&configureFrame);
133 		addOnMap(&mapFrame);
134 		addOnUnmap(&unmapFrame);
135 		addOnVisibilityNotify(&visibilityFrame);
136 		return true;
137 	}
138 	
139 	/**
140 	 * The widget should use this method to redraw it self at any time
141 	 */
142 	public bool glDrawFrame()
143 	{
144 		return glDrawFrame(this);
145 	}
146 	
147 	/**
148 	 * The application should use this method to redraw the scene at any time
149 	 */
150 	bool glDrawFrame(Widget widget)
151 	{
152 		//printf("GLCapabilityT.realizeFrame \n" );
153 		GLContext context = GLWidget.getGLContext(widget);
154 		GLDrawable drawable = GLWidget.getGLDrawable(widget);
155 		
156 		/*** OpenGL BEGIN ***/
157 		if ( !drawable.glBegin(context) )
158 		{
159 			return false;
160 		}
161 		
162 		/*** do user actions ***/
163 		bool consumeEvent = typeof(this).drawGL(null);
164 		
165 		/*** flush ***/
166 		if ( drawable.isDoubleBuffered() )
167 		{
168 			drawable.swapBuffers();
169 		}
170 		else
171 		{
172 			glFlush ();
173 		}
174 		
175 		drawable.glEnd();
176 		/*** OpenGL END ***/
177 		return true;
178 		
179 	}
180 	
181 	bool alreadyRealized;
182 	
183 	bool getAlreadyRealized()
184 	{
185 		return alreadyRealized;
186 	}
187 	
188 	void realizeFrame(Widget widget)
189 	{
190 		alreadyRealized = true;
191 		
192 		//printf("GLCapabilityT.realizeFrame \n" );
193 		GLContext context = GLWidget.getGLContext(widget);
194 		GLDrawable drawable = GLWidget.getGLDrawable(widget);
195 		
196 		/*** OpenGL BEGIN ***/
197 		if ( !drawable.glBegin(context) )
198 		{
199 			return;
200 		}
201 		
202 		/*** do user actions ***/
203 		bool consumeEvent = typeof(this).initGL();
204 		
205 		/*** flush ***/
206 		if ( drawable.isDoubleBuffered() )
207 		{
208 			drawable.swapBuffers();
209 		}
210 		else
211 		{
212 			glFlush ();
213 		}
214 		
215 		drawable.glEnd();
216 		/*** OpenGL END ***/
217 		
218 		//return consumeEvent;
219 	}
220 	
221 	bool exposeFrame(GdkEventExpose* event, Widget widget)
222 	{
223 		//printf("GLCapabilityT.exposeFrame exposeFrame\n" );
224 		GLContext context = GLWidget.getGLContext(widget);
225 		GLDrawable drawable = GLWidget.getGLDrawable(widget);
226 		
227 		/*** OpenGL BEGIN ***/
228 		if ( !drawable.glBegin(context) )
229 		{
230 			return false;
231 		}
232 		
233 		/*** do user actions ***/
234 		bool consumeEvent = typeof(this).drawGL(event);
235 		
236 		/*** flush ***/
237 		if ( drawable.isDoubleBuffered() )
238 		{
239 			drawable.swapBuffers();
240 		}
241 		else
242 		{
243 			glFlush ();
244 		}
245 		
246 		drawable.glEnd();
247 		/*** OpenGL END ***/
248 		
249 		return consumeEvent;
250 	}
251 	
252 	bool configureFrame(GdkEventConfigure* event, Widget widget)
253 	{
254 		if ( event != null )
255 		{
256 			width = event.width;
257 			height = event.height;
258 		}
259 		version(Tango) tango.core.Memory.GC.disable();
260 		else version(D_Version2) core.memory.GC.disable();
261 		else std.gc.disable();
262 		//writefln("configureFrame 1");
263 		//printf("GLCapabilityT.configureFrame \n" );
264 		GLContext context = GLWidget.getGLContext(widget);
265 		GLDrawable drawable = GLWidget.getGLDrawable(widget);
266 		
267 		/*** OpenGL BEGIN ***/
268 		if ( !drawable.glBegin(context) )
269 		{
270 			return false;
271 		}
272 		
273 		//writefln("configureFrame 2");
274 		/*** do user actions ***/
275 		bool consumeEvent = typeof(this).resizeGL(event);
276 		//printf("here\n");
277 		//writefln("configureFrame 3");
278 		
279 		/*** flush ***/
280 		if ( drawable.isDoubleBuffered() )
281 		{
282 			//writefln("configureFrame 4");
283 			drawable.swapBuffers();
284 			//writefln("configureFrame 5");
285 		}
286 		else
287 		{
288 			//writefln("configureFrame 6");
289 			glFlush ();
290 			//writefln("configureFrame 7");
291 		}
292 		
293 		//writefln("configureFrame 8");
294 		drawable.glEnd();
295 		//writefln("configureFrame 9");
296 		/*** OpenGL END ***/
297 		
298 		version(Tango) tango.core.Memory.GC.enable();
299 		else version(D_Version2) core.memory.GC.enable();
300 		else std.gc.enable();
301 		
302 		return consumeEvent;
303 	}
304 	
305 	void mapFrame(Widget widget)
306 	{
307 		//printf("GLCapabilityT.mapFrame \n" );
308 		GLContext context = GLWidget.getGLContext(widget);
309 		GLDrawable drawable = GLWidget.getGLDrawable(widget);
310 		
311 		/*** OpenGL BEGIN ***/
312 		if ( !drawable.glBegin(context) )
313 		{
314 			return;
315 		}
316 		
317 		/*** do user actions ***/
318 		bool consumeEvent = typeof(this).onMap();
319 		
320 		/*** flush ***/
321 		if ( drawable.isDoubleBuffered() )
322 		{
323 			drawable.swapBuffers();
324 		}
325 		else
326 		{
327 			glFlush ();
328 		}
329 		
330 		drawable.glEnd();
331 		/*** OpenGL END ***/
332 		
333 		//return consumeEvent;
334 	}
335 	
336 	void unmapFrame(Widget widget)
337 	{
338 		//printf("GLCapabilityT.unmapFrame \n" );
339 		GLContext context = GLWidget.getGLContext(widget);
340 		GLDrawable drawable = GLWidget.getGLDrawable(widget);
341 		
342 		/*** OpenGL BEGIN ***/
343 		if ( !drawable.glBegin(context) )
344 		{
345 			return;
346 		}
347 		
348 		/*** do user actions ***/
349 		bool consumeEvent = typeof(this).onUnmap();
350 		
351 		/*** flush ***/
352 		if ( drawable.isDoubleBuffered() )
353 		{
354 			drawable.swapBuffers();
355 		}
356 		else
357 		{
358 			glFlush ();
359 		}
360 		
361 		drawable.glEnd();
362 		/*** OpenGL END ***/
363 		
364 		//return consumeEvent;
365 	}
366 	
367 	bool visibilityFrame(GdkEventVisibility* event, Widget widget)
368 	{
369 		//printf("GLCapabilityT.visibilityFrame \n" );
370 		GLContext context = GLWidget.getGLContext(widget);
371 		GLDrawable drawable = GLWidget.getGLDrawable(widget);
372 		
373 		/*** OpenGL BEGIN ***/
374 		if ( !drawable.glBegin(context) )
375 		{
376 			return false;
377 		}
378 		
379 		/*** do user actions ***/
380 		bool consumeEvent = typeof(this).onVisibility(event);
381 		
382 		/*** flush ***/
383 		if ( drawable.isDoubleBuffered() )
384 		{
385 			drawable.swapBuffers();
386 		}
387 		else
388 		{
389 			glFlush ();
390 		}
391 		
392 		drawable.glEnd();
393 		/*** OpenGL END ***/
394 		
395 		return consumeEvent;
396 	}
397 	
398 	bool onMap()
399 	{
400 		//printf("GLCapabilityT.map \n" );
401 		return true;
402 	}
403 	
404 	bool onUnmap()
405 	{
406 		//printf("GLCapabilityT.unmap \n" );
407 		return true;
408 	}
409 	
410 	bool onVisibility(GdkEventVisibility* event)
411 	{
412 		//printf("GLCapabilityT.visibility \n" );
413 		return true;
414 	}
415 }
416 
417 /**
418  */
419