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
14reproduced, in whole or part, in any form, or by any means of electronic,
15mechanical, or otherwise, without the written permission of DiSTI. Said
16permission may be derived through the purchase of applicable DiSTI product
17licenses which detail the distribution rights of this content and any
18Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37State 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# if defined( EMSCRIPTEN )
51# include "events.h"
52# include "gls_gl.h"
53# include "gls_include.h"
54# include "timer.h"
55# else
57namespace disti
58{
59/// Base class for all embedded (openGL ES) display frame classes.
61} // namespace disti
62# endif
63
64#else
65
66# include "gls_include.h"
67
68# ifdef WIN32
69# pragma warning( push )
70# pragma warning( disable : 4244 )
71# endif
72# include <FL/Fl.H>
73# include <FL/Fl_Box.H>
74# include <FL/Fl_Gl_Window.H>
75# include <FL/Fl_Window.H>
76# ifdef WIN32
77# pragma warning( pop )
78# endif
79
80# include "events.h"
82
83class Fl_Gl_Window;
84
85namespace disti
86{
87class SplashDisplay;
88class glsDisplayFrame;
89
90/** \class OpenGLWindow
91 * OpenGLWindow is a GL Studio specific implementation of the Fltk Fl_Gl_Window
92 */
93class OpenGLWindow : public Fl_Gl_Window
94{
95 glsDisplayFrame* frame; /**< The DisplayFrame associated with this window */
96 MouseEvent ev; /**< Last mouse event received */
97 KeyboardEvent kev; /**< Last keyboard event received */
98
99 /** Overload of FLTK draw routine */
100 GLS_EXPORT void draw();
101
102public:
103 /** Overload of FLTK make_current() method. Sets this window as the current OpenGL context */
104 GLS_EXPORT void make_current();
105
106 /** Overload of FLTK end() method. Used to signal FLTK to not make this the "current" window to add widgets to */
107 GLS_EXPORT void end();
108
109 /// Overload of FLTK resizable() method.
110 /// \param win The widget to be used as the resizable region.
111 GLS_EXPORT void resizable( OpenGLWindow* win );
112
113 /** Overload of FLTK resize() method. Resizes the window.
114 * \param x New x coordinate of window on screen
115 * \param y New y coordinate of window on screen
116 * \param w New width of window in pixels
117 * \param h New height of window in pixels
118 */
119 GLS_EXPORT void resize( int x, int y, int w, int h );
120
121 /** Overload of FLTK show() method. Sets the visible flag for this window, causing it to be shown the next time
122 * the FLTK event loop is checked.
123 */
124 GLS_EXPORT void show();
125
126 /// Overload of FLTK event handle routine. This is how mouse and keyboard events get passed in.
127 /// \return 0 if the event was not handled, otherwise non zero (usually 1).
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
154typedef void ( *GlsDrawCallback )( glsDisplayFrame* ); ///< Typedef for a function pointer used for pre/post draw callbacks.
155
156/** GL Studio standalone application class.
157 * Creates one window and draws all contents in it.
158 */
159class glsDisplayFrame : public RuntimeDisplayFrame
160{
161protected:
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
173public:
174 OpenGLWindow* theWindow; /**< The window associated with this DisplayFrame */
175
176 /** Used for event compression. Not for general use by users. */
177 EventCompressor<DisplayFrame> eventCompressor;
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();
197
198 /** Sets up the default Orthographic projection (which supports things like pan and zoom) */
199 virtual GLS_EXPORT void SetProjection();
200
201 /// \see RuntimeDisplayFrame
202 /// \note Overridden to return true if any window is open.
203 /// \return True if any window is open.
205
206 /** \see RuntimeDisplayFrame */
208
209 /** Redraw the window now.
210 * This actually calls the OpenGL Drawing routines.
211 */
212 virtual GLS_EXPORT void Redraw();
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 */
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 /// \param cb The new callback to use.
238 virtual GLS_EXPORT void PostDrawCallback( GlsDrawCallback cb );
239
240 /// Sets the pre draw callback to the function pointer passed in.
241 /// \param cb The new callback to use.
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
Definition: embedded_display_frame.h:61
void WindowFlags(int)
Unused in ES, remains for backward compatibility.
Definition: embedded_display_frame.h:64
virtual void SetProjection(GlsMatrixType &projMatrix, GlsMatrixType &model)
virtual void CreateSplash()
Definition: embedded_display_frame.h:110
virtual EventCompressor< DisplayFrame > * GetEventCompressor() override
Definition: embedded_display_frame.h:74
virtual void RemoveSplash()
Definition: embedded_display_frame.h:103
EventCompressor< DisplayFrame > eventCompressor
Definition: embedded_display_frame.h:98
virtual bool FrameAnimate()
disti::EmbeddedDisplayFrame class. The class for creating standalone executables for EGL.
The standard Mouse and keyboard events and event structures.
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:222
The gls_gl.
A file for all GL Studio files to include.
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:52
Definition: bmpimage.h:47
EmbeddedDisplayFrame glsDisplayFrame
Base class for all embedded (openGL ES) display frame classes.
Definition: gls_display_frame.h:60
DistiAttribDict::const_iterator end(const DistiAttribDict &dict)
Definition: disti_metadata.h:975
The disti::RuntimeDisplayFrame class, parent class of all DisplayFrames used in runtime code.
The disti::Timer class. An OS portable timing class.