Flu_GL_Window.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // $Id: Flu_GL_Window.cpp,v 1.24 2004/12/08 20:18:57 jbryan Exp $
  2. /***************************************************************
  3. * FLU - FLTK Utility Widgets
  4. * Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
  5. *
  6. * This file and its content is protected by a software license.
  7. * You should have received a copy of this license with this file.
  8. * If not, please contact the Ohio Supercomputer Center immediately:
  9. * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
  10. *
  11. ***************************************************************/
  12. #include "FLU/Flu_GL_Window.H"
  13. Flu_GL_Window::AllInitProto Flu_GL_Window::allInitCB = 0;
  14. void* Flu_GL_Window::allInitCBD = 0;
  15. Flu_GL_Window :: Flu_GL_Window( int x, int y, int w, int h, const char *label )
  16. : Fl_Gl_Window( x, y, w, h, label )
  17. {
  18. _lastContext = 0;
  19. cartesianInput( true );
  20. _drawCB = NULL; _drawCBD = NULL;
  21. _resizeCB = NULL; _resizeCBD = NULL;
  22. _initCB = NULL; _initCBD = NULL;
  23. _mouseWheelCB = NULL; _mouseWheelCBD = NULL;
  24. _mouseDownCB = NULL; _mouseDownCBD = NULL;
  25. _mouseUpCB = NULL; _mouseUpCBD = NULL;
  26. _mouseDragCB = NULL; _mouseDragCBD = NULL;
  27. _mouseMoveCB = NULL; _mouseMoveCBD = NULL;
  28. _keyboardCB = NULL; _keyboardCBD = NULL;
  29. _enterCB = NULL; _enterCBD = NULL;
  30. _exitCB = NULL; _exitCBD = NULL;
  31. //_firstDraw = true;
  32. end();
  33. }
  34. Flu_GL_Window :: Flu_GL_Window( int w, int h, const char *label )
  35. : Fl_Gl_Window( w, h, label )
  36. {
  37. _lastContext = 0;
  38. cartesianInput( true );
  39. _drawCB = NULL; _drawCBD = NULL;
  40. _resizeCB = NULL; _resizeCBD = NULL;
  41. _initCB = NULL; _initCBD = NULL;
  42. _mouseWheelCB = NULL; _mouseWheelCBD = NULL;
  43. _mouseDownCB = NULL; _mouseDownCBD = NULL;
  44. _mouseUpCB = NULL; _mouseUpCBD = NULL;
  45. _mouseDragCB = NULL; _mouseDragCBD = NULL;
  46. _mouseMoveCB = NULL; _mouseMoveCBD = NULL;
  47. _keyboardCB = NULL; _keyboardCBD = NULL;
  48. _enterCB = NULL; _enterCBD = NULL;
  49. _exitCB = NULL; _exitCBD = NULL;
  50. //_firstDraw = true;
  51. end();
  52. }
  53. Flu_GL_Window :: ~Flu_GL_Window()
  54. {
  55. }
  56. void Flu_GL_Window :: redraw()
  57. {
  58. Fl_Gl_Window::redraw();
  59. }
  60. int Flu_GL_Window :: handle( int event )
  61. {
  62. //if( !context() )
  63. //_firstDraw = true;
  64. if( !context() || !visible() )
  65. return Fl_Gl_Window::handle( event );
  66. int x = Fl::event_x(), y = Fl::event_y();
  67. if( _cartesian )
  68. y = h() - 1 - y;
  69. switch( event )
  70. {
  71. case FL_MOVE:
  72. {
  73. // make sure the GL context is current in case the callback needs it
  74. Fl_Group *current = Fl_Group::current();
  75. make_current();
  76. if( _mouseMoveCB )
  77. _mouseMoveCB( x, y, _mouseMoveCBD );
  78. Fl_Group::current( current );
  79. return 1;
  80. }
  81. case FL_DRAG:
  82. {
  83. // make sure the GL context is current in case the callback needs it
  84. Fl_Group *current = Fl_Group::current();
  85. make_current();
  86. if( _mouseDragCB )
  87. _mouseDragCB( x, y, _mouseDragCBD );
  88. Fl_Group::current( current );
  89. return 1;
  90. }
  91. case FL_PUSH:
  92. {
  93. // make sure the GL context is current in case the callback needs it
  94. Fl_Group *current = Fl_Group::current();
  95. make_current();
  96. if( _mouseDownCB )
  97. _mouseDownCB( Fl::event_button(), x, y, _mouseDownCBD );
  98. Fl_Group::current( current );
  99. return 1;
  100. }
  101. case FL_RELEASE:
  102. {
  103. // make sure the GL context is current in case the callback needs it
  104. Fl_Group *current = Fl_Group::current();
  105. make_current();
  106. if( _mouseUpCB )
  107. _mouseUpCB( Fl::event_button(), x, y, _mouseUpCBD );
  108. Fl_Group::current( current );
  109. return 1;
  110. }
  111. case FL_MOUSEWHEEL:
  112. {
  113. // make sure the GL context is current in case the callback needs it
  114. Fl_Group *current = Fl_Group::current();
  115. make_current();
  116. if( _mouseWheelCB )
  117. _mouseWheelCB( Fl::event_dx(), Fl::event_dy(), x, y, _mouseWheelCBD );
  118. Fl_Group::current( current );
  119. return 1;
  120. }
  121. case FL_FOCUS :
  122. case FL_UNFOCUS :
  123. return 1;
  124. case FL_ENTER:
  125. {
  126. // make sure the GL context is current in case the callback needs it
  127. Fl_Group *current = Fl_Group::current();
  128. make_current();
  129. if( _enterCB )
  130. _enterCB( _enterCBD );
  131. Fl_Group::current( current );
  132. return 1;
  133. }
  134. case FL_LEAVE:
  135. {
  136. // make sure the GL context is current in case the callback needs it
  137. Fl_Group *current = Fl_Group::current();
  138. make_current();
  139. if( _exitCB )
  140. _exitCB( _exitCBD );
  141. Fl_Group::current( current );
  142. return 1;
  143. }
  144. case FL_KEYUP:
  145. // make sure the GL context is current in case the callback needs it
  146. //make_current();
  147. if( _keyboardCB )
  148. _keyboardCB( Fl::event_key(), x, y, _keyboardCBD );
  149. return Fl_Gl_Window::handle( event );
  150. default:
  151. // pass other events to the base class...
  152. return Fl_Gl_Window::handle( event );
  153. }
  154. }
  155. void Flu_GL_Window :: draw()
  156. {
  157. if( !context() )
  158. return;
  159. //if( _firstDraw )
  160. if( _lastContext != context() )
  161. {
  162. //_firstDraw = false;
  163. if( allInitCB )
  164. allInitCB( allInitCBD );
  165. if( _initCB )
  166. _initCB( _initCBD );
  167. _lastContext = context();
  168. }
  169. if( !valid() )
  170. {
  171. if( _resizeCB )
  172. _resizeCB( w(), h(), _resizeCBD );
  173. }
  174. if( _drawCB )
  175. _drawCB( _drawCBD );
  176. }