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 // SNEAKY MIXIN PROBLEM: 63 // 64 // These need to be public imports 65 // or GLCompatibility will not compile 66 // as a mixin in other modules! 67 68 // May as well be explicit about it: 69 70 public import cairo.Context; 71 public import glgtk.GLWidget; 72 public import glgtk.GLWidget : widgetSetGLCapability = setGLCapability; 73 public import glgdk.GLWindow; 74 public import gdk.Event; 75 76 template GLCapability() 77 { 78 79 GLfloat width = 0; 80 GLfloat height = 0; 81 82 GLfloat getGLWidth() 83 { 84 return width; 85 } 86 GLfloat getGLHeight() 87 { 88 return height; 89 } 90 91 92 /** 93 * Sets the GL capabilities for the widget 94 */ 95 bool setGLCapability(GLConfig glConfig = null, int renderType = GLRenderType.RGBA_TYPE) 96 { 97 if ( glConfig is null ) 98 { 99 glConfig = new GLConfig( 100 GLConfigMode.MODE_RGB 101 | GLConfigMode.MODE_DEPTH 102 | GLConfigMode.MODE_DOUBLE, 103 GLConfigMode.MODE_RGB 104 | GLConfigMode.MODE_DEPTH 105 ); 106 } 107 bool ok = setGLCapability(this, glConfig, null, true, renderType); 108 109 return ok; 110 } 111 112 /** 113 * Set the GL capabilities for the widget 114 */ 115 bool setGLCapability(Widget widget, GLConfig glConfig, GLContext shareList, bool direct, int renderType) 116 { 117 widgetSetGLCapability(widget, glConfig, shareList, direct, renderType); 118 119 addOnRealize(&realizeFrame); 120 addOnUnrealize(&realizeFrame); 121 addOnDraw(&drawFrame); 122 addOnConfigure(&configureFrame); 123 addOnMap(&mapFrame); 124 addOnUnmap(&unmapFrame); 125 addOnVisibilityNotify(&visibilityFrame); 126 return true; 127 } 128 129 /** 130 * The widget should use this method to redraw it self at any time 131 */ 132 bool drawFrame() 133 { 134 return drawFrame(null, this); 135 } 136 137 bool alreadyRealized; 138 139 bool getAlreadyRealized() 140 { 141 return alreadyRealized; 142 } 143 144 void realizeFrame(Widget widget) 145 { 146 alreadyRealized = true; 147 148 //printf("GLCapabilityT.realizeFrame \n" ); 149 GLContext context = getGLContext(widget); 150 GLWindow drawable = getGLWindow(widget); 151 152 /*** OpenGL BEGIN ***/ 153 if ( !context.makeCurrent(drawable, drawable) ) 154 { 155 return; 156 } 157 158 /*** do user actions ***/ 159 typeof(this).initGL(); 160 161 /*** flush ***/ 162 if ( drawable.isDoubleBuffered() ) 163 { 164 drawable.swapBuffers(); 165 } 166 else 167 { 168 glFlush (); 169 } 170 171 context.releaseCurrent(); 172 /*** OpenGL END ***/ 173 } 174 175 bool drawFrame(Context cr, Widget widget) 176 { 177 //printf("GLCapabilityT.exposeFrame exposeFrame\n" ); 178 GLContext context = getGLContext(widget); 179 GLWindow drawable = getGLWindow(widget); 180 181 /*** OpenGL BEGIN ***/ 182 if ( !context.makeCurrent(drawable, drawable) ) 183 { 184 return false; 185 } 186 187 /*** do user actions ***/ 188 bool consumeEvent = typeof(this).drawGL(); 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 bool configureFrame(Event event, Widget widget) 207 { 208 if ( event.type == GdkEventType.CONFIGURE ) 209 { 210 width = event.configure.width; 211 height = event.configure.height; 212 } 213 214 GLContext context = getGLContext(widget); 215 GLWindow drawable = getGLWindow(widget); 216 217 /*** OpenGL BEGIN ***/ 218 if ( !context.makeCurrent(drawable, drawable) ) 219 { 220 return false; 221 } 222 223 /*** do user actions ***/ 224 bool consumeEvent = typeof(this).resizeGL(event); 225 226 /*** Seems to be the default on Linux, but not on Windows ***/ 227 version(Windows) 228 { 229 typeof(this).drawGL(); 230 } 231 232 /*** flush ***/ 233 if ( drawable.isDoubleBuffered() ) 234 { 235 drawable.swapBuffers(); 236 } 237 else 238 { 239 glFlush (); 240 } 241 242 context.releaseCurrent(); 243 /*** OpenGL END ***/ 244 245 return consumeEvent; 246 } 247 248 void mapFrame(Widget widget) 249 { 250 GLContext context = getGLContext(widget); 251 GLWindow drawable = getGLWindow(widget); 252 253 /*** OpenGL BEGIN ***/ 254 if ( !context.makeCurrent(drawable, drawable) ) 255 { 256 return; 257 } 258 259 /*** do user actions ***/ 260 typeof(this).onMap(); 261 262 /*** flush ***/ 263 if ( drawable.isDoubleBuffered() ) 264 { 265 drawable.swapBuffers(); 266 } 267 else 268 { 269 glFlush (); 270 } 271 272 context.releaseCurrent(); 273 /*** OpenGL END ***/ 274 } 275 276 void unmapFrame(Widget widget) 277 { 278 GLContext context = getGLContext(widget); 279 GLWindow drawable = getGLWindow(widget); 280 281 /*** OpenGL BEGIN ***/ 282 if ( !context.makeCurrent(drawable, drawable) ) 283 { 284 return; 285 } 286 287 /*** do user actions ***/ 288 typeof(this).onUnmap(); 289 290 /*** flush ***/ 291 if ( drawable.isDoubleBuffered() ) 292 { 293 drawable.swapBuffers(); 294 } 295 else 296 { 297 glFlush (); 298 } 299 300 context.releaseCurrent(); 301 /*** OpenGL END ***/ 302 } 303 304 bool visibilityFrame(Event event, Widget widget) 305 { 306 GLContext context = getGLContext(widget); 307 GLWindow drawable = getGLWindow(widget); 308 309 /*** OpenGL BEGIN ***/ 310 if ( !context.makeCurrent(drawable, drawable) ) 311 { 312 return false; 313 } 314 315 /*** do user actions ***/ 316 bool consumeEvent = typeof(this).onVisibility(event); 317 318 /*** flush ***/ 319 if ( drawable.isDoubleBuffered() ) 320 { 321 drawable.swapBuffers(); 322 } 323 else 324 { 325 glFlush (); 326 } 327 328 context.releaseCurrent(); 329 /*** OpenGL END ***/ 330 331 return consumeEvent; 332 } 333 334 void onMap() 335 { 336 return; 337 } 338 339 void onUnmap() 340 { 341 return; 342 } 343 344 bool onVisibility(Event event) 345 { 346 return true; 347 } 348 } 349 350 /** 351 */ 352