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 module glgtk.GLCapability;
26 
27 private import gtkglc.glgtk;
28 public  import gtkglc.glgtktypes;
29 
30 
31 /** */
32 public import cairo.Context;
33 public import gdk.Event;
34 public import glgdk.GLWindow;
35 public import glgtk.GLWidget;
36 public import glgtk.GLWidget : widgetSetGlCapability = setGlCapability;
37 
38 template GLCapability()
39 {
40 	GLfloat width = 0;
41 	GLfloat height = 0;
42 	
43 	GLfloat getGlWidth()
44 	{
45 		return width;
46 	}
47 	GLfloat getGlHeight()
48 	{
49 		return height;
50 	}
51 	
52 	/**
53 	 * Sets the GL capabilities for the widget
54 	 */
55 	bool setGlCapability(GLConfig glConfig = null, int renderType = GdkGLRenderType.RGBA_TYPE)
56 	{
57 		if ( glConfig is null )
58 		{
59 			glConfig = new GLConfig(
60 				GdkGLConfigMode.RGB
61 				| GdkGLConfigMode.DEPTH
62 				| GdkGLConfigMode.DOUBLE,
63 				GdkGLConfigMode.RGB
64 				| GdkGLConfigMode.DEPTH
65 			);
66 		}
67 		return setGlCapability(this, glConfig, null, true, renderType);
68 	}
69 	
70 	/**
71 	 * Set the GL capabilities for the widget
72 	 */
73 	bool setGlCapability(Widget widget, GLConfig glConfig, GLContext shareList, bool direct, int renderType)
74 	{
75 		if(!widgetSetGlCapability(widget, glConfig, shareList, direct, renderType))
76 			return false;
77 		
78 		addOnRealize(&realizeFrame);
79 		addOnUnrealize(&realizeFrame);
80 		addOnDraw(&drawFrame);
81 		addOnConfigure(&configureFrame);
82 		addOnMap(&mapFrame);
83 		addOnUnmap(&unmapFrame);
84 		addOnVisibilityNotify(&visibilityFrame);
85 		return true;
86 	}
87 	
88 	/**
89 	 * The widget should use this method to redraw it self at any time
90 	 */
91 	bool drawFrame()
92 	{
93 		Scoped!Context cr;
94 		return drawFrame(cr, this);
95 	}
96 	
97 	bool alreadyRealized;
98 	
99 	bool getAlreadyRealized()
100 	{
101 		return alreadyRealized;
102 	}
103 	
104 	void realizeFrame(Widget widget)
105 	{
106 		alreadyRealized = true;
107 		
108 		GLContext context = getGlContext(widget);
109 		GLWindow drawable = getGlWindow(widget);
110 		
111 		/*** OpenGL BEGIN ***/
112 		if ( !context.makeCurrent(drawable, drawable) )
113 		{
114 			return;
115 		}
116 		
117 		/*** do user actions ***/
118 		typeof(this).initGL();
119 		
120 		/*** flush ***/
121 		if ( drawable.isDoubleBuffered() )
122 		{
123 			drawable.swapBuffers();
124 		}
125 		else
126 		{
127 			glFlush ();
128 		}
129 		
130 		context.releaseCurrent();
131 		/*** OpenGL END ***/
132 	}
133 	
134 	bool drawFrame(Scoped!Context cr, Widget widget)
135 	{
136 		GLContext context = getGlContext(widget);
137 		GLWindow drawable = getGlWindow(widget);
138 		
139 		/*** OpenGL BEGIN ***/
140 		if ( !context.makeCurrent(drawable, drawable) )
141 		{
142 			return false;
143 		}
144 		
145 		/*** do user actions ***/
146 		bool consumeEvent = typeof(this).drawGL();
147 		
148 		/*** flush ***/
149 		if ( drawable.isDoubleBuffered() )
150 		{
151 			drawable.swapBuffers();
152 		}
153 		else
154 		{
155 			glFlush ();
156 		}
157 		
158 		context.releaseCurrent();
159 		/*** OpenGL END ***/
160 		
161 		return consumeEvent;
162 	}
163 	
164 	bool configureFrame(Event event, Widget widget)
165 	{
166 		if ( event.type == GdkEventType.CONFIGURE )
167 		{
168 			width = event.configure.width;
169 			height = event.configure.height;
170 		}
171 		
172 		GLContext context = getGlContext(widget);
173 		GLWindow drawable = getGlWindow(widget);
174 		
175 		/*** OpenGL BEGIN ***/
176 		if ( !context.makeCurrent(drawable, drawable) )
177 		{
178 			return false;
179 		}
180 		
181 		/*** do user actions ***/
182 		bool consumeEvent = typeof(this).resizeGL(event);
183 		
184 		/*** Seems to be the default on Linux, but not on Windows ***/
185 		version(Windows)
186 		{
187 			typeof(this).drawGL();
188 		}
189 		
190 		/*** flush ***/
191 		if ( drawable.isDoubleBuffered() )
192 		{
193 			drawable.swapBuffers();
194 		}
195 		else
196 		{
197 			glFlush ();
198 		}
199 		
200 		context.releaseCurrent();
201 		/*** OpenGL END ***/
202 		
203 		return consumeEvent;
204 	}
205 	
206 	void mapFrame(Widget widget)
207 	{
208 		GLContext context = getGlContext(widget);
209 		GLWindow drawable = getGlWindow(widget);
210 		
211 		/*** OpenGL BEGIN ***/
212 		if ( !context.makeCurrent(drawable, drawable) )
213 		{
214 			return;
215 		}
216 		
217 		/*** do user actions ***/
218 		typeof(this).onMap();
219 		
220 		/*** flush ***/
221 		if ( drawable.isDoubleBuffered() )
222 		{
223 			drawable.swapBuffers();
224 		}
225 		else
226 		{
227 			glFlush ();
228 		}
229 		
230 		context.releaseCurrent();
231 		/*** OpenGL END ***/
232 	}
233 	
234 	void unmapFrame(Widget widget)
235 	{
236 		GLContext context = getGlContext(widget);
237 		GLWindow drawable = getGlWindow(widget);
238 		
239 		/*** OpenGL BEGIN ***/
240 		if ( !context.makeCurrent(drawable, drawable) )
241 		{
242 			return;
243 		}
244 		
245 		/*** do user actions ***/
246 		typeof(this).onUnmap();
247 		
248 		/*** flush ***/
249 		if ( drawable.isDoubleBuffered() )
250 		{
251 			drawable.swapBuffers();
252 		}
253 		else
254 		{
255 			glFlush ();
256 		}
257 		
258 		context.releaseCurrent();
259 		/*** OpenGL END ***/
260 	}
261 	
262 	bool visibilityFrame(Event event, Widget widget)
263 	{
264 		GLContext context = getGlContext(widget);
265 		GLWindow drawable = getGlWindow(widget);
266 		
267 		/*** OpenGL BEGIN ***/
268 		if ( !context.makeCurrent(drawable, drawable) )
269 		{
270 			return false;
271 		}
272 		
273 		/*** do user actions ***/
274 		bool consumeEvent = typeof(this).onVisibility(event);
275 		
276 		/*** flush ***/
277 		if ( drawable.isDoubleBuffered() )
278 		{
279 			drawable.swapBuffers();
280 		}
281 		else
282 		{
283 			glFlush ();
284 		}
285 		
286 		context.releaseCurrent();
287 		/*** OpenGL END ***/
288 		
289 		return consumeEvent;
290 	}
291 	
292 	void onMap()
293 	{
294 		return;
295 	}
296 	
297 	void onUnmap()
298 	{
299 		return;
300 	}
301 	
302 	bool onVisibility(Event event)
303 	{
304 		return true;
305 	}
306 }
307 
308 /**
309  */