Flu_GL_Window.H 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // $Id: Flu_GL_Window.h,v 1.13 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. #ifndef _FLU_GL_WINDOW_H
  13. #define _FLU_GL_WINDOW_H
  14. #include <stdio.h>
  15. /* fltk includes */
  16. #include <FL/Fl.H>
  17. #include <FL/Fl_Gl_Window.H>
  18. #include "FLU/Flu_Enumerations.H"
  19. //! A class designed to supply an easier, more functional FLTK GL window, with callback functionality similar to GLUT.
  20. class FLU_EXPORT Flu_GL_Window : public Fl_Gl_Window
  21. {
  22. public:
  23. //! Normal FLTK widget constructor
  24. Flu_GL_Window( int x, int y, int w, int h, const char *label = 0 );
  25. //! Top-level window constructor
  26. Flu_GL_Window( int w, int h, const char *label = 0 );
  27. //! Default destructor
  28. virtual ~Flu_GL_Window();
  29. //! Force this window to redraw
  30. void redraw();
  31. //! \return \c true if the OpenGL context managed by this window is valid to take OpenGL calls, \c false otherwise
  32. /*! \note This does not mean this context is the current one taking OpenGL calls, only that it *can* take calls
  33. when it becomes current. */
  34. inline bool is_context_valid()
  35. { return( can_do() > 0 ); }
  36. //! Setting this to \c true will report mouse input in cartesian coordinates instead of window coordinates.
  37. /*! Default is \c true */
  38. inline void cartesianInput( bool b )
  39. { _cartesian = b; }
  40. //! \return \c true if mouse input is reported in cartesian coordinates, \c false otherwise
  41. inline bool cartesianInput() const
  42. { return _cartesian; }
  43. /*! \name Drawing/Input Callback Registration
  44. * The registered functions will be called on the indicated event.
  45. */
  46. //@{
  47. //! The passed function must have the following signature: (void *user_data)
  48. inline void setInitFunc( void (*cb)(void*), void* cbd = NULL )
  49. { _initCB = cb; _initCBD = cbd; }
  50. //! The passed function must have the following signature: (int width, int height, void *user_data)
  51. /*! \b width and \b height represent the new size of the OpenGL context */
  52. inline void setResizeFunc( void (*cb)(int, int, void*), void* cbd = NULL )
  53. { _resizeCB = cb; _resizeCBD = cbd; }
  54. //! The passed function must have the following signature: (void *user_data)
  55. inline void setDrawFunc( void (*cb)(void*), void* cbd = NULL )
  56. { _drawCB = cb; _drawCBD = cbd; }
  57. //! The passed function must have the following signature: (int dx, int dy, int x, int y)
  58. /*! \b dx and \b dy represent the amount of movement of the mouse wheel (usually 1 or -1),
  59. and \b x and \b y represent where in the OpenGL context the event ocurred. */
  60. inline void setMouseWheelFunc( void (*cb)(int, int, int, int, void*), void* cbd = NULL )
  61. { _mouseWheelCB = cb; _mouseWheelCBD = cbd; }
  62. //! The passed function must have the following signature: (int button, int x, int y, void *user_data)
  63. /*! \b button is which mouse button generated the event: { \c FL_LEFT_MOUSE | \c FL_RIGHT_MOUSE | \c FL_MIDDLE_MOUSE },
  64. and \b x and \b y represent where in the OpenGL context the event ocurred. */
  65. inline void setMouseDownFunc( void (*cb)(int, int, int, void*), void* cbd = NULL )
  66. { _mouseDownCB = cb; _mouseDownCBD = cbd; }
  67. //! The passed function must have the following signature: (int button, int x, int y, void *user_data)
  68. /*! \b button is which mouse button generated the event: { \c FL_LEFT_MOUSE | \c FL_RIGHT_MOUSE | \c FL_MIDDLE_MOUSE },
  69. and \b x and \b y represent where in the OpenGL context the event ocurred. */
  70. inline void setMouseUpFunc( void (*cb)(int, int, int, void*), void* cbd = NULL )
  71. { _mouseUpCB = cb; _mouseUpCBD = cbd; }
  72. //! The passed function must have the following signature: (int x, int y, void *user_data)
  73. /*! \b x and \b y represent where in the OpenGL context the event ocurred. */
  74. inline void setMouseDragFunc( void (*cb)(int, int, void*), void* cbd = NULL )
  75. { _mouseDragCB = cb; _mouseDragCBD = cbd; }
  76. //! The passed function must have the following signature:(int x, int y, void *user_data)
  77. /*! \b x and \b y represent where in the OpenGL context the event ocurred. */
  78. inline void setMouseMoveFunc( void (*cb)(int, int, void*), void* cbd = NULL )
  79. { _mouseMoveCB = cb; _mouseMoveCBD = cbd; }
  80. //! The passed function must have the following signature: (void *user_data)
  81. inline void setMouseEnterFunc( void (*cb)(void*), void* cbd = NULL )
  82. { _enterCB = cb; _enterCBD = cbd; }
  83. //! The passed function must have the following signature: (void *user_data)
  84. inline void setMouseExitFunc( void (*cb)(void*), void* cbd = NULL )
  85. { _exitCB = cb; _exitCBD = cbd; }
  86. //! The passed function must have the following signature: (int key, int x, int y, void *user_data)
  87. /*! \b key is which key generated the event,
  88. and \b x and \b y represent where in the OpenGL context the event ocurred. */
  89. inline void setKeyboardFunc( void (*cb)(int, int, int, void*), void* cbd = NULL )
  90. { _keyboardCB = cb; _keyboardCBD = cbd; }
  91. //@}
  92. //! Set a function that will be called each time a new OpenGL context is created
  93. /*! This is useful for doing something globally specific for all contexts, such as
  94. loading OpenGL API entrypoints under Windows. */
  95. inline static void setAllInitFunc( void (*cb)(void*), void* cbd = NULL )
  96. { allInitCB = cb; allInitCBD = cbd; }
  97. protected:
  98. void (*_drawCB)(void*);
  99. void* _drawCBD;
  100. void (*_resizeCB)(int, int, void*);
  101. void* _resizeCBD;
  102. void (*_initCB)(void*);
  103. void* _initCBD;
  104. void (*_mouseWheelCB)(int, int, int, int, void*);
  105. void* _mouseWheelCBD;
  106. void (*_mouseDownCB)(int, int, int, void*);
  107. void* _mouseDownCBD;
  108. void (*_mouseUpCB)(int, int, int, void*);
  109. void* _mouseUpCBD;
  110. void (*_mouseDragCB)(int, int, void*);
  111. void* _mouseDragCBD;
  112. void (*_mouseMoveCB)(int, int, void*);
  113. void* _mouseMoveCBD;
  114. void (*_keyboardCB)(int, int, int, void*);
  115. void* _keyboardCBD;
  116. void (*_enterCB)(void*);
  117. void* _enterCBD;
  118. void (*_exitCB)(void*);
  119. void* _exitCBD;
  120. private:
  121. typedef void (*AllInitProto)(void*);
  122. static AllInitProto allInitCB;
  123. static void* allInitCBD;
  124. bool _firstDraw;
  125. bool _cartesian;
  126. void *_lastContext;
  127. /* overridden from Fl_Gl_Window */
  128. int handle( int event );
  129. void draw();
  130. };
  131. #endif