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