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 		return drawFrame(getScopedGobject!Context(null, true), this);
94 	}
95 	
96 	bool alreadyRealized;
97 	
98 	bool getAlreadyRealized()
99 	{
100 		return alreadyRealized;
101 	}
102 	
103 	void realizeFrame(Widget widget)
104 	{
105 		alreadyRealized = true;
106 		
107 		GLContext context = getGlContext(widget);
108 		GLWindow drawable = getGlWindow(widget);
109 		
110 		/*** OpenGL BEGIN ***/
111 		if ( !context.makeCurrent(drawable, drawable) )
112 		{
113 			return;
114 		}
115 		
116 		/*** do user actions ***/
117 		typeof(this).initGL();
118 		
119 		/*** flush ***/
120 		if ( drawable.isDoubleBuffered() )
121 		{
122 			drawable.swapBuffers();
123 		}
124 		else
125 		{
126 			glFlush ();
127 		}
128 		
129 		context.releaseCurrent();
130 		/*** OpenGL END ***/
131 	}
132 	
133 	bool drawFrame(Scoped!Context cr, Widget widget)
134 	{
135 		GLContext context = getGlContext(widget);
136 		GLWindow drawable = getGlWindow(widget);
137 		
138 		/*** OpenGL BEGIN ***/
139 		if ( !context.makeCurrent(drawable, drawable) )
140 		{
141 			return false;
142 		}
143 		
144 		/*** do user actions ***/
145 		bool consumeEvent = typeof(this).drawGL();
146 		
147 		/*** flush ***/
148 		if ( drawable.isDoubleBuffered() )
149 		{
150 			drawable.swapBuffers();
151 		}
152 		else
153 		{
154 			glFlush ();
155 		}
156 		
157 		context.releaseCurrent();
158 		/*** OpenGL END ***/
159 		
160 		return consumeEvent;
161 	}
162 	
163 	bool configureFrame(Event event, Widget widget)
164 	{
165 		if ( event.type == GdkEventType.CONFIGURE )
166 		{
167 			width = event.configure.width;
168 			height = event.configure.height;
169 		}
170 		
171 		GLContext context = getGlContext(widget);
172 		GLWindow drawable = getGlWindow(widget);
173 		
174 		/*** OpenGL BEGIN ***/
175 		if ( !context.makeCurrent(drawable, drawable) )
176 		{
177 			return false;
178 		}
179 		
180 		/*** do user actions ***/
181 		bool consumeEvent = typeof(this).resizeGL(event);
182 		
183 		/*** Seems to be the default on Linux, but not on Windows ***/
184 		version(Windows)
185 		{
186 			typeof(this).drawGL();
187 		}
188 		
189 		/*** flush ***/
190 		if ( drawable.isDoubleBuffered() )
191 		{
192 			drawable.swapBuffers();
193 		}
194 		else
195 		{
196 			glFlush ();
197 		}
198 		
199 		context.releaseCurrent();
200 		/*** OpenGL END ***/
201 		
202 		return consumeEvent;
203 	}
204 	
205 	void mapFrame(Widget widget)
206 	{
207 		GLContext context = getGlContext(widget);
208 		GLWindow drawable = getGlWindow(widget);
209 		
210 		/*** OpenGL BEGIN ***/
211 		if ( !context.makeCurrent(drawable, drawable) )
212 		{
213 			return;
214 		}
215 		
216 		/*** do user actions ***/
217 		typeof(this).onMap();
218 		
219 		/*** flush ***/
220 		if ( drawable.isDoubleBuffered() )
221 		{
222 			drawable.swapBuffers();
223 		}
224 		else
225 		{
226 			glFlush ();
227 		}
228 		
229 		context.releaseCurrent();
230 		/*** OpenGL END ***/
231 	}
232 	
233 	void unmapFrame(Widget widget)
234 	{
235 		GLContext context = getGlContext(widget);
236 		GLWindow drawable = getGlWindow(widget);
237 		
238 		/*** OpenGL BEGIN ***/
239 		if ( !context.makeCurrent(drawable, drawable) )
240 		{
241 			return;
242 		}
243 		
244 		/*** do user actions ***/
245 		typeof(this).onUnmap();
246 		
247 		/*** flush ***/
248 		if ( drawable.isDoubleBuffered() )
249 		{
250 			drawable.swapBuffers();
251 		}
252 		else
253 		{
254 			glFlush ();
255 		}
256 		
257 		context.releaseCurrent();
258 		/*** OpenGL END ***/
259 	}
260 	
261 	bool visibilityFrame(Event event, Widget widget)
262 	{
263 		GLContext context = getGlContext(widget);
264 		GLWindow drawable = getGlWindow(widget);
265 		
266 		/*** OpenGL BEGIN ***/
267 		if ( !context.makeCurrent(drawable, drawable) )
268 		{
269 			return false;
270 		}
271 		
272 		/*** do user actions ***/
273 		bool consumeEvent = typeof(this).onVisibility(event);
274 		
275 		/*** flush ***/
276 		if ( drawable.isDoubleBuffered() )
277 		{
278 			drawable.swapBuffers();
279 		}
280 		else
281 		{
282 			glFlush ();
283 		}
284 		
285 		context.releaseCurrent();
286 		/*** OpenGL END ***/
287 		
288 		return consumeEvent;
289 	}
290 	
291 	void onMap()
292 	{
293 		return;
294 	}
295 	
296 	void onUnmap()
297 	{
298 		return;
299 	}
300 	
301 	bool onVisibility(Event event)
302 	{
303 		return true;
304 	}
305 }
306 
307 /**
308  */