GL Studio 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) 2015 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 "gls_include.h"
57 #include "timer.h"
58 #include "events.h"
59 #include "gls_gl.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_Window.H>
78 #include <FL/Fl_Gl_Window.H>
79 #include <FL/Fl_Box.H>
80 #ifdef WIN32
81 #pragma warning(pop)
82 #endif
83 
84 #include "timer.h"
85 #include "runtime_display_frame.h"
86 #include "events.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 
109  /** Overload of FLTK make_current() method. Sets this window as the current OpenGL context */
110  GLS_EXPORT void make_current();
111 
112  /** Overload of FLTK end() method. Used to signal FLTK to not make this the "current" window to add widgets to */
113  GLS_EXPORT void end();
114 
115  /** Overload of FLTK resizable() method. */
116  GLS_EXPORT void resizable(OpenGLWindow* win);
117 
118  /** Overload of FLTK resize() method. Resizes the window.
119  * \param x New x coordinate of window on screen
120  * \param y New y coordinate of window on screen
121  * \param w New width of window in pixels
122  * \param h New height of window in pixels
123  */
124  GLS_EXPORT void resize(int x, int y, int w, int h);
125 
126  /** Overload of FLTK show() method. Sets the visible flag for this window, causing it to be shown the next time
127  * the FLTK event loop is checked.
128  */
129  GLS_EXPORT void show();
130 
131  /** Overload of FLTK event handle routine. This is how mouse and keyboard events get passed in */
132  GLS_EXPORT int handle(int);
133 
134  /** Constructor for window
135  * \param x Initial x loc of window
136  * \param y Initial y loc of window
137  * \param w Initial width of window
138  * \param h Initial height of window
139  * \param l Window title
140  * \param frame_ Display to associate with window */
141  GLS_EXPORT OpenGLWindow(int x,int y,int w,int h,const char *l,glsDisplayFrame *frame_);
142 
143  /** Grabs the window contents and saves them to an uncompressed 24 bit BMP file
144  * \param filename Name of the file to write a BMP to
145  */
146  GLS_EXPORT void GrabWindow(char *filename);
147 
148  /** Converts mouse window coordinates to logical simulation coordinates.
149  * \param frame DisplayFrame to convert for
150  * \param x Mouse Device coordinate
151  * \param y Mouse Device coordinate
152  * \param lx Filled in with logical X coordinate
153  * \param ly Filled in with logical Y coordinate
154  */
155  GLS_EXPORT void WindowToLogical(glsDisplayFrame *frame, float x, float y, float &lx, float &ly);
156 };
157 
158 typedef void (*GlsDrawCallback)(glsDisplayFrame *);
159 
160 /** GL Studio standalone application class.
161  * Creates one window and draws all contents in it.
162  */
164 {
165 protected:
166  Timer frameTimer; /**< Timer used for scheduling */
167  float _smoothedFrameDelay; /**< Frame interval, smoothed based on actual draw performance */
168  bool _redraw; /**< Flag indicating if the window should be redrawn */
169 
170  float _width_offset; /**< Current "width" offset of window. Used for panning of display horizontally in ortho mode. */
171  float _height_offset; /**< Current "height" offset of window. Used for panning of display vertically in ortho mode. */
172  Vector _viewOffset;
173 
174  GlsDrawCallback _preDrawCallback; /**< A function pointer that will be called prior to the Draw method being called */
175  GlsDrawCallback _postDrawCallback; /**< A function pointer that will be called after the Draw method is called */
176 
177  SplashDisplay *splashDisplay; /**< The Spash screen image */
178 
179  int _current_view; /**< Current view of the canvas (e.g., ortho, perspective, eyepoint) */
180 
181  /** For better control over clipping and field of view, use a GlsEyePoint, but some limited functionality is available here */
182 
183  float _depthFactor; /**< Used for auto calculations */
184  double _fov; /**< Field Of View. If 0.0 (the default), fov will be auto calculated. */
185  double _nearZ; /**< Near clipping plane. Only meaningful if _autoCalcNearZ is false */
186  bool _autoCalcNearZ; /**< When true a _nearZ is automatically calculated. */
187  double _farZ; /**< Far clipping plane. Only meaningfull if _autoCalcVarZ is false */
188  bool _autoCalcFarZ; /**< When true a _farZ is automatically calculated. */
189 
190  bool _sKeyTogglesStatistics; /**< When true, the [s] key toggles statistics */
191  bool _escKeyExits; /**< When true, the [Esc] key exits the application */
192 
193  /* \see DisplayFrame */
194  virtual GLS_EXPORT EventCompressor<DisplayFrame>* GetEventCompressor() { return &eventCompressor; }
195 
196 public:
197  OpenGLWindow *theWindow; /**< The window associated with this DisplayFrame */
198 
199  /** Used for event compression. Not for general use by users. */
201 
202  /** Creates this glsDisplayFrame
203  * \param name Window Title
204  * \param width Width of Dsplay Frame in pixels
205  * \param height Width of Dsplay Frame in pixels
206  */
207  GLS_EXPORT glsDisplayFrame(const char *name,int width,int height);
208 
209  virtual GLS_EXPORT ~glsDisplayFrame();
210 
211  /** Removes (hides) the spash screen */
212  virtual GLS_EXPORT void RemoveSplash();
213 
214  /** Creates the spash screen */
215  virtual GLS_EXPORT void CreateSplash();
216 
217  /** Creates this display frame. Called after the constructor so that things that need to
218  * access the OpenGL context can safely do so */
219  virtual GLS_EXPORT void Create(void);
220 
221  /** Sets up the default Orthographic projection (which supports things like pan and zoom) */
222  virtual GLS_EXPORT void SetProjection(void);
223 
224  /** Redraw the window at the Hz rate set for the DisplayFrame, or at least
225  * try to. We might be slower if the hardware can't keep up.
226  */
227  virtual GLS_EXPORT bool FrameAnimate(void);
228 
229  /** Redraw the window now.
230  * This actually calls the OpenGL Drawing routines.
231  */
232  virtual GLS_EXPORT void Redraw(void);
233 
234  /** Set a flag that UpdateAnimate can test to see if the window needs redrawing.
235  */
236  virtual GLS_EXPORT void SetRedraw(void);
237 
238  /** Only draw on events or if SetRedraw has been called.
239  * If this is called in a main loop, updates can occur very frequently if SetRedraw is
240  * continuously being called.
241  */
242  virtual GLS_EXPORT bool UpdateAnimate(void);
243 
244  /** Set the dimensions for the display frame window
245  * \param X New X coordinate of window
246  * \param Y New Y coordinate of window
247  * \param W New width of window
248  * \param H New height of window
249  */
250  virtual GLS_EXPORT void SetWindowDimensions(int X, int Y, int W, int H);
251 
252  /** Get the dimensions for the display frame window
253  * \param X Gets X coordinate of window
254  * \param Y Gets Y coordinate of window
255  * \param W Gets width of window
256  * \param H Gets height of window
257  */
258  virtual GLS_EXPORT void GetWindowDimensions(int &X, int &Y, int &W, int &H);
259 
260  /** Sets the post draw callback to the function pointer passed in */
261  virtual GLS_EXPORT void PostDrawCallback(GlsDrawCallback cb);
262 
263  /** Sets the pre draw callback to the function pointer passed in */
264  virtual GLS_EXPORT void PreDrawCallback(GlsDrawCallback cb);
265 
266  /** Sets the mode flags for the window
267  * \param flags The mode flags
268  */
269  virtual GLS_EXPORT void WindowFlags(unsigned long flags);
270 
271  /** Pans the display horizontally
272  * \param offset The new X position at the center of the window
273  */
274  virtual GLS_EXPORT void WidthOffset(float offset);
275 
276  /** Gets the horizontal position of the display at the center of the window
277  * \return The X position at the center of the window
278  */
279  virtual GLS_EXPORT float WidthOffset(void);
280 
281  /** Pans the display vertically
282  * \param offset The new Y position of the center of the window
283  */
284  virtual GLS_EXPORT void HeightOffset(float offset);
285 
286  /** Gets the vertical position of the display at the center of the window
287  * \return The Y position at the center of the window
288  */
289  virtual GLS_EXPORT float HeightOffset(void);
290 
291  /** Called after calling handle.
292  * \param handled True when the event has already been handled
293  * \param ev the pointer to the the event
294  * \return True If PostHandle has handled the event.
295  * Checks for statistics toggle [s] key, and [ESC] key press.
296  * The user can override this to turn off these behaviors.
297  */
298  virtual GLS_EXPORT bool PostHandle(bool handled, DisplayEvent *ev);
299 
300  /** Causes the window to center the view on the specified logical coordinate.
301  * It takes into account the possible rotation of the top group.
302  * \param lx Logical X Coordinate
303  * \param ly Logical Y Coordinate
304  */
305  virtual GLS_EXPORT void CenterOnLogical(float lx, float ly);
306 
307  /** Sets the Depth Factor for the window
308  * \param factor The depth factor. Used for autocalculating clipping planes */
309  virtual GLS_EXPORT void DepthFactor(float factor);
310 
311  /** Gets the Depth Factor for the window
312  * \return The current depth factor
313  */
314  virtual GLS_EXPORT float DepthFactor();
315 
316  /** Sets the FOV (Field of View) for the window. If fov is set to 0.0, a reasonable FOV
317  * will be calculated based on width and height.
318  * \param fov New field of view in degrees
319  */
320  virtual GLS_EXPORT void FOV(double fov);
321 
322  /** Gets the FOV (Field of View) for the window.
323  * \return The current field of view in degrees
324  */
325  virtual GLS_EXPORT double FOV();
326 
327  /** Sets the current view mode for the window
328  * \param view The new view mode for the window.
329  * Acceptable view types are:
330  * [VIEW_EYEPOINT - The application will be viewed through an eyepoint]
331  * [VIEW_XY - The application will be viewed through a 2D orthographic view of the XY plane]
332  * [VIEW_PERSPECTIVE - The application will be viewed through a perspective projection]
333  */
334  virtual GLS_EXPORT void CurrentView(const int view) { _current_view = view; }
335 
336  /** Gets the current view mode for the window.
337  * \return The current viewmode for the window (VIEW_EYEPOINT, VIEW_XY, VIEW_PERSPECTIVE)
338  */
339  virtual GLS_EXPORT int CurrentView(void) const { return _current_view;}
340 
341  /** \return Whether or not the 'S' key is enabled for controlling statistics
342  */
343  virtual GLS_EXPORT bool SKeyTogglesStatistics();
344 
345  /** Enable/disable s key for toggling statistics
346  * \param flag Whether or not S key will toggle statistics
347  */
348  virtual GLS_EXPORT void SKeyTogglesStatistics(bool flag);
349 
350 
351  /** \return Whether or not the ESC key exits application
352  */
353  virtual GLS_EXPORT bool EscKeyExits();
354 
355  /** Enable/disable ESC key for exiting application
356  * \param flag Whether or not ESC key exits application
357  */
358  virtual GLS_EXPORT void EscKeyExits(bool flag);
359 };
360 
361 } // namespace disti
362 
363 #endif
364 #endif
virtual void Create(void)
virtual void CurrentView(const int view)
Definition: gls_display_frame.h:334
virtual void CreateSplash()
bool _sKeyTogglesStatistics
Definition: gls_display_frame.h:190
bool _redraw
Definition: gls_display_frame.h:168
EventCompressor< DisplayFrame > eventCompressor
Definition: gls_display_frame.h:200
Definition: gls_display_frame.h:98
Timer frameTimer
Definition: gls_display_frame.h:166
OpenGLWindow(int x, int y, int w, int h, const char *l, glsDisplayFrame *frame_)
float _height_offset
Definition: gls_display_frame.h:171
virtual bool SKeyTogglesStatistics()
virtual float WidthOffset(void)
GlsDrawCallback _preDrawCallback
Definition: gls_display_frame.h:174
Definition: events.h:272
Definition: splash_display.h:83
Definition: display_frame.h:75
bool _autoCalcFarZ
Definition: gls_display_frame.h:188
virtual double FOV()
OpenGLWindow * theWindow
Definition: gls_display_frame.h:197
virtual void CenterOnLogical(float lx, float ly)
float _smoothedFrameDelay
Definition: gls_display_frame.h:167
float _depthFactor
Definition: gls_display_frame.h:183
virtual void Redraw(void)
void resize(int x, int y, int w, int h)
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:177
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:163
double _fov
Definition: gls_display_frame.h:184
virtual void RemoveSplash()
double _farZ
Definition: gls_display_frame.h:187
virtual int CurrentView(void) const
Definition: gls_display_frame.h:339
float _width_offset
Definition: gls_display_frame.h:170
int _current_view
Definition: gls_display_frame.h:179
virtual void GetWindowDimensions(int &X, int &Y, int &W, int &H)
Definition: events.h:111
virtual void WindowFlags(unsigned long flags)
bool _autoCalcNearZ
Definition: gls_display_frame.h:186
double _nearZ
Definition: gls_display_frame.h:185
Definition: vertex.h:84
virtual void SetWindowDimensions(int X, int Y, int W, int H)
GlsDrawCallback _postDrawCallback
Definition: gls_display_frame.h:175
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:219
virtual void SetRedraw(void)
bool _escKeyExits
Definition: gls_display_frame.h:191
The gls_gl.