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 
87 class Fl_Gl_Window;
88 
89 namespace disti
90 {
91 class SplashDisplay;
92 class glsDisplayFrame;
93 
94 /** \class OpenGLWindow
95  * OpenGLWindow is a GL Studio specific implementation of the Fltk Fl_Gl_Window
96  */
97 class OpenGLWindow : public Fl_Gl_Window
98 {
99  glsDisplayFrame* frame; /**< The DisplayFrame associated with this window */
100  MouseEvent ev; /**< Last mouse event received */
101  KeyboardEvent kev; /**< Last keyboard event received */
102 
103  /** Overload of FLTK draw routine */
104  GLS_EXPORT void draw();
105 
106 public:
107  /** Overload of FLTK make_current() method. Sets this window as the current OpenGL context */
108  GLS_EXPORT void make_current();
109 
110  /** Overload of FLTK end() method. Used to signal FLTK to not make this the "current" window to add widgets to */
111  GLS_EXPORT void end();
112 
113  /** Overload of FLTK resizable() method. */
114  GLS_EXPORT void resizable( OpenGLWindow* win );
115 
116  /** Overload of FLTK resize() method. Resizes the window.
117  * \param x New x coordinate of window on screen
118  * \param y New y coordinate of window on screen
119  * \param w New width of window in pixels
120  * \param h New height of window in pixels
121  */
122  GLS_EXPORT void resize( int x, int y, int w, int h );
123 
124  /** Overload of FLTK show() method. Sets the visible flag for this window, causing it to be shown the next time
125  * the FLTK event loop is checked.
126  */
127  GLS_EXPORT void show();
128 
129  /** Overload of FLTK event handle routine. This is how mouse and keyboard events get passed in */
130  GLS_EXPORT int handle( int );
131 
132  /** Constructor for window
133  * \param x Initial x loc of window
134  * \param y Initial y loc of window
135  * \param w Initial width of window
136  * \param h Initial height of window
137  * \param l Window title
138  * \param frame_ Display to associate with window */
139  GLS_EXPORT OpenGLWindow( int x, int y, int w, int h, const char* l, glsDisplayFrame* frame_ );
140 
141  /** Grabs the window contents and saves them to an uncompressed 24 bit BMP file
142  * \param filename Name of the file to write a BMP to
143  */
144  GLS_EXPORT void GrabWindow( char* filename );
145 
146  /** Converts mouse window coordinates to logical simulation coordinates.
147  * \param frame DisplayFrame to convert for
148  * \param x Mouse Device coordinate
149  * \param y Mouse Device coordinate
150  * \param lx Filled in with logical X coordinate
151  * \param ly Filled in with logical Y coordinate
152  */
153  GLS_EXPORT void WindowToLogical( glsDisplayFrame* frame, float x, float y, float& lx, float& ly );
154 };
155 
156 typedef void ( *GlsDrawCallback )( glsDisplayFrame* );
157 
158 /** GL Studio standalone application class.
159  * Creates one window and draws all contents in it.
160  */
162 {
163 protected:
164  GlsDrawCallback _preDrawCallback; /**< A function pointer that will be called prior to the Draw method being called */
165  GlsDrawCallback _postDrawCallback; /**< A function pointer that will be called after the Draw method is called */
166 
167  SplashDisplay* splashDisplay; /**< The Spash screen image */
168 
169  bool _sKeyTogglesStatistics; /**< When true, the [s] key toggles statistics */
170  bool _escKeyExits; /**< When true, the [Esc] key exits the application */
171 
172  /* \see DisplayFrame */
173  virtual GLS_EXPORT EventCompressor<DisplayFrame>* GetEventCompressor() { return &eventCompressor; }
174 
175 public:
176  OpenGLWindow* theWindow; /**< The window associated with this DisplayFrame */
177 
178  /** Used for event compression. Not for general use by users. */
180 
181  /** Creates this glsDisplayFrame
182  * \param name Window Title
183  * \param width Width of Dsplay Frame in pixels
184  * \param height Width of Dsplay Frame in pixels
185  */
186  GLS_EXPORT glsDisplayFrame( const char* name, int width, int height );
187 
188  virtual GLS_EXPORT ~glsDisplayFrame();
189 
190  /** Removes (hides) the spash screen */
191  virtual GLS_EXPORT void RemoveSplash();
192 
193  /** Creates the spash screen */
194  virtual GLS_EXPORT void CreateSplash();
195 
196  /** Creates this display frame. Called after the constructor so that things that need to
197  * access the OpenGL context can safely do so */
198  virtual GLS_EXPORT void Create( void );
199 
200  /** Sets up the default Orthographic projection (which supports things like pan and zoom) */
201  virtual GLS_EXPORT void SetProjection( void );
202 
203  /** \see RuntimeDisplayFrame
204  * Overridden to return true if any window is open.
205  */
206  GLS_EXPORT bool FrameAnimate() DISTI_METHOD_OVERRIDE;
207 
208  /** \see RuntimeDisplayFrame */
209  GLS_EXPORT void Paint( void ) DISTI_METHOD_OVERRIDE;
210 
211  /** Redraw the window now.
212  * This actually calls the OpenGL Drawing routines.
213  */
214  virtual GLS_EXPORT void Redraw( void );
215 
216  /** \see DisplayFrame. On Desktop, this also triggers the frame to redraw. This function is deprecated and should not be called by user code. Call Invalidate() from the GlsPainterInterface
217  * to signal that the frame needs to be redrawn (if using conditional animation), and call Paint() to trigger the displayframe to redraw.
218  * \deprecated
219  */
220  GLS_EXPORT void SetRedraw( void ) DISTI_METHOD_OVERRIDE;
221 
222  /** Set the dimensions for the display frame window
223  * \param X New X coordinate of window
224  * \param Y New Y coordinate of window
225  * \param W New width of window
226  * \param H New height of window
227  */
228  virtual GLS_EXPORT void SetWindowDimensions( int X, int Y, int W, int H );
229 
230  /** Get the dimensions for the display frame window
231  * \param X Gets X coordinate of window
232  * \param Y Gets Y coordinate of window
233  * \param W Gets width of window
234  * \param H Gets height of window
235  */
236  virtual GLS_EXPORT void GetWindowDimensions( int& X, int& Y, int& W, int& H );
237 
238  /** Sets the post draw callback to the function pointer passed in */
239  virtual GLS_EXPORT void PostDrawCallback( GlsDrawCallback cb );
240 
241  /** Sets the pre draw callback to the function pointer passed in */
242  virtual GLS_EXPORT void PreDrawCallback( GlsDrawCallback cb );
243 
244  /** Sets the mode flags for the window
245  * \param flags The mode flags
246  */
247  virtual GLS_EXPORT void WindowFlags( unsigned long flags );
248 
249  /** Called after calling handle.
250  * \param handled True when the event has already been handled
251  * \param ev the pointer to the the event
252  * \return True If PostHandle has handled the event.
253  * Checks for statistics toggle [s] key, and [ESC] key press.
254  * The user can override this to turn off these behaviors.
255  */
256  virtual GLS_EXPORT bool PostHandle( bool handled, DisplayEvent* ev );
257 
258  /** Causes the window to center the view on the specified logical coordinate.
259  * It takes into account the possible rotation of the top group.
260  * \param lx Logical X Coordinate
261  * \param ly Logical Y Coordinate
262  */
263  virtual GLS_EXPORT void CenterOnLogical( float lx, float ly );
264 
265  /** \return Whether or not the 'S' key is enabled for controlling statistics
266  */
267  virtual GLS_EXPORT bool SKeyTogglesStatistics();
268 
269  /** Enable/disable s key for toggling statistics
270  * \param flag Whether or not S key will toggle statistics
271  */
272  virtual GLS_EXPORT void SKeyTogglesStatistics( bool flag );
273 
274  /** \return Whether or not the ESC key exits application
275  */
276  virtual GLS_EXPORT bool EscKeyExits();
277 
278  /** Enable/disable ESC key for exiting application
279  * \param flag Whether or not ESC key exits application
280  */
281  virtual GLS_EXPORT void EscKeyExits( bool flag );
282 };
283 
284 } // namespace disti
285 
286 #endif
287 #endif
virtual void Create(void)
virtual void CreateSplash()
bool _sKeyTogglesStatistics
Definition: gls_display_frame.h:169
EventCompressor< DisplayFrame > eventCompressor
Definition: gls_display_frame.h:179
Definition: gls_display_frame.h:97
OpenGLWindow(int x, int y, int w, int h, const char *l, glsDisplayFrame *frame_)
virtual bool SKeyTogglesStatistics()
GlsDrawCallback _preDrawCallback
Definition: gls_display_frame.h:164
Definition: events.h:272
Definition: splash_display.h:79
Definition: display_frame.h:77
OpenGLWindow * theWindow
Definition: gls_display_frame.h:176
virtual void CenterOnLogical(float lx, float ly)
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 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:53
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:167
The standard Mouse and keyboard events and event structures.
Definition: gls_display_frame.h:161
virtual void RemoveSplash()
virtual void GetWindowDimensions(int &X, int &Y, int &W, int &H)
Definition: events.h:111
virtual void WindowFlags(unsigned long flags)
virtual void SetWindowDimensions(int X, int Y, int W, int H)
GlsDrawCallback _postDrawCallback
Definition: gls_display_frame.h:165
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
bool _escKeyExits
Definition: gls_display_frame.h:170
The gls_gl.