GL Studio C++ Runtime API
gls_display_frame.h
Go to the documentation of this file.
1 /*! \file
2  \brief disti::glsDisplayFrame class. The class for creating standalone executables.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2017 by The DiSTI Corporation.<br>
7  11301 Corporate Blvd; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13  This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36  The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38 
39 */
40 #ifndef GLS_DISPLAY_H
41 #define GLS_DISPLAY_H
42 
43 // This is just here to have somewhere to put it that will get documented by doxygen.
44 /** \class Fl_Gl_Window
45  * \htmlonly <dt><a href="fltk/Fl_Gl_Window.html">Fl_Gl_Window reference</a></dt> \endhtmlonly
46  * \htmlonly <dt><a href="fltk/index.html">Complete Fltk documentation</a></dt> \endhtmlonly
47  */
48 
49 #ifdef GLES
50 
51 # ifdef __APPLE__
52 # include "ios_display_frame.h"
53 # elif defined( ANDROID )
54 # include "android_display_frame.h"
55 # elif defined( EMSCRIPTEN )
56 # include "events.h"
57 # include "gls_gl.h"
58 # include "gls_include.h"
59 # include "timer.h"
60 # else
61 # include "embedded_display_frame.h"
62 namespace disti
63 {
64 typedef EmbeddedDisplayFrame glsDisplayFrame;
65 }
66 # endif
67 
68 #else
69 
70 # include "gls_include.h"
71 
72 # ifdef WIN32
73 # pragma warning( push )
74 # pragma warning( disable : 4244 )
75 # endif
76 # include <FL/Fl.H>
77 # include <FL/Fl_Box.H>
78 # include <FL/Fl_Gl_Window.H>
79 # include <FL/Fl_Window.H>
80 # ifdef WIN32
81 # pragma warning( pop )
82 # endif
83 
84 # include "events.h"
85 # include "runtime_display_frame.h"
86 # include "timer.h"
87 
88 class Fl_Gl_Window;
89 
90 namespace disti
91 {
92 class SplashDisplay;
93 class glsDisplayFrame;
94 
95 /** \class OpenGLWindow
96  * OpenGLWindow is a GL Studio specific implementation of the Fltk Fl_Gl_Window
97  */
98 class OpenGLWindow : public Fl_Gl_Window
99 {
100  glsDisplayFrame* frame; /**< The DisplayFrame associated with this window */
101  MouseEvent ev; /**< Last mouse event received */
102  KeyboardEvent kev; /**< Last keyboard event received */
103 
104  /** Overload of FLTK draw routine */
105  GLS_EXPORT void draw();
106 
107 public:
108  /** Overload of FLTK make_current() method. Sets this window as the current OpenGL context */
109  GLS_EXPORT void make_current();
110 
111  /** Overload of FLTK end() method. Used to signal FLTK to not make this the "current" window to add widgets to */
112  GLS_EXPORT void end();
113 
114  /** Overload of FLTK resizable() method. */
115  GLS_EXPORT void resizable( OpenGLWindow* win );
116 
117  /** Overload of FLTK resize() method. Resizes the window.
118  * \param x New x coordinate of window on screen
119  * \param y New y coordinate of window on screen
120  * \param w New width of window in pixels
121  * \param h New height of window in pixels
122  */
123  GLS_EXPORT void resize( int x, int y, int w, int h );
124 
125  /** Overload of FLTK show() method. Sets the visible flag for this window, causing it to be shown the next time
126  * the FLTK event loop is checked.
127  */
128  GLS_EXPORT void show();
129 
130  /** Overload of FLTK event handle routine. This is how mouse and keyboard events get passed in */
131  GLS_EXPORT int handle( int );
132 
133  /** Constructor for window
134  * \param x Initial x loc of window
135  * \param y Initial y loc of window
136  * \param w Initial width of window
137  * \param h Initial height of window
138  * \param l Window title
139  * \param frame_ Display to associate with window */
140  GLS_EXPORT OpenGLWindow( int x, int y, int w, int h, const char* l, glsDisplayFrame* frame_ );
141 
142  /** Grabs the window contents and saves them to an uncompressed 24 bit BMP file
143  * \param filename Name of the file to write a BMP to
144  */
145  GLS_EXPORT void GrabWindow( char* filename );
146 
147  /** Converts mouse window coordinates to logical simulation coordinates.
148  * \param frame DisplayFrame to convert for
149  * \param x Mouse Device coordinate
150  * \param y Mouse Device coordinate
151  * \param lx Filled in with logical X coordinate
152  * \param ly Filled in with logical Y coordinate
153  */
154  GLS_EXPORT void WindowToLogical( glsDisplayFrame* frame, float x, float y, float& lx, float& ly );
155 };
156 
157 typedef void ( *GlsDrawCallback )( glsDisplayFrame* );
158 
159 /** GL Studio standalone application class.
160  * Creates one window and draws all contents in it.
161  */
163 {
164 protected:
165  Timer frameTimer; /**< Timer used for scheduling */
166  float _smoothedFrameDelay; /**< Frame interval, smoothed based on actual draw performance */
167  bool _redraw; /**< Flag indicating if the window should be redrawn */
168 
169  float _width_offset; /**< Current "width" offset of window. Used for panning of display horizontally in ortho mode. */
170  float _height_offset; /**< Current "height" offset of window. Used for panning of display vertically in ortho mode. */
171  Vector _viewOffset;
172 
173  GlsDrawCallback _preDrawCallback; /**< A function pointer that will be called prior to the Draw method being called */
174  GlsDrawCallback _postDrawCallback; /**< A function pointer that will be called after the Draw method is called */
175 
176  SplashDisplay* splashDisplay; /**< The Spash screen image */
177 
178  int _current_view; /**< Current view of the canvas (e.g., ortho, perspective, eyepoint) */
179 
180  /** For better control over clipping and field of view, use a GlsEyePoint, but some limited functionality is available here */
181 
182  float _depthFactor; /**< Used for auto calculations */
183  double _fov; /**< Field Of View. If 0.0 (the default), fov will be auto calculated. */
184  double _nearZ; /**< Near clipping plane. Only meaningful if _autoCalcNearZ is false */
185  bool _autoCalcNearZ; /**< When true a _nearZ is automatically calculated. */
186  double _farZ; /**< Far clipping plane. Only meaningfull if _autoCalcVarZ is false */
187  bool _autoCalcFarZ; /**< When true a _farZ is automatically calculated. */
188 
189  bool _sKeyTogglesStatistics; /**< When true, the [s] key toggles statistics */
190  bool _escKeyExits; /**< When true, the [Esc] key exits the application */
191 
192  /* \see DisplayFrame */
193  virtual GLS_EXPORT EventCompressor<DisplayFrame>* GetEventCompressor() { return &eventCompressor; }
194 
195 public:
196  OpenGLWindow* theWindow; /**< The window associated with this DisplayFrame */
197 
198  /** Used for event compression. Not for general use by users. */
200 
201  /** Creates this glsDisplayFrame
202  * \param name Window Title
203  * \param width Width of Dsplay Frame in pixels
204  * \param height Width of Dsplay Frame in pixels
205  */
206  GLS_EXPORT glsDisplayFrame( const char* name, int width, int height );
207 
208  virtual GLS_EXPORT ~glsDisplayFrame();
209 
210  /** Removes (hides) the spash screen */
211  virtual GLS_EXPORT void RemoveSplash();
212 
213  /** Creates the spash screen */
214  virtual GLS_EXPORT void CreateSplash();
215 
216  /** Creates this display frame. Called after the constructor so that things that need to
217  * access the OpenGL context can safely do so */
218  virtual GLS_EXPORT void Create( void );
219 
220  /** Sets up the default Orthographic projection (which supports things like pan and zoom) */
221  virtual GLS_EXPORT void SetProjection( void );
222 
223  /** Redraw the window at the Hz rate set for the DisplayFrame, or at least
224  * try to. We might be slower if the hardware can't keep up.
225  */
226  virtual GLS_EXPORT bool FrameAnimate( void );
227 
228  /** Redraw the window now.
229  * This actually calls the OpenGL Drawing routines.
230  */
231  virtual GLS_EXPORT void Redraw( void );
232 
233  /** Set a flag that UpdateAnimate can test to see if the window needs redrawing.
234  */
235  virtual GLS_EXPORT void SetRedraw( void );
236 
237  /** Only draw on events or if SetRedraw has been called.
238  * If this is called in a main loop, updates can occur very frequently if SetRedraw is
239  * continuously being called.
240  */
241  virtual GLS_EXPORT bool UpdateAnimate( void );
242 
243  /** Set the dimensions for the display frame window
244  * \param X New X coordinate of window
245  * \param Y New Y coordinate of window
246  * \param W New width of window
247  * \param H New height of window
248  */
249  virtual GLS_EXPORT void SetWindowDimensions( int X, int Y, int W, int H );
250 
251  /** Get the dimensions for the display frame window
252  * \param X Gets X coordinate of window
253  * \param Y Gets Y coordinate of window
254  * \param W Gets width of window
255  * \param H Gets height of window
256  */
257  virtual GLS_EXPORT void GetWindowDimensions( int& X, int& Y, int& W, int& H );
258 
259  /** Sets the post draw callback to the function pointer passed in */
260  virtual GLS_EXPORT void PostDrawCallback( GlsDrawCallback cb );
261 
262  /** Sets the pre draw callback to the function pointer passed in */
263  virtual GLS_EXPORT void PreDrawCallback( GlsDrawCallback cb );
264 
265  /** Sets the mode flags for the window
266  * \param flags The mode flags
267  */
268  virtual GLS_EXPORT void WindowFlags( unsigned long flags );
269 
270  /** Pans the display horizontally
271  * \param offset The new X position at the center of the window
272  */
273  virtual GLS_EXPORT void WidthOffset( float offset );
274 
275  /** Gets the horizontal position of the display at the center of the window
276  * \return The X position at the center of the window
277  */
278  virtual GLS_EXPORT float WidthOffset( void );
279 
280  /** Pans the display vertically
281  * \param offset The new Y position of the center of the window
282  */
283  virtual GLS_EXPORT void HeightOffset( float offset );
284 
285  /** Gets the vertical position of the display at the center of the window
286  * \return The Y position at the center of the window
287  */
288  virtual GLS_EXPORT float HeightOffset( void );
289 
290  /** Called after calling handle.
291  * \param handled True when the event has already been handled
292  * \param ev the pointer to the the event
293  * \return True If PostHandle has handled the event.
294  * Checks for statistics toggle [s] key, and [ESC] key press.
295  * The user can override this to turn off these behaviors.
296  */
297  virtual GLS_EXPORT bool PostHandle( bool handled, DisplayEvent* ev );
298 
299  /** Causes the window to center the view on the specified logical coordinate.
300  * It takes into account the possible rotation of the top group.
301  * \param lx Logical X Coordinate
302  * \param ly Logical Y Coordinate
303  */
304  virtual GLS_EXPORT void CenterOnLogical( float lx, float ly );
305 
306  /** Sets the Depth Factor for the window
307  * \param factor The depth factor. Used for autocalculating clipping planes */
308  virtual GLS_EXPORT void DepthFactor( float factor );
309 
310  /** Gets the Depth Factor for the window
311  * \return The current depth factor
312  */
313  virtual GLS_EXPORT float DepthFactor();
314 
315  /** Sets the FOV (Field of View) for the window. If fov is set to 0.0, a reasonable FOV
316  * will be calculated based on width and height.
317  * \param fov New field of view in degrees
318  */
319  virtual GLS_EXPORT void FOV( double fov );
320 
321  /** Gets the FOV (Field of View) for the window.
322  * \return The current field of view in degrees
323  */
324  virtual GLS_EXPORT double FOV();
325 
326  /** Sets the current view mode for the window
327  * \param view The new view mode for the window.
328  * Acceptable view types are:
329  * [VIEW_EYEPOINT - The application will be viewed through an eyepoint]
330  * [VIEW_XY - The application will be viewed through a 2D orthographic view of the XY plane]
331  * [VIEW_PERSPECTIVE - The application will be viewed through a perspective projection]
332  */
333  virtual GLS_EXPORT void CurrentView( const int view ) { _current_view = view; }
334 
335  /** Gets the current view mode for the window.
336  * \return The current viewmode for the window (VIEW_EYEPOINT, VIEW_XY, VIEW_PERSPECTIVE)
337  */
338  virtual GLS_EXPORT int CurrentView( void ) const { return _current_view; }
339 
340  /** \return Whether or not the 'S' key is enabled for controlling statistics
341  */
342  virtual GLS_EXPORT bool SKeyTogglesStatistics();
343 
344  /** Enable/disable s key for toggling statistics
345  * \param flag Whether or not S key will toggle statistics
346  */
347  virtual GLS_EXPORT void SKeyTogglesStatistics( bool flag );
348 
349  /** \return Whether or not the ESC key exits application
350  */
351  virtual GLS_EXPORT bool EscKeyExits();
352 
353  /** Enable/disable ESC key for exiting application
354  * \param flag Whether or not ESC key exits application
355  */
356  virtual GLS_EXPORT void EscKeyExits( bool flag );
357 };
358 
359 } // namespace disti
360 
361 #endif
362 #endif
virtual void Create(void)
virtual void CurrentView(const int view)
Definition: gls_display_frame.h:333
virtual void CreateSplash()
bool _sKeyTogglesStatistics
Definition: gls_display_frame.h:189
bool _redraw
Definition: gls_display_frame.h:167
EventCompressor< DisplayFrame > eventCompressor
Definition: gls_display_frame.h:199
Definition: gls_display_frame.h:98
Timer frameTimer
Definition: gls_display_frame.h:165
OpenGLWindow(int x, int y, int w, int h, const char *l, glsDisplayFrame *frame_)
float _height_offset
Definition: gls_display_frame.h:170
virtual bool SKeyTogglesStatistics()
virtual float WidthOffset(void)
GlsDrawCallback _preDrawCallback
Definition: gls_display_frame.h:173
Definition: events.h:271
Definition: splash_display.h:79
Definition: display_frame.h:75
bool _autoCalcFarZ
Definition: gls_display_frame.h:187
virtual double FOV()
OpenGLWindow * theWindow
Definition: gls_display_frame.h:196
virtual void CenterOnLogical(float lx, float ly)
float _smoothedFrameDelay
Definition: gls_display_frame.h:166
float _depthFactor
Definition: gls_display_frame.h:182
virtual void Redraw(void)
void resize(int x, int y, int w, int h)
disti::eglDisplayFrame class. The class for creating standalone executables for EGL.
virtual void PreDrawCallback(GlsDrawCallback cb)
virtual float DepthFactor()
virtual bool EscKeyExits()
glsDisplayFrame(const char *name, int width, int height)
The disti::Timer class. An OS portable timing class.
virtual void SetProjection(void)
Definition: runtime_display_frame.h:52
virtual bool FrameAnimate(void)
A file for all GL Studio files to include.
void WindowToLogical(glsDisplayFrame *frame, float x, float y, float &lx, float &ly)
SplashDisplay * splashDisplay
Definition: gls_display_frame.h:176
virtual bool UpdateAnimate(void)
The standard Mouse and keyboard events and event structures.
Definition: timer.h:66
virtual float HeightOffset(void)
Definition: gls_display_frame.h:162
double _fov
Definition: gls_display_frame.h:183
virtual void RemoveSplash()
double _farZ
Definition: gls_display_frame.h:186
virtual int CurrentView(void) const
Definition: gls_display_frame.h:338
float _width_offset
Definition: gls_display_frame.h:169
int _current_view
Definition: gls_display_frame.h:178
virtual void GetWindowDimensions(int &X, int &Y, int &W, int &H)
Definition: events.h:110
virtual void WindowFlags(unsigned long flags)
bool _autoCalcNearZ
Definition: gls_display_frame.h:185
double _nearZ
Definition: gls_display_frame.h:184
Definition: vertex.h:83
virtual void SetWindowDimensions(int X, int Y, int W, int H)
GlsDrawCallback _postDrawCallback
Definition: gls_display_frame.h:174
void resizable(OpenGLWindow *win)
void GrabWindow(char *filename)
virtual void PostDrawCallback(GlsDrawCallback cb)
The disti::RuntimeDisplayFrame class, parent class of all DisplayFrames used in runtime code...
virtual bool PostHandle(bool handled, DisplayEvent *ev)
Definition: bmpimage.h:46
Definition: events.h:218
virtual void SetRedraw(void)
bool _escKeyExits
Definition: gls_display_frame.h:190
The gls_gl.