GL Studio C++ Runtime API
display_frame.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::DisplayFrame class.
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 _DISPLAY_FRAME_H
41 #define _DISPLAY_FRAME_H
42 
43 #include "display.h"
44 #include "gls_include.h"
45 #include "image.h"
46 #include "texture_palette.h"
47 #include "util.h"
48 #include "vertex.h"
49 #include <string.h>
50 #ifndef GLS_EDITOR_CODE
51 # include "message.h"
52 #endif
53 
54 #include "disti_metadata.h"
55 #include "dynamic_array.h"
56 #include "input_handler.h"
57 #include "material.h"
58 #include "scoped_ptr.h"
59 #include "sound.h"
60 
61 struct DragObjectMap;
62 
63 namespace disti
64 {
65 static const int MAX_PLAYABLE = 20; /**< Max. Number of sound files that can be played */
66 
67 const char META_COMPONENT_HEADER_FILE_NAME[] = "ComponentHeaderFile";
68 
69 typedef DynamicArray<Material, false> DynamicMaterialArray; /**< Typedef for dynamic array of materials */
70 
71 class Group;
72 class ComponentLightMgr;
73 
74 template<class>
76 
77 /** The base class for associating a display device with an object list.
78  *
79  * DisplayFrame contains all of the display objects, texture, and fonts for
80  * an application.
81  *
82  */
83 class DisplayFrame : virtual public AttributeChangedNotifier
84 {
85 private:
86  DistiAttribDict* _frameAttribDict; /**< Stores all of the attributes specific to the DisplayFrame */
87  ScopedPtr<InputHandler> _inputHandler;
88 
89 protected:
90  bool _cullingEnabled; /**< True if culling is enabled for this DisplayFrame */
91  int _width; /**< The width of the window for this display frame */
92  int _height; /**< The height of the window for this display frame */
93  float _lastPickedDepth; /**< Keeps previous picks depth for use when no pick is performed (dragging) */
94  DynamicMaterialArray _materialPalette; /**< A Dynamic array for keeping the materials for this frame */
95  ComponentLightMgr* _lightMgr; /**< The _lightMgr is used to setup lighting for the DisplayFrame */
96  GLbitfield _clearBitfield; /**< The OpenGL bitfield to use when clearing. /see glClear */
97 
98  std::string _componentHeaderFileName; /**< backing store for META_COMPONENT_HEADER_FILE_NAME attribute */
99 
100  DragObjectMap* _dragObjectMap;
101  unsigned int _currentCursor; /**< the current cursor being processed */
102  bool _multitouchEnabled; /**< whether or not multitouch is enabled */
103  unsigned int _cursorsDown; /**< The number of cursors (touches) that are currently down */
104 
105  /** Changes the current cursor to the specified cursor id. Needed by multitouch, so that DragObject and FocusObject will return
106  * the correct objects for the current cursor.
107  * \param cursor_id the cursor id
108  */
109  virtual GLS_EXPORT void CurrentCursor( unsigned int cursor_id );
110 
111  /** Cleanup unused entries from the drag map */
112  void CleanupDragMap();
113 
114  /** Get the drag object that corresponds to the curosr
115  * \param cursorID the cursor
116  * \return the drag object or null if none exists
117  */
118  DisplayObject* GetDragObjectForCursor( unsigned int cursorID );
119 
120  /** Find a non-null drag object from the _dragObjectMap if on exists
121  * \return a drag object, or null if there aren't any in the map
122  */
124 
125  /* Get the event compressor for this display frame, if it exists
126  * \return the event compressor
127  */
128  virtual GLS_EXPORT EventCompressor<DisplayFrame>* GetEventCompressor() { return NULL; };
129 
130  /** \return The current scale for the display frame
131  */
132  virtual GLS_EXPORT float Scale( void ) { return 1.0f; }
133 
134 public:
135  TexturePalette* texturePalette; /**< An array of textures allocated for display on objects */
136  SoundSystem* _sound_player; /**< Sound file player for this DisplayFrame */
137  Group* objects; /**< The object hierarchy for this display frame */
138 
139  /** Creates a new display frame
140  * \param width The width of this display frame in pixels
141  * \param height The height of this display frame in pixels
142  * \param allocateObjects
143  */
144  GLS_EXPORT DisplayFrame( int width, int height, bool allocateObjects = true );
145 
146  virtual GLS_EXPORT ~DisplayFrame( void );
147 
148  /** Sets the OpenGL clear bitmask that will be used when the window is cleared
149  * \param bitField The OpenGL bitfield to use when clearing. /see glClear
150  */
151  inline void ClearBitfield( GLbitfield bitField ) { _clearBitfield = bitField; }
152 
153  /** Gets the OpenGL clear bitmask that will be used when the window is cleared
154  * \return The OpenGL bitfield to use when clearing. /see glClear
155  */
156  inline GLbitfield ClearBitfield() { return _clearBitfield; }
157 
158  /** Sets the current "Drag" object for the current cursor
159  * \param obj The new DragObject
160  */
161  virtual GLS_EXPORT void DragObject( DisplayObject* obj );
162 
163  /** Gets the current "Drag" object for the current cursor
164  * \return The current DragObject
165  */
166  virtual GLS_EXPORT DisplayObject* DragObject( void );
167 
168  /** Clears the drag objects for all cursors.*/
169  virtual GLS_EXPORT void ClearDrag();
170 
171  /** Sets the current focus object for the current cursor.*/
172  virtual GLS_EXPORT void FocusObject( DisplayObject* obj );
173 
174  /** Gets the current "Focus" object for the current cursor
175  * \return The current FocusObject
176  */
177  virtual GLS_EXPORT DisplayObject* FocusObject( void );
178 
179  /** Clears the focus objects for all cursors.*/
180  virtual GLS_EXPORT void ClearFocus();
181 
182  /** Enables/Disables multitouch on the display frame. Multitouch is enabled by default. This function has no effect on platforms that
183  * do not support multitouch */
184  virtual GLS_EXPORT void MultitouchEnabled( bool enabled );
185 
186  /** Gets whether or not multitouch is enabled on the display frame. */
187  virtual GLS_EXPORT bool MultitouchEnabled( void );
188 
189  /** Get the input handler */
190  virtual GLS_EXPORT InputHandler* GetInputHandler();
191 
192  /** Handles a display event. Picks an object and also tracks focus.
193  */
194  virtual GLS_EXPORT DisplayObject* HandleDisplayEvent( DisplayEvent* ev );
195 
196  /** Write the resources (attributes) of the objects in this display frame to the specified file
197  * \param filename Name of the file to write to
198  * \param filter A filter to specify which attributes to write
199  */
200  virtual GLS_EXPORT void WriteResources( const char* filename, GlsResourceFilter* filter = NULL );
201 
202  /** Read the resources (attributes) of the objects in this display frame from the specified file
203  * \param filename Name of the file to read from
204  */
205  virtual GLS_EXPORT void ReadResources( const char* filename );
206 
207  /** Gets a reference to the specified attribute for reading and writing.
208  * This reference can be streamed into and out of variables.
209  * This can access different levels of objects.
210  * For example:
211  * The DisplayFrame:
212  * Resource("ComponentHeaderFile") >> someStdString;
213  * An object in the DisplayFrame:
214  * Resource("SomeObject.Visible") << someBool;
215  * An object in a Component in this DisplayFrame:
216  * Resource("SomeComponentObject.SomeObject.Visible") >> someBool;
217  */
218  virtual GLS_EXPORT DistiAttributeBase& Resource( const char* name );
219 
220  /** Get the resources for this display frame and all it's children acording to the filter
221  * \param outstr The stream to write to
222  * \param filter The filter to control what gets written.
223  */
224  virtual GLS_EXPORT void GetResources( std::ostream& outstr, GlsResourceFilter* filter = NULL );
225 
226  /** Parse a stream of resource value pairs.
227  * \param instr Stream containing the resource data
228  */
229  virtual GLS_EXPORT void SetResources( std::istream& instr );
230 
231  /** Sets a DisplayFrame resource value.
232  * \param resourceName Name of the resource to set.
233  * \param resourceVal Value of the resource to set
234  */
235  inline void SetResource( const std::string& resourceName, const std::string& resourceVal )
236  {
237  SetResource_CRTClean( resourceName.c_str(), resourceVal.c_str() );
238  }
239  inline void SetResource( const char* resourceName, const char* resourceVal )
240  {
241  SetResource_CRTClean( resourceName, resourceVal );
242  }
243 
244  /** Gets a DisplayFrame resource value.
245  * \param resourceName Name of the resource to set
246  */
247  inline std::string GetResource( const std::string& resourceName )
248  {
249  char* value = GetResource_CRTClean( resourceName.c_str() );
250  std::string stringVal = value;
251  GetResourceFree_CRTClean( value );
252  return stringVal;
253  }
254  inline std::string GetResource( const char* resourceName )
255  {
256  char* value = GetResource_CRTClean( resourceName );
257  std::string stringVal = value;
258  GetResourceFree_CRTClean( value );
259  return stringVal;
260  }
261 
262  /** CRT Insensitive version of GetResource()
263  * Version with streams can not be called from differently compiled code.
264  * \param name name of resource
265  * \return The requested value allocated as a char array.
266  * The user MUST call GetResourceFree() when finished using returned value.
267  */
268  virtual GLS_EXPORT char* GetResource_CRTClean( const char* name );
269 
270  /** Frees the memory allocated by a previous GetResource_CRTClean call
271  * \param memoryToFree Pointer to memory allocated by GetResource_CRTClean
272  */
273  virtual GLS_EXPORT void GetResourceFree_CRTClean( char* memoryToFree );
274 
275  /** CRT Insensitive version of GetResources()
276  * \param filter The filter to control what gets written
277  * \return A null terminated char* containing the requested resources
278  * The user MUST call GetResourcesFree() on the returned value.
279  */
280  virtual GLS_EXPORT char* GetResources_CRTClean( GlsResourceFilter* filter );
281 
282  /** Frees the memory allocated by a previous GetResources_CRTClean call
283  * \param memoryToFree Pointer to memory allocated by GetResource_CRTClean
284  */
285  virtual GLS_EXPORT void GetResourcesFree_CRTClean( char* memoryToFree );
286 
287  /** CRT Insensitive version of SetResource()
288  * Version with streams can not be called from differently compiled code.
289  * \param name name of resource
290  * \param value new value for resource
291  */
292  virtual GLS_EXPORT void SetResource_CRTClean( const char* name, const char* value );
293 
294  /** CRT Insensitive version of SetResources()
295  * Parse a buffer of resource value pairs.
296  * \param buf String containing resource data
297  */
298  virtual GLS_EXPORT void SetResources_CRTClean( const char* buf );
299 
300  /** Implements AttributeChangedNotifier::NotifyAttributeChanged.
301  * Notify the class that the attribute has changed. Observers of the attribute will have their callbacks called
302  * \param name the name of the attribute
303  */
304  virtual GLS_EXPORT void NotifyAttributeChanged( const AttributeName& name ) DISTI_METHOD_OVERRIDE;
305 
306 #ifndef GLES
307  /** Get the details of the Cpp Interface
308  * The actual interface is exposed in compiled code.
309  * \param addToThisList A list to add to and then return. Creates a new one if NULL.
310  * \return A templated list.
311  * The caller must call the corresponding free method to
312  * safely free the memory.
313  */
314  virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL );
315 
316  /** Frees the memory allocated by a previous GetCppInterfaceDescription call
317  * \param array Pointer to memory allocated by GetCppInterfaceDescription
318  */
319  virtual GLS_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array );
320 #endif
321 
322  /** Sets the texture palette size for this display frame
323  * \param cnt The number of entries to have in the display frame
324  */
325  GLS_EXPORT void SetTexturePaletteSize( int cnt );
326 
327  /** Draw the objects contained in this display frame */
328  GLS_EXPORT void Draw( void );
329 
330  /* Adds the specified object into this display frame
331  * \param A pointer to the object to add
332  * \param Whether or not the object parent should be set to this group
333  * \param Whether or not to recalculate the bounding box
334  * \param Where to insert it (defaults to -1 which means at the end of the list)
335  */
336  GLS_EXPORT void InsertObject( DisplayObject* obj, bool reparent = true, bool recalculateBoundingbox = true, int loc = -1 );
337 
338  /** Inserts a display object into this display frame at the specified
339  * index in the object list.
340  * \param obj The object to insert
341  * \param loc Where to insert the object
342  */
343  GLS_EXPORT void InsertObject( DisplayObject* obj, int loc );
344 
345  /** Inserts a display object into this display frame at the end
346  * of the object list.
347  * \param obj The object to insert
348  */
349  GLS_EXPORT void PushObject( DisplayObject* obj );
350 
351  /** Gets the width in pixels of this display frame
352  * \return The width in pixels of this display frame
353  */
354  GLS_EXPORT int Width( void );
355 
356  /** Gets the height in pixels of this display frame
357  * \return The height in pixels of this display frame
358  */
359  GLS_EXPORT int Height( void );
360 
361  /** Sets the width in pixels of this display frame
362  * \param w The new width in pixels of this display frame
363  */
364  GLS_EXPORT void SetWidth( int w );
365 
366  /** Sets the height in pixels of this display frame
367  * \param h The new height in pixels of this display frame
368  */
369  GLS_EXPORT void SetHeight( int h );
370 
371  /** Does nothing here in the base class. Allows other display
372  * frames to add functionality
373  */
374  virtual GLS_EXPORT void SetRedraw( void );
375 
376  /** Gets the whether or not culling is enabled for this display frame
377  * \return whether or not culling is enabled for this display frame
378  */
379  GLS_EXPORT bool CullingEnabled( void );
380 
381  /** Sets the whether or not culling is enabled for this display frame
382  * \param enabled whether or not culling is enabled for this display frame
383  */
384  GLS_EXPORT void CullingEnabled( const bool enabled );
385 
386  /** Sets up the OpenGL Pipeline to the state expected by GL Studio drawing.
387  * resetTemplate is used to not reset certain catagories. For example, it may
388  * be desirable for a GL Studio object to receive lighting from it's VegaPrime scene.
389  * \param saveVal Whether or not to save values. If true, this will call
390  * glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS) and glPushAttrib(GL_ALL_ATTRIB_BITS). You should call
391  * RestoreOpenGLState() after drawing to pop the attributes.
392  */
393  static GLS_EXPORT void SetOpenGLDefaultState( bool saveVal );
394 
395  /** Call this after calling SetOpenGLDefaultState with saveVal == true.
396  * DO NOT call this after calling SetOpenGLDefaultState with saveVal == false
397  * because this will pop the attribute stack.
398  */
399  static GLS_EXPORT void RestoreOpenGLState( void );
400 
401  /** \return A reference to the Attribute dictionary for this display frame */
402  inline DistiAttribDict& FrameAttribDict( void ) { return *_frameAttribDict; }
403 
404  /** \return A const reference to the Attribute dictionary for this display frame */
405  inline const DistiAttribDict& FrameAttribDict( void ) const { return *_frameAttribDict; }
406 
407  /** \return A reference to the material palette for this display frame */
408  inline DynamicMaterialArray& MaterialPalette( void ) { return _materialPalette; }
409 
410  /** \return A pointer to the light manager for this display frame */
411  inline ComponentLightMgr* LightMgr( void ) { return _lightMgr; }
412 
413  /** Sets the light manager for this display frame.
414  * This is used only for very special cases.
415  * The current LightMgr is NOT deleted when the new one is set.
416  * If this is used, it is recommended to restore the value to
417  * the original value.
418  * \param val The pointer to the new light manger.
419  */
420  inline void LightMgr( ComponentLightMgr* val ) { _lightMgr = val; }
421 
422  /** Call this before deleting objects which may be being kept
423  * by the drag or focus objects.
424  * If an object is to be deleted. The user must ensure that it is not
425  * being used as the drag or focus object. If it is, a leave event may
426  * be sent to it after it has been deleted, causing a crash.
427  * To avoid this the user can either ensure that the object never handles mouse events,
428  * or call ClearDragAndFocus() imediatly before deleting them */
429  virtual GLS_EXPORT void ClearDragAndFocus();
430 };
431 
432 } // namespace disti
433 
434 #endif
GLbitfield _clearBitfield
Definition: display_frame.h:96
Definition: display_frame.h:83
static void SetOpenGLDefaultState(bool saveVal)
virtual DisplayObject * FocusObject(void)
The disti metadata.
The disti::Material class.
The SoundSystem class for playback of audio files.
virtual void ClearFocus()
bool _cullingEnabled
Definition: display_frame.h:90
void SetResource(const std::string &resourceName, const std::string &resourceVal)
Definition: display_frame.h:235
ComponentLightMgr * LightMgr(void)
Definition: display_frame.h:411
virtual char * GetResources_CRTClean(GlsResourceFilter *filter)
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
virtual char * GetResource_CRTClean(const char *name)
virtual DisplayObject * HandleDisplayEvent(DisplayEvent *ev)
virtual void SetResources_CRTClean(const char *buf)
Definition: display_frame.h:75
SoundSystem * _sound_player
Definition: display_frame.h:136
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
DynamicArray< Material, false > DynamicMaterialArray
Definition: display_frame.h:69
virtual void ReadResources(const char *filename)
DistiAttribDict & FrameAttribDict(void)
Definition: display_frame.h:402
virtual void SetRedraw(void)
Definition: display.h:97
The disti::TexturePalette class.
The Message functions. Implements Messages to the user in the form of pop-up dialog boxes...
void PushObject(DisplayObject *obj)
virtual void NotifyAttributeChanged(const AttributeName &name)
static void RestoreOpenGLState(void)
std::string _componentHeaderFileName
Definition: display_frame.h:98
Definition: component_light_mgr.h:55
A file for all GL Studio files to include.
The disti::DisplayObject class and global enumerations.
The Image class. All textures are converted internally into Images.
const DistiAttribDict & FrameAttribDict(void) const
Definition: display_frame.h:405
Definition: scoped_ptr.h:53
Group * objects
Definition: display_frame.h:137
virtual DisplayObject * DragObject(void)
bool _multitouchEnabled
Definition: display_frame.h:102
std::string GetResource(const std::string &resourceName)
Definition: display_frame.h:247
The disti::Vertex class. A class for manipulating 3D vertices.
Generally useful defines, macros, enumerations and function prototypes.
bool CullingEnabled(void)
Definition: input_handler.h:115
DynamicMaterialArray & MaterialPalette(void)
Definition: display_frame.h:408
Definition: disti_metadata.h:174
TexturePalette * texturePalette
Definition: display_frame.h:135
virtual void CurrentCursor(unsigned int cursor_id)
Definition: events.h:110
virtual bool MultitouchEnabled(void)
void LightMgr(ComponentLightMgr *val)
Definition: display_frame.h:420
unsigned int _cursorsDown
Definition: display_frame.h:103
Definition: disti_metadata.h:667
GLbitfield ClearBitfield()
Definition: display_frame.h:156
ComponentLightMgr * _lightMgr
Definition: display_frame.h:95
Definition: sound.h:50
virtual void GetResourcesFree_CRTClean(char *memoryToFree)
DisplayFrame(int width, int height, bool allocateObjects=true)
void SetWidth(int w)
virtual DistiAttributeBase & Resource(const char *name)
virtual InputHandler * GetInputHandler()
Definition: group.h:52
int _height
Definition: display_frame.h:92
virtual float Scale(void)
Definition: display_frame.h:132
Definition: disti_metadata.h:443
virtual void WriteResources(const char *filename, GlsResourceFilter *filter=NULL)
int _width
Definition: display_frame.h:91
unsigned int _currentCursor
Definition: display_frame.h:101
virtual void SetResource_CRTClean(const char *name, const char *value)
The input handler interface.
virtual void ClearDragAndFocus()
A smart pointer with unique ownership – poor man's std::unique_ptr.
float _lastPickedDepth
Definition: display_frame.h:93
void SetTexturePaletteSize(int cnt)
Definition: texture_palette.h:143
DisplayObject * GetDragObjectForCursor(unsigned int cursorID)
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
virtual void SetResources(std::istream &instr)
Definition: gls_resources.h:50
virtual void GetResources(std::ostream &outstr, GlsResourceFilter *filter=NULL)
void ClearBitfield(GLbitfield bitField)
Definition: display_frame.h:151
Definition: bmpimage.h:46
void SetHeight(int h)
DynamicMaterialArray _materialPalette
Definition: display_frame.h:94
virtual void GetResourceFree_CRTClean(char *memoryToFree)
virtual void ClearDrag()
DisplayObject * FindDragObject()