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