Visualization Library 2.0.0-b3

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-2017, 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  glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE );
109  glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, info.majVersion() );
110  glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, info.minVersion() );
111  break;
112  case vl::GLP_Core:
113  glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
114  glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, info.majVersion() );
115  glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, info.minVersion() );
116  break;
117  case vl::GLP_Default:
118  glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE );
119  break;
120  }
121 
122  mFullscreen = info.fullscreen();
123  if ( info.fullscreen() ) {
124  width = mode->width;
125  height = mode->height;
126  } else {
127  monitor = NULL;
128  }
129 
130  mHandle = glfwCreateWindow(width, height, title.toStdString().c_str(), monitor, share);
131 
132  if ( ! mHandle )
133  {
134  //glfwTerminate();
135  //exit(EXIT_FAILURE);
136  return false;
137  } else {
138  mWinMap[ mHandle ] = this;
139  }
140 
141  glfwMakeContextCurrent( mHandle );
142 
143  initGLContext();
144 
145  // Init is dispatched before resize
146  dispatchInitEvent();
147 
148  // Init is dispatched before resize
149  dispatchResizeEvent( width, height );
150 
151  glfwSetWindowSizeCallback( mHandle, glfw_size_callback );
152  glfwSetWindowPosCallback( mHandle, glfw_pos_callback );
153  glfwSetWindowRefreshCallback( mHandle, glfw_refresh_callback );
154  glfwSetWindowCloseCallback( mHandle, glfw_close_callback );
155  glfwSetWindowFocusCallback( mHandle, glfw_focus_callback );
156  glfwSetWindowIconifyCallback( mHandle, glfw_iconify_callback );
157 
158  glfwSetKeyCallback( mHandle, glfw_key_callback );
159  glfwSetCharCallback( mHandle, glfw_unicode_callback );
160  glfwSetCursorEnterCallback( mHandle, glfw_cursor_enter_callback );
161  glfwSetCursorPosCallback( mHandle, glfw_cursor_pos_callback );
162  glfwSetMouseButtonCallback( mHandle, glfw_mouse_button_callback );
163  glfwSetScrollCallback( mHandle, glfw_scroll_callback );
164  glfwSetDropCallback( mHandle, glfw_drop_callback );
165 
166  return true;
167 }
168 
170 {
171  if ( mHandle )
172  {
173  dispatchDestroyEvent();
174  glfwDestroyWindow( mHandle );
175  mWinMap.erase( mHandle );
176  mHandle = NULL;
177  }
178 }
179 
181 {
182  if ( mHandle )
183  {
184  glfwMakeContextCurrent( mHandle );
185  }
186 }
187 
189  dispatchUpdateEvent();
190 }
191 
193  if ( mHandle )
194  {
195  glfwSwapBuffers( mHandle );
196  }
197 }
198 
199 void GLFWWindow::glfw_size_callback(GLFWwindow* window, int w, int h)
200 {
201  WinMapType::iterator it = mWinMap.find( window );
202  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
203  if ( vlwin ) {
204  vlwin->dispatchResizeEvent( w, h );
205  }
206 }
207 
208 void GLFWWindow::glfw_pos_callback(GLFWwindow* window, int x, int y)
209 {
210  WinMapType::iterator it = mWinMap.find( window );
211  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
212  if ( vlwin ) {
213  // At the moment we don't have such event
214  // vlwin->dispatchPositionEvent( focused );
215  }
216 }
217 
218 void GLFWWindow::glfw_refresh_callback(GLFWwindow* window)
219 {
220  WinMapType::iterator it = mWinMap.find( window );
221  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
222  if ( vlwin ) {
223  vlwin->dispatchUpdateEvent();
224  }
225 }
226 
227 void GLFWWindow::glfw_close_callback(GLFWwindow* window)
228 {
229  if ( glfwWindowShouldClose( window ) ) {
230  WinMapType::iterator it = mWinMap.find( window );
231  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
232  if ( vlwin ) {
233  vlwin->destroyWindow();
234  }
235  }
236 }
237 
238 void GLFWWindow::glfw_focus_callback(GLFWwindow* window, int focused)
239 {
240  WinMapType::iterator it = mWinMap.find( window );
241  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
242  if ( vlwin ) {
243  // At the moment we don't have such event
244  // vlwin->dispatchFocusEvent( focused );
245  }
246 }
247 
248 void GLFWWindow::glfw_iconify_callback(GLFWwindow* window, int iconified)
249 {
250  WinMapType::iterator it = mWinMap.find( window );
251  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
252  if ( vlwin ) {
253  vlwin->dispatchVisibilityEvent( ! iconified );
254  }
255 }
256 
257 void GLFWWindow::glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
258 {
259  WinMapType::iterator it = mWinMap.find( window );
260  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
261  if ( vlwin ) {
262  vl::EKey vlkey = translateKey( key, scancode, mods );
263 
264  switch( action ) {
265  case GLFW_PRESS:
266  vlwin->dispatchKeyPressEvent( 0, vlkey );
267  break;
268  case GLFW_RELEASE:
269  vlwin->dispatchKeyReleaseEvent( vlwin->mUnicodeChar, vlkey );
270  vlwin->mUnicodeChar = 0;
271  break;
272  case GLFW_REPEAT:
273  break;
274  }
275  }
276 }
277 
278 void GLFWWindow::glfw_unicode_callback(GLFWwindow* window, unsigned int unicode)
279 {
280  WinMapType::iterator it = mWinMap.find( window );
281  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
282  if ( vlwin ) {
283  // Note: this event is triggered after key press but before key release
284  // this is a work around in order to get the unicode of the currently
285  // pressed key - for a better input experience one should hook into this
286  // callback directly without relying on key press/release events.
287  vlwin->mUnicodeChar = (unsigned int)unicode;
288  }
289 }
290 
291 void GLFWWindow::glfw_cursor_enter_callback(GLFWwindow* window, int entered)
292 {
293  WinMapType::iterator it = mWinMap.find( window );
294  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
295  if ( vlwin ) {
296  // At the moment we don't have such event
297  }
298 }
299 
300 void GLFWWindow::glfw_cursor_pos_callback(GLFWwindow* window, double dx, double dy)
301 {
302  WinMapType::iterator it = mWinMap.find( window );
303  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
304  if ( vlwin ) {
305  int x = floor(dx);
306  int y = floor(dy);
307  vlwin->dispatchMouseMoveEvent( x, y );
308  }
309 }
310 
311 void GLFWWindow::glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
312 {
313  WinMapType::iterator it = mWinMap.find( window );
314  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
315  if ( vlwin ) {
317  switch( button )
318  {
319  case GLFW_MOUSE_BUTTON_LEFT:
320  btn = vl::LeftButton;
321  break;
322  case GLFW_MOUSE_BUTTON_MIDDLE:
323  btn = vl::MiddleButton;
324  break;
325  case GLFW_MOUSE_BUTTON_RIGHT:
326  btn = vl::RightButton;
327  break;
328  }
329 
330  double dx = 0, dy = 0;
331  glfwGetCursorPos( window, &dx, &dy );
332  int x = floor(dx);
333  int y = floor(dy);
334 
335  if (action == GLFW_PRESS)
336  vlwin->dispatchMouseDownEvent(btn, x, y);
337  else
338  if (action == GLFW_RELEASE)
339  vlwin->dispatchMouseUpEvent(btn, x, y);
340  }
341 }
342 
343 void GLFWWindow::glfw_scroll_callback(GLFWwindow* window, double dx, double dy)
344 {
345  WinMapType::iterator it = mWinMap.find( window );
346  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
347  if ( vlwin ) {
348  int x = floor(dx);
349  int y = floor(dy);
350  vlwin->dispatchMouseWheelEvent( y );
351  }
352 }
353 
354 void GLFWWindow::glfw_drop_callback(GLFWwindow * window, int count, const char** df)
355 {
356  WinMapType::iterator it = mWinMap.find( window );
357  GLFWWindow* vlwin = it != mWinMap.end() ? it->second : NULL;
358  if ( vlwin ) {
359  std::vector<String> files;
360  for(int i=0; i<count; ++i) {
361  files.push_back( df[ i ] );
362  }
363  vlwin->dispatchFileDroppedEvent( files );
364  }
365 }
366 
368 {
369  if ( mHandle )
370  {
371  mFullscreen = fs;
372  GLFWmonitor* monitor = glfwGetPrimaryMonitor();
373  const GLFWvidmode* mode = glfwGetVideoMode( monitor );
374  int x = 100;
375  int y = 100;
376  int w = 512;
377  int h = 512;
378  int r = GLFW_DONT_CARE;
379  if ( fs ) {
380  x = 0;
381  y = 0;
382  w = mode->width;
383  h = mode->height;
384  r = mode->refreshRate;
385  } else {
386  monitor = 0;
387  }
388  glfwSetWindowMonitor( mHandle, monitor, x, y, w, h, r );
389  if ( ! fs ) {
390  setPosition( x, y );
391  }
392  return true;
393  }
394 
395  return false;
396 }
397 
399 {
400  if ( mHandle )
401  {
402  glfwSetWindowTitle( mHandle, title.toStdString().c_str() );
403  }
404 }
405 
406 void GLFWWindow::setPosition(int x, int y)
407 {
408  if ( mHandle )
409  {
410  glfwSetWindowPos( mHandle, x, y );
411  }
412 }
413 
414 void GLFWWindow::setSize(int w, int h)
415 {
416  if ( mHandle )
417  {
418  glfwSetWindowSize( mHandle, w, h );
419  }
420 }
421 
423 {
424  int x = 0, y = 0;
425  if ( mHandle )
426  {
427  glfwGetWindowPos( mHandle, &x, &y );
428  }
429  return vl::ivec2( x, y );
430 }
431 
433 {
434  int w = 0, h = 0;
435  if ( mHandle )
436  {
437  glfwGetWindowSize( mHandle, &w, &h );
438  }
439  return vl::ivec2( w, h );
440 }
441 
443 {
444  if ( mHandle )
445  {
446  glfwShowWindow( mHandle );
447  }
448 }
449 
451 {
452  if ( mHandle )
453  {
454  glfwHideWindow( mHandle );
455  }
456 }
457 
459 {
460  if ( mHandle )
461  {
462  glfwFocusWindow( mHandle );
463  }
464 }
465 
466 void GLFWWindow::setMouseVisible(bool visible)
467 {
468  if ( mHandle )
469  {
470  glfwSetInputMode( mHandle, GLFW_CURSOR, visible ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED );
471  }
472 }
473 
475 {
476  if ( mHandle )
477  {
478  glfwSetCursorPos( mHandle, x, y );
479  }
480 }
481 
482 vl::EKey GLFWWindow::translateKey(int key, int scancode, int mods)
483 {
484  // Other keys depending on keyboard layout
485  // vl::Key_Exclam
486  // vl::Key_QuoteDbl
487  // vl::Key_Hash
488  // vl::Key_Dollar
489  // vl::Key_Ampersand
490  // vl::Key_LeftParen
491  // vl::Key_RightParen
492  // vl::Key_Asterisk
493  // vl::Key_Plus
494  // vl::Key_Colon
495  // vl::Key_Less
496  // vl::Key_Greater
497  // vl::Key_Question
498  // vl::Key_At
499  // vl::Key_Caret
500  // vl::Key_Underscore
501 
502  switch( key ) {
503  default: return vl::Key_Unknown;
504  case GLFW_KEY_UNKNOWN: return vl::Key_Unknown;
505  case GLFW_KEY_SPACE: return vl::Key_Space;
506  case GLFW_KEY_APOSTROPHE: vl::Key_Quote;
507  case GLFW_KEY_COMMA: return vl::Key_Comma;
508  case GLFW_KEY_MINUS: return vl::Key_Minus;
509  case GLFW_KEY_PERIOD: return vl::Key_Period;
510  case GLFW_KEY_SLASH: return vl::Key_Slash;
511  case GLFW_KEY_0: return vl::Key_0;
512  case GLFW_KEY_1: return vl::Key_1;
513  case GLFW_KEY_2: return vl::Key_2;
514  case GLFW_KEY_3: return vl::Key_3;
515  case GLFW_KEY_4: return vl::Key_4;
516  case GLFW_KEY_5: return vl::Key_5;
517  case GLFW_KEY_6: return vl::Key_6;
518  case GLFW_KEY_7: return vl::Key_7;
519  case GLFW_KEY_8: return vl::Key_8;
520  case GLFW_KEY_9: return vl::Key_9;
521  case GLFW_KEY_SEMICOLON: return vl::Key_Semicolon;
522  case GLFW_KEY_EQUAL: return vl::Key_Equal;
523  case GLFW_KEY_A: return vl::Key_A;
524  case GLFW_KEY_B: return vl::Key_B;
525  case GLFW_KEY_C: return vl::Key_C;
526  case GLFW_KEY_D: return vl::Key_D;
527  case GLFW_KEY_E: return vl::Key_E;
528  case GLFW_KEY_F: return vl::Key_F;
529  case GLFW_KEY_G: return vl::Key_G;
530  case GLFW_KEY_H: return vl::Key_H;
531  case GLFW_KEY_I: return vl::Key_I;
532  case GLFW_KEY_J: return vl::Key_J;
533  case GLFW_KEY_K: return vl::Key_K;
534  case GLFW_KEY_L: return vl::Key_L;
535  case GLFW_KEY_M: return vl::Key_M;
536  case GLFW_KEY_N: return vl::Key_N;
537  case GLFW_KEY_O: return vl::Key_O;
538  case GLFW_KEY_P: return vl::Key_P;
539  case GLFW_KEY_Q: return vl::Key_Q;
540  case GLFW_KEY_R: return vl::Key_R;
541  case GLFW_KEY_S: return vl::Key_S;
542  case GLFW_KEY_T: return vl::Key_T;
543  case GLFW_KEY_U: return vl::Key_U;
544  case GLFW_KEY_V: return vl::Key_V;
545  case GLFW_KEY_W: return vl::Key_W;
546  case GLFW_KEY_X: return vl::Key_X;
547  case GLFW_KEY_Y: return vl::Key_Y;
548  case GLFW_KEY_Z: return vl::Key_Z;
549  case GLFW_KEY_LEFT_BRACKET: return vl::Key_LeftBracket;
550  case GLFW_KEY_BACKSLASH: return vl::Key_BackSlash;
551  case GLFW_KEY_RIGHT_BRACKET: return vl::Key_RightBracket;
552  case GLFW_KEY_GRAVE_ACCENT: vl::Key_QuoteLeft;
553  //case GLFW_KEY_WORLD_1:
554  //case GLFW_KEY_WORLD_2:
555  case GLFW_KEY_ESCAPE: return vl::Key_Escape;
556  case GLFW_KEY_ENTER: return vl::Key_Return;
557  case GLFW_KEY_TAB: return vl::Key_Tab;
558  case GLFW_KEY_BACKSPACE: return vl::Key_BackSpace;
559  case GLFW_KEY_INSERT: return vl::Key_Insert;
560  case GLFW_KEY_DELETE: return vl::Key_Delete;
561  case GLFW_KEY_RIGHT: return vl::Key_Right;
562  case GLFW_KEY_LEFT: return vl::Key_Left;
563  case GLFW_KEY_DOWN: return vl::Key_Down;
564  case GLFW_KEY_UP: return vl::Key_Up;
565  case GLFW_KEY_PAGE_UP: return vl::Key_PageUp;
566  case GLFW_KEY_PAGE_DOWN: return vl::Key_PageDown;
567  case GLFW_KEY_HOME: return vl::Key_Home;
568  case GLFW_KEY_END: return vl::Key_End;
569  //case GLFW_KEY_CAPS_LOCK:
570  //case GLFW_KEY_SCROLL_LOCK:
571  //case GLFW_KEY_NUM_LOCK:
572  case GLFW_KEY_PRINT_SCREEN: vl::Key_Print;
573  case GLFW_KEY_PAUSE: return vl::Key_Pause;
574  case GLFW_KEY_F1: return vl::Key_F1;
575  case GLFW_KEY_F2: return vl::Key_F2;
576  case GLFW_KEY_F3: return vl::Key_F3;
577  case GLFW_KEY_F4: return vl::Key_F4;
578  case GLFW_KEY_F5: return vl::Key_F5;
579  case GLFW_KEY_F6: return vl::Key_F6;
580  case GLFW_KEY_F7: return vl::Key_F7;
581  case GLFW_KEY_F8: return vl::Key_F8;
582  case GLFW_KEY_F9: return vl::Key_F9;
583  case GLFW_KEY_F10: return vl::Key_F10;
584  case GLFW_KEY_F11: return vl::Key_F11;
585  case GLFW_KEY_F12: return vl::Key_F12;
586  //case GLFW_KEY_F13:
587  //case GLFW_KEY_F14:
588  //case GLFW_KEY_F15:
589  //case GLFW_KEY_F16:
590  //case GLFW_KEY_F17:
591  //case GLFW_KEY_F18:
592  //case GLFW_KEY_F19:
593  //case GLFW_KEY_F20:
594  //case GLFW_KEY_F21:
595  //case GLFW_KEY_F22:
596  //case GLFW_KEY_F23:
597  //case GLFW_KEY_F24:
598  //case GLFW_KEY_F25:
599  case GLFW_KEY_KP_0: return vl::Key_0;
600  case GLFW_KEY_KP_1: return vl::Key_1;
601  case GLFW_KEY_KP_2: return vl::Key_2;
602  case GLFW_KEY_KP_3: return vl::Key_3;
603  case GLFW_KEY_KP_4: return vl::Key_4;
604  case GLFW_KEY_KP_5: return vl::Key_5;
605  case GLFW_KEY_KP_6: return vl::Key_6;
606  case GLFW_KEY_KP_7: return vl::Key_7;
607  case GLFW_KEY_KP_8: return vl::Key_8;
608  case GLFW_KEY_KP_9: return vl::Key_9;
609  case GLFW_KEY_KP_DECIMAL: return vl::Key_Period;
610  case GLFW_KEY_KP_DIVIDE: return vl::Key_Slash;
611  case GLFW_KEY_KP_MULTIPLY: return vl::Key_Asterisk;
612  case GLFW_KEY_KP_SUBTRACT: return vl::Key_Minus;
613  case GLFW_KEY_KP_ADD: return vl::Key_Plus;
614  case GLFW_KEY_KP_ENTER: return vl::Key_Return;
615  case GLFW_KEY_KP_EQUAL: return vl::Key_Equal;
616  case GLFW_KEY_LEFT_SHIFT: return vl::Key_Shift;
617  case GLFW_KEY_LEFT_CONTROL: return vl::Key_Ctrl;
618  case GLFW_KEY_LEFT_ALT: return vl::Key_Alt;
619  //case GLFW_KEY_LEFT_SUPER:
620  case GLFW_KEY_RIGHT_SHIFT: return vl::Key_Shift;
621  case GLFW_KEY_RIGHT_CONTROL: return vl::Key_Ctrl;
622  case GLFW_KEY_RIGHT_ALT: return vl::Key_Alt;
623  //case GLFW_KEY_RIGHT_SUPER:
624  // case GLFW_KEY_MENU:
625  }
626 }
627 
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:442
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:466
void hide()
If the OpenGL context is a widget this function makes it invisible to the user.
Definition: GLFWWindow.cpp:450
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:311
static void glfw_focus_callback(GLFWwindow *window, int)
Definition: GLFWWindow.cpp:238
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:278
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:257
static void glfw_size_callback(GLFWwindow *window, int w, int h)
Definition: GLFWWindow.cpp:199
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:367
static void glfw_pos_callback(GLFWwindow *window, int x, int y)
Definition: GLFWWindow.cpp:208
void swapBuffers()
Swaps the back and front buffers to present the last rendering.
Definition: GLFWWindow.cpp:192
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:398
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:248
const T_Scalar & g() const
Definition: Vector4.hpp:112
vl::ivec2 size() const
Definition: GLFWWindow.cpp:432
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:458
const ivec4 & accumRGBABits() const
static void glfw_refresh_callback(GLFWwindow *window)
Definition: GLFWWindow.cpp:218
static void glfw_close_callback(GLFWwindow *window)
Definition: GLFWWindow.cpp:227
EMouseButton
static vl::EKey translateKey(int key, int scancode, int mods)
Definition: GLFWWindow.cpp:482
void setPosition(int x, int y)
If the OpenGL context is a widget this function sets its position.
Definition: GLFWWindow.cpp:406
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:300
void setSize(int w, int h)
If the OpenGL context is a widget this function sets its size.
Definition: GLFWWindow.cpp:414
EOpenGLProfile openGLProfile() const
static void glfw_scroll_callback(GLFWwindow *, double, double)
Definition: GLFWWindow.cpp:343
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:354
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:422
T floor(T a)
Definition: glsl_math.hpp:698
void makeCurrent()
Sets the OpenGL context as current for the calling thread.
Definition: GLFWWindow.cpp:180
static void glfw_cursor_enter_callback(GLFWwindow *, int)
Definition: GLFWWindow.cpp:291
void setMousePosition(int x, int y)
If the OpenGL context is a widget this function sets the mouse position.
Definition: GLFWWindow.cpp:474
void update()
If the OpenGLContext is a widget this function requests a redraw and generates an updateEvent()...
Definition: GLFWWindow.cpp:188
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...