Flu_GL_Window.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // $Id: Flu_GL_Window.cpp,v 1.21 2004/07/27 19:34:29 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. cartesianInput( true );
  19. _drawCB = NULL; _drawCBD = NULL;
  20. _resizeCB = NULL; _resizeCBD = NULL;
  21. _initCB = NULL; _initCBD = NULL;
  22. _mouseWheelCB = NULL; _mouseWheelCBD = NULL;
  23. _mouseDownCB = NULL; _mouseDownCBD = NULL;
  24. _mouseUpCB = NULL; _mouseUpCBD = NULL;
  25. _mouseDragCB = NULL; _mouseDragCBD = NULL;
  26. _mouseMoveCB = NULL; _mouseMoveCBD = NULL;
  27. _keyboardCB = NULL; _keyboardCBD = NULL;
  28. _enterCB = NULL; _enterCBD = NULL;
  29. _exitCB = NULL; _exitCBD = NULL;
  30. _firstDraw = true;
  31. end();
  32. }
  33. Flu_GL_Window :: Flu_GL_Window( int w, int h, const char *label )
  34. : Fl_Gl_Window( w, h, label )
  35. {
  36. cartesianInput( true );
  37. _drawCB = NULL; _drawCBD = NULL;
  38. _resizeCB = NULL; _resizeCBD = NULL;
  39. _initCB = NULL; _initCBD = NULL;
  40. _mouseWheelCB = NULL; _mouseWheelCBD = NULL;
  41. _mouseDownCB = NULL; _mouseDownCBD = NULL;
  42. _mouseUpCB = NULL; _mouseUpCBD = NULL;
  43. _mouseDragCB = NULL; _mouseDragCBD = NULL;
  44. _mouseMoveCB = NULL; _mouseMoveCBD = NULL;
  45. _keyboardCB = NULL; _keyboardCBD = NULL;
  46. _enterCB = NULL; _enterCBD = NULL;
  47. _exitCB = NULL; _exitCBD = NULL;
  48. _firstDraw = true;
  49. end();
  50. }
  51. Flu_GL_Window :: ~Flu_GL_Window()
  52. {
  53. }
  54. void Flu_GL_Window :: redraw()
  55. {
  56. Fl_Gl_Window::redraw();
  57. }
  58. int Flu_GL_Window :: handle( int event )
  59. {
  60. if( !context() )
  61. _firstDraw = true;
  62. if( !context() || !visible() )
  63. return Fl_Gl_Window::handle( event );
  64. int x = Fl::event_x(), y = Fl::event_y();
  65. if( _cartesian )
  66. y = h() - 1 - y;
  67. switch( event )
  68. {
  69. case FL_MOVE:
  70. {
  71. // make sure the GL context is current in case the callback needs it
  72. Fl_Group *current = Fl_Group::current();
  73. make_current();
  74. if( _mouseMoveCB )
  75. _mouseMoveCB( x, y, _mouseMoveCBD );
  76. Fl_Group::current( current );
  77. return 1;
  78. }
  79. case FL_DRAG:
  80. {
  81. // make sure the GL context is current in case the callback needs it
  82. Fl_Group *current = Fl_Group::current();
  83. make_current();
  84. if( _mouseDragCB )
  85. _mouseDragCB( x, y, _mouseDragCBD );
  86. Fl_Group::current( current );
  87. return 1;
  88. }
  89. case FL_PUSH:
  90. {
  91. // make sure the GL context is current in case the callback needs it
  92. Fl_Group *current = Fl_Group::current();
  93. make_current();
  94. if( _mouseDownCB )
  95. _mouseDownCB( Fl::event_button(), x, y, _mouseDownCBD );
  96. Fl_Group::current( current );
  97. return 1;
  98. }
  99. case FL_RELEASE:
  100. {
  101. // make sure the GL context is current in case the callback needs it
  102. Fl_Group *current = Fl_Group::current();
  103. make_current();
  104. if( _mouseUpCB )
  105. _mouseUpCB( Fl::event_button(), x, y, _mouseUpCBD );
  106. Fl_Group::current( current );
  107. return 1;
  108. }
  109. case FL_MOUSEWHEEL:
  110. {
  111. // make sure the GL context is current in case the callback needs it
  112. Fl_Group *current = Fl_Group::current();
  113. make_current();
  114. if( _mouseWheelCB )
  115. _mouseWheelCB( Fl::event_dx(), Fl::event_dy(), x, y, _mouseWheelCBD );
  116. Fl_Group::current( current );
  117. return 1;
  118. }
  119. case FL_FOCUS :
  120. case FL_UNFOCUS :
  121. return 1;
  122. case FL_ENTER:
  123. {
  124. // make sure the GL context is current in case the callback needs it
  125. Fl_Group *current = Fl_Group::current();
  126. make_current();
  127. if( _enterCB )
  128. _enterCB( _enterCBD );
  129. Fl_Group::current( current );
  130. return 1;
  131. }
  132. case FL_LEAVE:
  133. {
  134. // make sure the GL context is current in case the callback needs it
  135. Fl_Group *current = Fl_Group::current();
  136. make_current();
  137. if( _exitCB )
  138. _exitCB( _exitCBD );
  139. Fl_Group::current( current );
  140. return 1;
  141. }
  142. case FL_KEYUP:
  143. // make sure the GL context is current in case the callback needs it
  144. //make_current();
  145. if( _keyboardCB )
  146. _keyboardCB( Fl::event_key(), x, y, _keyboardCBD );
  147. return Fl_Gl_Window::handle( event );
  148. default:
  149. // pass other events to the base class...
  150. return Fl_Gl_Window::handle( event );
  151. }
  152. }
  153. void Flu_GL_Window :: draw()
  154. {
  155. if( !context() )
  156. return;
  157. if( _firstDraw )
  158. {
  159. _firstDraw = false;
  160. if( allInitCB )
  161. allInitCB( allInitCBD );
  162. if( _initCB )
  163. _initCB( _initCBD );
  164. }
  165. if( !valid() )
  166. {
  167. if( _resizeCB )
  168. _resizeCB( w(), h(), _resizeCBD );
  169. }
  170. if( _drawCB )
  171. _drawCB( _drawCBD );
  172. }