Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
GLFWWindow.cpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #include <vlGLFW/GLFWWindow.hpp>
33 #include <cstdlib>
34 #include <cstdio>
35 
36 using namespace vlGLFW;
37 using namespace vl;
38 
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
42 
44 {
45  destroyWindow();
46 }
47 
49 {
50  mHandle = NULL;
51  mUnicodeChar = 0;
52 }
53 
54 GLFWWindow::GLFWWindow(const vl::String& title, const vl::OpenGLContextFormat& info, int width, int height, GLFWwindow* share)
55 {
56  mHandle = NULL;
57  mUnicodeChar = 0;
58 
59  initGLFWWindow(title, info, width, height);
60 }
61 
63 bool GLFWWindow::initGLFWWindow(const vl::String& title, const vl::OpenGLContextFormat& info, int width, int height, GLFWwindow* share)
64 {
65  destroyWindow();
66 
67  // Allow user to set hints we don't support in here
68  // glfwDefaultWindowHints();
69 
70  GLFWmonitor* monitor = glfwGetPrimaryMonitor();
71  const GLFWvidmode* mode = glfwGetVideoMode( monitor );
72 
73  glfwWindowHint( GLFW_RED_BITS, info.rgbaBits().r() ? info.rgbaBits().r() : mode->redBits );
74  glfwWindowHint( GLFW_GREEN_BITS, info.rgbaBits().g() ? info.rgbaBits().g() : mode->greenBits );
75  glfwWindowHint( GLFW_BLUE_BITS, info.rgbaBits().b() ? info.rgbaBits().b() : mode->blueBits );
76  glfwWindowHint( GLFW_ALPHA_BITS, info.rgbaBits().a() ? info.rgbaBits().a() : GLFW_DONT_CARE );
77  glfwWindowHint( GLFW_DEPTH_BITS, info.depthBufferBits() ? info.depthBufferBits() : GLFW_DONT_CARE );
78  glfwWindowHint( GLFW_STENCIL_BITS, info.stencilBufferBits() ? info.stencilBufferBits() : GLFW_DONT_CARE );
79 
80  glfwWindowHint( GLFW_ACCUM_RED_BITS, info.accumRGBABits().r() ? info.accumRGBABits().r() : GLFW_DONT_CARE );
81  glfwWindowHint( GLFW_ACCUM_GREEN_BITS, info.accumRGBABits().g() ? info.accumRGBABits().g() : GLFW_DONT_CARE );
82  glfwWindowHint( GLFW_ACCUM_BLUE_BITS, info.accumRGBABits().b() ? info.accumRGBABits().b() : GLFW_DONT_CARE );
83  glfwWindowHint( GLFW_ACCUM_ALPHA_BITS, info.accumRGBABits().a() ? info.accumRGBABits().a() : GLFW_DONT_CARE );
84 
85  glfwWindowHint( GLFW_AUX_BUFFERS, GLFW_DONT_CARE );
86 
87  glfwWindowHint( GLFW_STEREO, info.stereo() );
88 
89  glfwWindowHint( GLFW_SAMPLES, info.multisample() ? info.multisampleSamples() : 0 );
90 
91  glfwWindowHint( GLFW_SRGB_CAPABLE, GLFW_DONT_CARE );
92 
93  glfwWindowHint( GLFW_DOUBLEBUFFER, info.doubleBuffer() );
94 
95  glfwWindowHint( GLFW_REFRESH_RATE, mode->refreshRate );
96 
97  glfwWindowHint( GLFW_CLIENT_API, GLFW_OPENGL_API );
98 
99  //glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR );
100  //glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR );
101  //glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT ); // Only for OpenGL 3.0 or above
102  //glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT );
103  //glfwWindowHint( GLFW_CONTEXT_ROBUSTNESS, GLFW_NO_RESET_NOTIFICATION|GLFW_LOSE_CONTEXT_ON_RESET|GLFW_NO_ROBUSTNESS);
104 
105  switch( info.openGLProfile() )
106  {
108  if ( info.majVersion() >= 3 && info.minVersion() >= 2 ) {
109  glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE );
110  }
111  if ( info.majVersion() ) {
112  glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, info.majVersion() );
113  glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, info.minVersion() );
114  }
115  break;
116  case vl::GLP_Core:
117  if ( info.majVersion() >= 3 && info.minVersion() >= 2 ) {
118  glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
119  }
120  if ( info.majVersion() ) {
121  glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, info.majVersion() );
122  glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, info.minVersion() );
123  }
124  break;
125  case vl::GLP_Default:
126  glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE );
127  break;
128  }
129 
130  mFullscreen = info.fullscreen();
131  if ( info.fullscreen() ) {
132  width = mode->width;
133  height = mode->height;
134  } else {
135  monitor = NULL;
136  }
137 
138  mHandle = glfwCreateWindow(width, height, title.toStdString().c_str(), monitor, share);
139 
140  if ( ! mHandle )
141  {
142  //glfwTerminate();
143  //exit(EXIT_FAILURE);
144  return false;
145  } else {
146  mWinMap[ mHandle ] = this;
147  }
148 
149  glfwMakeContextCurrent( mHandle );
150 
151  initGLContext();
152 
153  // Init is dispatched before resize
154  dispatchInitEvent();
155 
156  // Init is dispatched before resize
157  dispatchResizeEvent( width, height );
158 
159  glfwSetWindowSizeCallback( mHandle, glfw_size_callback );
160  glfwSetWindowPosCallback( mHandle, glfw_pos_callback );
161  glfwSetWindowRefreshCallback( mHandle, glfw_refresh_callback );
162  glfwSetWindowCloseCallback( mHandle, glfw_close_callback );
163  glfwSetWindowFocusCallback( mHandle, glfw_focus_callback );
164  glfwSetWindowIconifyCallback( mHandle, glfw_iconify_callback );
165 
166  glfwSetKeyCallback( mHandle, glfw_key_callback );
167  glfwSetCharCallback( mHandle, glfw_unicode_callback );
168  glfwSetCursorEnterCallback( mHandle, glfw_cursor_enter_callback );
169  glfwSetCursorPosCallback( mHandle, glfw_cursor_pos_callback );
170  glfwSetMouseButtonCallback( mHandle, glfw_mouse_button_callback );
171  glfwSetScrollCallback( mHandle, glfw_scroll_callback );
172  glfwSetDropCallback( mHandle, glfw_drop_callback );
173 
174  return true;
175 }
176 
178 {
179  if ( mHandle )
180  {
181  dispatchDestroyEvent();
182  glfwDestroyWindow( mHandle );
183  mWinMap.erase( mHandle );
184  mHandle = NULL;
185  }
186 }
187 
189 {
190  if ( mHandle )
191  {
192  glfwMakeContextCurrent( mHandle );
193  }
194 }
195 
197  dispatchUpdateEvent();
198 }
199 
201  if ( mHandle )
202  {
203  glfwSwapBuffers( mHandle );
204  }
205 }
206 
207 void GLFWWindow::glfw_size_callback(GLFWwindow* window, int w, int h)
208 {
209  WinMapType::iterator it = mWinMap.find( window );
210  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
211  if ( vlwin ) {
212  vlwin->dispatchResizeEvent( w, h );
213  }
214 }
215 
216 void GLFWWindow::glfw_pos_callback(GLFWwindow* window, int x, int y)
217 {
218  WinMapType::iterator it = mWinMap.find( window );
219  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
220  if ( vlwin ) {
221  // At the moment we don't have such event
222  // vlwin->dispatchPositionEvent( focused );
223  }
224 }
225 
226 void GLFWWindow::glfw_refresh_callback(GLFWwindow* window)
227 {
228  WinMapType::iterator it = mWinMap.find( window );
229  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
230  if ( vlwin ) {
231  vlwin->dispatchUpdateEvent();
232  }
233 }
234 
235 void GLFWWindow::glfw_close_callback(GLFWwindow* window)
236 {
237  if ( glfwWindowShouldClose( window ) ) {
238  WinMapType::iterator it = mWinMap.find( window );
239  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
240  if ( vlwin ) {
241  vlwin->destroyWindow();
242  }
243  }
244 }
245 
246 void GLFWWindow::glfw_focus_callback(GLFWwindow* window, int focused)
247 {
248  WinMapType::iterator it = mWinMap.find( window );
249  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
250  if ( vlwin ) {
251  // At the moment we don't have such event
252  // vlwin->dispatchFocusEvent( focused );
253  }
254 }
255 
256 void GLFWWindow::glfw_iconify_callback(GLFWwindow* window, int iconified)
257 {
258  WinMapType::iterator it = mWinMap.find( window );
259  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
260  if ( vlwin ) {
261  vlwin->dispatchVisibilityEvent( ! iconified );
262  }
263 }
264 
265 void GLFWWindow::glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
266 {
267  WinMapType::iterator it = mWinMap.find( window );
268  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
269  if ( vlwin ) {
270  vl::EKey vlkey = translateKey( key, scancode, mods );
271 
272  switch( action ) {
273  case GLFW_PRESS:
274  vlwin->dispatchKeyPressEvent( 0, vlkey );
275  break;
276  case GLFW_RELEASE:
277  vlwin->dispatchKeyReleaseEvent( vlwin->mUnicodeChar, vlkey );
278  vlwin->mUnicodeChar = 0;
279  break;
280  case GLFW_REPEAT:
281  break;
282  }
283  }
284 }
285 
286 void GLFWWindow::glfw_unicode_callback(GLFWwindow* window, unsigned int unicode)
287 {
288  WinMapType::iterator it = mWinMap.find( window );
289  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
290  if ( vlwin ) {
291  // Note: this event is triggered after key press but before key release
292  // this is a work around in order to get the unicode of the currently
293  // pressed key - for a better input experience one should hook into this
294  // callback directly without relying on key press/release events.
295  vlwin->mUnicodeChar = (unsigned int)unicode;
296  }
297 }
298 
299 void GLFWWindow::glfw_cursor_enter_callback(GLFWwindow* window, int entered)
300 {
301  WinMapType::iterator it = mWinMap.find( window );
302  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
303  if ( vlwin ) {
304  // At the moment we don't have such event
305  }
306 }
307 
308 void GLFWWindow::glfw_cursor_pos_callback(GLFWwindow* window, double dx, double dy)
309 {
310  WinMapType::iterator it = mWinMap.find( window );
311  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
312  if ( vlwin ) {
313  int x = floor(dx);
314  int y = floor(dy);
315  vlwin->dispatchMouseMoveEvent( x, y );
316  }
317 }
318 
319 void GLFWWindow::glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
320 {
321  WinMapType::iterator it = mWinMap.find( window );
322  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
323  if ( vlwin ) {
325  switch( button )
326  {
327  case GLFW_MOUSE_BUTTON_LEFT:
328  btn = vl::LeftButton;
329  break;
330  case GLFW_MOUSE_BUTTON_MIDDLE:
331  btn = vl::MiddleButton;
332  break;
333  case GLFW_MOUSE_BUTTON_RIGHT:
334  btn = vl::RightButton;
335  break;
336  }
337 
338  double dx = 0, dy = 0;
339  glfwGetCursorPos( window, &dx, &dy );
340  int x = floor(dx);
341  int y = floor(dy);
342 
343  if (action == GLFW_PRESS)
344  vlwin->dispatchMouseDownEvent(btn, x, y);
345  else
346  if (action == GLFW_RELEASE)
347  vlwin->dispatchMouseUpEvent(btn, x, y);
348  }
349 }
350 
351 void GLFWWindow::glfw_scroll_callback(GLFWwindow* window, double dx, double dy)
352 {
353  WinMapType::iterator it = mWinMap.find( window );
354  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
355  if ( vlwin ) {
356  int x = floor(dx);
357  int y = floor(dy);
358  vlwin->dispatchMouseWheelEvent( y );
359  }
360 }
361 
362 void GLFWWindow::glfw_drop_callback(GLFWwindow * window, int count, const char** df)
363 {
364  WinMapType::iterator it = mWinMap.find( window );
365  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
366  if ( vlwin ) {
367  std::vector<String> files;
368  for(int i=0; i<count; ++i) {
369  files.push_back( df[ i ] );
370  }
371  vlwin->dispatchFileDroppedEvent( files );
372  }
373 }
374 
376 {
377  if ( mHandle )
378  {
379  mFullscreen = fs;
380  GLFWmonitor* monitor = glfwGetPrimaryMonitor();
381  const GLFWvidmode* mode = glfwGetVideoMode( monitor );
382  int x = 100;
383  int y = 100;
384  int w = 512;
385  int h = 512;
386  int r = GLFW_DONT_CARE;
387  if ( fs ) {
388  x = 0;
389  y = 0;
390  w = mode->width;
391  h = mode->height;
392  r = mode->refreshRate;
393  } else {
394  monitor = 0;
395  }
396  glfwSetWindowMonitor( mHandle, monitor, x, y, w, h, r );
397  if ( ! fs ) {
398  setPosition( x, y );
399  }
400  return true;
401  }
402 
403  return false;
404 }
405 
407 {
408  if ( mHandle )
409  {
410  glfwSetWindowTitle( mHandle, title.toStdString().c_str() );
411  }
412 }
413 
414 void GLFWWindow::setPosition(int x, int y)
415 {
416  if ( mHandle )
417  {
418  glfwSetWindowPos( mHandle, x, y );
419  }
420 }
421 
422 void GLFWWindow::setSize(int w, int h)
423 {
424  if ( mHandle )
425  {
426  glfwSetWindowSize( mHandle, w, h );
427  }
428 }
429 
431 {
432  int x = 0, y = 0;
433  if ( mHandle )
434  {
435  glfwGetWindowPos( mHandle, &x, &y );
436  }
437  return vl::ivec2( x, y );
438 }
439 
441 {
442  int w = 0, h = 0;
443  if ( mHandle )
444  {
445  glfwGetWindowSize( mHandle, &w, &h );
446  }
447  return vl::ivec2( w, h );
448 }
449 
451 {
452  if ( mHandle )
453  {
454  glfwShowWindow( mHandle );
455  }
456 }
457 
459 {
460  if ( mHandle )
461  {
462  glfwHideWindow( mHandle );
463  }
464 }
465 
467 {
468  if ( mHandle )
469  {
470  glfwFocusWindow( mHandle );
471  }
472 }
473 
474 void GLFWWindow::setMouseVisible(bool visible)
475 {
476  if ( mHandle )
477  {
478  glfwSetInputMode( mHandle, GLFW_CURSOR, visible ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED );
479  }
480 }
481 
483 {
484  if ( mHandle )
485  {
486  glfwSetCursorPos( mHandle, x, y );
487  }
488 }
489 
490 vl::EKey GLFWWindow::translateKey(int key, int scancode, int mods)
491 {
492  // Other keys depending on keyboard layout
493  // vl::Key_Exclam
494  // vl::Key_QuoteDbl
495  // vl::Key_Hash
496  // vl::Key_Dollar
497  // vl::Key_Ampersand
498  // vl::Key_LeftParen
499  // vl::Key_RightParen
500  // vl::Key_Asterisk
501  // vl::Key_Plus
502  // vl::Key_Colon
503  // vl::Key_Less
504  // vl::Key_Greater
505  // vl::Key_Question
506  // vl::Key_At
507  // vl::Key_Caret
508  // vl::Key_Underscore
509 
510  switch( key ) {
511  default: return vl::Key_Unknown;
512  case GLFW_KEY_UNKNOWN: return vl::Key_Unknown;
513  case GLFW_KEY_SPACE: return vl::Key_Space;
514  case GLFW_KEY_APOSTROPHE: vl::Key_Quote;
515  case GLFW_KEY_COMMA: return vl::Key_Comma;
516  case GLFW_KEY_MINUS: return vl::Key_Minus;
517  case GLFW_KEY_PERIOD: return vl::Key_Period;
518  case GLFW_KEY_SLASH: return vl::Key_Slash;
519  case GLFW_KEY_0: return vl::Key_0;
520  case GLFW_KEY_1: return vl::Key_1;
521  case GLFW_KEY_2: return vl::Key_2;
522  case GLFW_KEY_3: return vl::Key_3;
523  case GLFW_KEY_4: return vl::Key_4;
524  case GLFW_KEY_5: return vl::Key_5;
525  case GLFW_KEY_6: return vl::Key_6;
526  case GLFW_KEY_7: return vl::Key_7;
527  case GLFW_KEY_8: return vl::Key_8;
528  case GLFW_KEY_9: return vl::Key_9;
529  case GLFW_KEY_SEMICOLON: return vl::Key_Semicolon;
530  case GLFW_KEY_EQUAL: return vl::Key_Equal;
531  case GLFW_KEY_A: return vl::Key_A;
532  case GLFW_KEY_B: return vl::Key_B;
533  case GLFW_KEY_C: return vl::Key_C;
534  case GLFW_KEY_D: return vl::Key_D;
535  case GLFW_KEY_E: return vl::Key_E;
536  case GLFW_KEY_F: return vl::Key_F;
537  case GLFW_KEY_G: return vl::Key_G;
538  case GLFW_KEY_H: return vl::Key_H;
539  case GLFW_KEY_I: return vl::Key_I;
540  case GLFW_KEY_J: return vl::Key_J;
541  case GLFW_KEY_K: return vl::Key_K;
542  case GLFW_KEY_L: return vl::Key_L;
543  case GLFW_KEY_M: return vl::Key_M;
544  case GLFW_KEY_N: return vl::Key_N;
545  case GLFW_KEY_O: return vl::Key_O;
546  case GLFW_KEY_P: return vl::Key_P;
547  case GLFW_KEY_Q: return vl::Key_Q;
548  case GLFW_KEY_R: return vl::Key_R;
549  case GLFW_KEY_S: return vl::Key_S;
550  case GLFW_KEY_T: return vl::Key_T;
551  case GLFW_KEY_U: return vl::Key_U;
552  case GLFW_KEY_V: return vl::Key_V;
553  case GLFW_KEY_W: return vl::Key_W;
554  case GLFW_KEY_X: return vl::Key_X;
555  case GLFW_KEY_Y: return vl::Key_Y;
556  case GLFW_KEY_Z: return vl::Key_Z;
557  case GLFW_KEY_LEFT_BRACKET: return vl::Key_LeftBracket;
558  case GLFW_KEY_BACKSLASH: return vl::Key_BackSlash;
559  case GLFW_KEY_RIGHT_BRACKET: return vl::Key_RightBracket;
560  case GLFW_KEY_GRAVE_ACCENT: vl::Key_QuoteLeft;
561  //case GLFW_KEY_WORLD_1:
562  //case GLFW_KEY_WORLD_2:
563  case GLFW_KEY_ESCAPE: return vl::Key_Escape;
564  case GLFW_KEY_ENTER: return vl::Key_Return;
565  case GLFW_KEY_TAB: return vl::Key_Tab;
566  case GLFW_KEY_BACKSPACE: return vl::Key_BackSpace;
567  case GLFW_KEY_INSERT: return vl::Key_Insert;
568  case GLFW_KEY_DELETE: return vl::Key_Delete;
569  case GLFW_KEY_RIGHT: return vl::Key_Right;
570  case GLFW_KEY_LEFT: return vl::Key_Left;
571  case GLFW_KEY_DOWN: return vl::Key_Down;
572  case GLFW_KEY_UP: return vl::Key_Up;
573  case GLFW_KEY_PAGE_UP: return vl::Key_PageUp;
574  case GLFW_KEY_PAGE_DOWN: return vl::Key_PageDown;
575  case GLFW_KEY_HOME: return vl::Key_Home;
576  case GLFW_KEY_END: return vl::Key_End;
577  //case GLFW_KEY_CAPS_LOCK:
578  //case GLFW_KEY_SCROLL_LOCK:
579  //case GLFW_KEY_NUM_LOCK:
580  case GLFW_KEY_PRINT_SCREEN: vl::Key_Print;
581  case GLFW_KEY_PAUSE: return vl::Key_Pause;
582  case GLFW_KEY_F1: return vl::Key_F1;
583  case GLFW_KEY_F2: return vl::Key_F2;
584  case GLFW_KEY_F3: return vl::Key_F3;
585  case GLFW_KEY_F4: return vl::Key_F4;
586  case GLFW_KEY_F5: return vl::Key_F5;
587  case GLFW_KEY_F6: return vl::Key_F6;
588  case GLFW_KEY_F7: return vl::Key_F7;
589  case GLFW_KEY_F8: return vl::Key_F8;
590  case GLFW_KEY_F9: return vl::Key_F9;
591  case GLFW_KEY_F10: return vl::Key_F10;
592  case GLFW_KEY_F11: return vl::Key_F11;
593  case GLFW_KEY_F12: return vl::Key_F12;
594  //case GLFW_KEY_F13:
595  //case GLFW_KEY_F14:
596  //case GLFW_KEY_F15:
597  //case GLFW_KEY_F16:
598  //case GLFW_KEY_F17:
599  //case GLFW_KEY_F18:
600  //case GLFW_KEY_F19:
601  //case GLFW_KEY_F20:
602  //case GLFW_KEY_F21:
603  //case GLFW_KEY_F22:
604  //case GLFW_KEY_F23:
605  //case GLFW_KEY_F24:
606  //case GLFW_KEY_F25:
607  case GLFW_KEY_KP_0: return vl::Key_0;
608  case GLFW_KEY_KP_1: return vl::Key_1;
609  case GLFW_KEY_KP_2: return vl::Key_2;
610  case GLFW_KEY_KP_3: return vl::Key_3;
611  case GLFW_KEY_KP_4: return vl::Key_4;
612  case GLFW_KEY_KP_5: return vl::Key_5;
613  case GLFW_KEY_KP_6: return vl::Key_6;
614  case GLFW_KEY_KP_7: return vl::Key_7;
615  case GLFW_KEY_KP_8: return vl::Key_8;
616  case GLFW_KEY_KP_9: return vl::Key_9;
617  case GLFW_KEY_KP_DECIMAL: return vl::Key_Period;
618  case GLFW_KEY_KP_DIVIDE: return vl::Key_Slash;
619  case GLFW_KEY_KP_MULTIPLY: return vl::Key_Asterisk;
620  case GLFW_KEY_KP_SUBTRACT: return vl::Key_Minus;
621  case GLFW_KEY_KP_ADD: return vl::Key_Plus;
622  case GLFW_KEY_KP_ENTER: return vl::Key_Return;
623  case GLFW_KEY_KP_EQUAL: return vl::Key_Equal;
624  case GLFW_KEY_LEFT_SHIFT: return vl::Key_Shift;
625  case GLFW_KEY_LEFT_CONTROL: return vl::Key_Ctrl;
626  case GLFW_KEY_LEFT_ALT: return vl::Key_Alt;
627  //case GLFW_KEY_LEFT_SUPER:
628  case GLFW_KEY_RIGHT_SHIFT: return vl::Key_Shift;
629  case GLFW_KEY_RIGHT_CONTROL: return vl::Key_Ctrl;
630  case GLFW_KEY_RIGHT_ALT: return vl::Key_Alt;
631  //case GLFW_KEY_RIGHT_SUPER:
632  // case GLFW_KEY_MENU:
633  }
634 }
635 
void dispatchKeyReleaseEvent(unsigned short unicode_ch, EKey key)
Dispatches the UIEventListener::keyReleaseEvent() notification to the subscribed UIEventListener obje...
Vector2< int > ivec2
A 2 components vector with int precision.
Definition: Vector2.hpp:278
void show()
If the OpenGL context is a widget this function makes it visible to the user.
Definition: GLFWWindow.cpp:450
void setMouseVisible(bool visible)
If the OpenGL context is a widget this function sets whether the mouse is visible over it or not...
Definition: GLFWWindow.cpp:474
void hide()
If the OpenGL context is a widget this function makes it invisible to the user.
Definition: GLFWWindow.cpp:458
void dispatchMouseDownEvent(EMouseButton button, int x, int y)
Dispatches the UIEventListener::mouseDownEvent() notification to the subscribed UIEventListener objec...
static void glfw_mouse_button_callback(GLFWwindow *, int, int, int)
Definition: GLFWWindow.cpp:319
static void glfw_focus_callback(GLFWwindow *window, int)
Definition: GLFWWindow.cpp:246
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
int multisampleSamples() const
const T_Scalar & r() const
Definition: Vector4.hpp:111
static void glfw_unicode_callback(GLFWwindow *, unsigned int)
Definition: GLFWWindow.cpp:286
unsigned short mUnicodeChar
Definition: GLFWWindow.hpp:155
The GLFW bindings namespace.
The GLFWWindow class implements an OpenGLContext using the GLFW API.
Definition: GLFWWindow.hpp:50
void dispatchVisibilityEvent(bool visible)
Dispatches the UIEventListener::visibilityEvent() notification to the subscribed UIEventListener obje...
static void glfw_key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
Definition: GLFWWindow.cpp:265
static void glfw_size_callback(GLFWwindow *window, int w, int h)
Definition: GLFWWindow.cpp:207
void dispatchKeyPressEvent(unsigned short unicode_ch, EKey key)
Dispatches the UIEventListener::keyPressEvent() notification to the subscribed UIEventListener object...
void dispatchResizeEvent(int w, int h)
Dispatches the UIEventListener::resizeEvent() notification to the subscribed UIEventListener objects...
bool setFullscreen(bool fs)
If the OpenGL context is a widget this function requests a maximization to fullscreen.
Definition: GLFWWindow.cpp:375
static void glfw_pos_callback(GLFWwindow *window, int x, int y)
Definition: GLFWWindow.cpp:216
void swapBuffers()
Swaps the back and front buffers to present the last rendering.
Definition: GLFWWindow.cpp:200
Visualization Library main namespace.
void setWindowTitle(const vl::String &title)
If the OpenGL context is a top window this function sets its title.
Definition: GLFWWindow.cpp:406
void translateKey(int &unicode, EKey &key, const wxKeyEvent &ev)
Definition: WXGLCanvas.cpp:166
std::map< ::GLFWwindow *, vlGLFW::GLFWWindow *> WinMapType
Definition: GLFWWindow.hpp:53
static void glfw_iconify_callback(GLFWwindow *window, int)
Definition: GLFWWindow.cpp:256
const T_Scalar & g() const
Definition: Vector4.hpp:112
vl::ivec2 size() const
Definition: GLFWWindow.cpp:440
void dispatchUpdateEvent()
Dispatches the UIEventListener::updateEvent() notification to the subscribed UIEventListener objects...
The OpenGLContextFormat class encapsulates the settings of an OpenGL rendering context.
static WinMapType mWinMap
Definition: GLFWWindow.hpp:154
const ivec4 & rgbaBits() const
void getFocus()
If the OpenGL context is a widget this function requests the mouse focus on it.
Definition: GLFWWindow.cpp:466
const ivec4 & accumRGBABits() const
static void glfw_refresh_callback(GLFWwindow *window)
Definition: GLFWWindow.cpp:226
static void glfw_close_callback(GLFWwindow *window)
Definition: GLFWWindow.cpp:235
EMouseButton
static vl::EKey translateKey(int key, int scancode, int mods)
Definition: GLFWWindow.cpp:490
void setPosition(int x, int y)
If the OpenGL context is a widget this function sets its position.
Definition: GLFWWindow.cpp:414
bool initGLFWWindow(const vl::String &title, const vl::OpenGLContextFormat &info, int width, int height, GLFWwindow *share=NULL)
Initializes and shows a GLFW window.
Definition: GLFWWindow.cpp:63
const T_Scalar & b() const
Definition: Vector4.hpp:113
void dispatchMouseWheelEvent(int n)
Dispatches the UIEventListener::mouseWheelEvent() notification to the subscribed UIEventListener obje...
#define NULL
Definition: OpenGLDefs.hpp:81
static void glfw_cursor_pos_callback(GLFWwindow *, double, double)
Definition: GLFWWindow.cpp:308
void setSize(int w, int h)
If the OpenGL context is a widget this function sets its size.
Definition: GLFWWindow.cpp:422
EOpenGLProfile openGLProfile() const
static void glfw_scroll_callback(GLFWwindow *, double, double)
Definition: GLFWWindow.cpp:351
void dispatchFileDroppedEvent(const std::vector< String > &files)
Dispatches the UIEventListener::fileDroppedEvent() notification to the subscribed UIEventListener obj...
static void glfw_drop_callback(GLFWwindow *, int, const char **)
Definition: GLFWWindow.cpp:362
void dispatchMouseMoveEvent(int x, int y)
Dispatches the UIEventListener::mouseMoveEvent() notification to the subscribed UIEventListener objec...
std::string toStdString() const
Returns a UTF8 encoded std::string.
Definition: String.cpp:1156
vl::ivec2 position() const
If the OpenGL context is a widget this function returns its position.
Definition: GLFWWindow.cpp:430
T floor(T a)
Definition: glsl_math.hpp:698
void makeCurrent()
Sets the OpenGL context as current for the calling thread.
Definition: GLFWWindow.cpp:188
static void glfw_cursor_enter_callback(GLFWwindow *, int)
Definition: GLFWWindow.cpp:299
void setMousePosition(int x, int y)
If the OpenGL context is a widget this function sets the mouse position.
Definition: GLFWWindow.cpp:482
void update()
If the OpenGLContext is a widget this function requests a redraw and generates an updateEvent()...
Definition: GLFWWindow.cpp:196
const T_Scalar & a() const
Definition: Vector4.hpp:114
void dispatchMouseUpEvent(EMouseButton button, int x, int y)
Dispatches the UIEventListener::mouseUpEvent() notification to the subscribed UIEventListener objects...