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