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