GL Studio C++ Runtime API
component_base.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::ComponentBase 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 _COMPONENT_BASE_H
41 #define _COMPONENT_BASE_H
42 
43 #include "display_frame.h"
44 #include "gls_include.h"
45 #include "group.h"
46 #include "version.h"
47 
48 namespace disti
49 {
50 class LiveComponentAccessor;
51 
52 /** Sets the default value for absolute placent. If not set, the default will be true.
53  * Typically only used for backwards compatibility with previous versions of GL Studio
54  * \param value true if the absolute placement default should be true, false otherwise.
55  */
56 GLS_EXPORT void SetAbsolutePlacementDefault( bool value );
57 
58 /** Gets the default value for absolute placent.
59  */
60 GLS_EXPORT bool GetAbsolutePlacementDefault();
61 
62 /** The ComponentBase class is derived from Group and DisplayFrame.
63  It is capable of containing objects as well as drawing them.
64  It is used for encapsulating object geometry and behavior.
65  The behavior is defined when this object is derived.
66  */
67 class ComponentBase : public Group
68  , public DisplayFrame
69 {
70 public:
71  typedef Group _BaseClass;
72  friend class disti::LiveComponentAccessor;
73 
74  /** Constructor
75  * \param generateInstance If true generates a new unique instance name
76  */
77  GLS_EXPORT ComponentBase( int generateInstance = FALSE );
78 
79  /** Cleans up the object and destructs it.
80  * Don't call "delete yourComponent", instead call yourComponent->Destroy().
81  * If this is an RSO, it will be completely destroyed, including the DLL.
82  */
83  virtual GLS_EXPORT ~ComponentBase();
84 
85  /** Create RSO static
86  * This will load the specified DLL and try to create the specified class.
87  * It will return the ComponentBase* on success, and NULL on failure.
88  * Internally, this uses a LiveComponentAccessor. If more control is needed,
89  * it is recommended to create a LiveComponentAccessor.
90  * \param fileName The name of the DLL
91  * \param className The class name to create. If NULL, the default class will be created.
92  * \param performCreate If true, CreateObjects() will be called, otherwise it will not.
93  * \param callingVersion
94  * \return NULL on failure.*/
95  static GLS_EXPORT ComponentBase* CreateLiveComponent( const char* fileName = NULL, const char* className = NULL, bool performCreate = true, const GlsBuiltVersionInfo& callingVersion = GlsBuiltVersionInfo() );
96 
97  /** Returns true if version checks ok, false if there MIGHT be a problem.
98  * The consequences of version mismatches depend on the methods that will be
99  * called on the object. This will emit warnings to stdout.
100  * \param comp RSO
101  * \param callingVersion Leave this as the default and it will use the calling function's version information.
102  * \return true If version is considered OK.
103  */
104  static GLS_EXPORT bool CheckLiveVersion( ComponentBase* comp, const GlsBuiltVersionInfo& callingVersion = GlsBuiltVersionInfo() );
105 
106  virtual GLS_EXPORT void SetAvailableAttributes( unsigned int value );
107 
108  /** Gets the value for Absolute Placement.
109  * If true, the component will be left in the generated location. Otherwise it will be moved
110  * based on its extents
111  */
112  bool AbsolutePlacement() const { return _absolutePlacement; }
113 
114  virtual GLS_EXPORT void ChangedAbsolutePlacement( bool val );
115 
116  /** Sets the value for Absolute Placement. This affects what happens
117  * durring the call to CreateObjects().
118  * If true, the component will be left in the generated location. Otherwise it will be moved
119  * based on its extents
120  */
121  virtual GLS_EXPORT void AbsolutePlacement( bool val );
122 
123  /* See base class */
124  virtual GLS_EXPORT void CalculateBoundingBox( void );
125 
126  /** Call this before deleting objects which may be being kept
127  * by the drag or focus objects. */
128  virtual GLS_EXPORT void ClearDragAndFocus();
129 
130  /* See base class */
131  virtual GLS_EXPORT DisplayObject* CloneObject( bool generateNames = false );
132 
133  /* Copies the geometry information from one object to another.
134  * In a ComponentBase, this does nothing.
135  * \param src The object to copy geometry from.
136  */
137  virtual GLS_EXPORT void CopyGeometry( DisplayObject* src );
138 
139  /* See base class */
140  virtual GLS_EXPORT void CopyProperties( DisplayObject* src );
141 
142 #ifndef GLES
143  /* See base class */
144  virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL );
145 
146  /* See base class */
147  virtual GLS_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array );
148 #endif
149 
150  /** In derived classes this creates all the geometry for the component */
151  virtual GLS_EXPORT void CreateObjects();
152 
153  /** Overriden to avoid children getting deleted until object deletion. */
154  virtual GLS_EXPORT void DeleteAllChildren();
155 
156  /** Draws this object and all its contained objects in the current OpenGL pipeline.
157  This can be overloaded to perform any special effects.
158  If PreDraw and Draw are needed, call DisplayFrame::Draw() */
159  virtual GLS_EXPORT void Draw();
160 
161  /** Finds a pointer to the display object in the group, using the object's
162  * instance name as a key.
163  * Because this is a component, it will always return NULL.
164  * \param name Instance name of the object to find
165  * \return A pointer to the object if it is in the group, otherwise NULL
166  */
167  virtual GLS_EXPORT DisplayObject* FindByNameSameFrame( const char* name );
168 
169  /* Figure out the min and max x&y extents for the object.
170  * Modify results by _scale
171  * \param x Gets the minimum x extent
172  * \param y Gets the minimum y extent
173  * \param z Gets the minimum z extent
174  * \param x1 Gets the maximum x extent
175  * \param y1 Gets the maximum y extent
176  * \param z1 Gets the maximum z extent
177  */
178  virtual GLS_EXPORT void GetExtents( float& x, float& y, float& z, float& x1, float& y1, float& z1 );
179 
180  /** Determines the extents of geometry projected to the XY plane of an arbirary coordinate system.
181  * \param min Returns the minimum values found in the traversal
182  * \param max Returns the maximum values found in the traversal
183  * \param matrix Transformation matrix from world coordinates to the desired coordinate system.
184  * \param resetMinMax Normally not specified by user. Should be true for the initial call.
185  */
186  virtual GLS_EXPORT void GetTransformedExtents( Vector& min, Vector& max, const GlsMatrixType& matrix, bool resetMinMax = true );
187 
188  /** Handles input events.
189  * It traverses the hierarchy with Pick3D.
190  * Then THE picked object is given the handle() call.
191  * \param ev The event data.
192  * \returns The object that handled the input.
193  */
194  virtual GLS_EXPORT DisplayObject* HandleInput( DisplayEvent* ev );
195 
196  /** Peforms post creation tasks including reparenting all objects.
197  * and adjusting their position.
198  * It checks the value of _absolutePlacement to determine if movement of the
199  * generated objects is necessary
200  * /see AbsolutePlacement
201  */
202  virtual GLS_EXPORT void Init();
203 
204  /** The GL Studio code generator allways derives a new Initialize method for the user
205  This is called after all the objects are created.
206  */
207  virtual GLS_EXPORT void Initialize();
208 
209  /** If this component was loaded from an RSO library,
210  * this method returns the object's library reference.
211  * The library reference should be deleted AFTER the component is deleted.
212  * If the component was not loaded from an RSO library,
213  * this method returns NULL.
214  */
216 
217  using Group::Location;
218  virtual GLS_EXPORT const Vertex& Location( void ) const DISTI_METHOD_OVERRIDE { return Group::Location(); }
219 
220  /* See base class */
221  virtual GLS_EXPORT void Location( const Vertex& v ) DISTI_METHOD_OVERRIDE;
222 
223  /* See base class */
224  virtual GLS_EXPORT void Location( float x, float y, float z );
225 
226  /* Unhides base class implementation. */
227  // force inheritance
228  using Group::Parent;
229 
230  /** Sets the DisplayFrame for this object.
231  * It does not set the specified parent for all the children.
232  * Instead, it sets all the children's parent to 'this'. And
233  * saves the argument 'par' in _parentDisplayFrame. This
234  * allows special traversals, which traverse out of the ComponentBase
235  * to the ComponentBase's parent.
236  * \param par The parent which will be saved in _parentDisplayFrame
237  * \see ParentDisplayFrame
238  */
239  virtual GLS_EXPORT void Parent( DisplayFrame* par );
240 
241  /** Gets the value of the DisplayFrame containing this component
242  * \return the value of the DisplayFrame containing this component.
243  * Returns NULL if there is no parent DisplayFrame
244  */
246 
247  /** Sets the parent DisplayFrame for this object. This is normally only set by a
248  * call to Parent().
249  * \param val The new val for _parentDisplayFrame
250  * \see ComponentBase::Parent()
251  */
252  inline void ParentDisplayFrame( DisplayFrame* val ) { _parentDisplayFrame = val; }
253 
254  /* See base class */
255  virtual GLS_EXPORT DisplayObject* Pick3D( const Vector& winLoc,
256  const Vector& logicalCoords,
257  float scale,
258  const Vector& directionVector,
259  Vector& collisionWinLoc /*Returned*/,
260  const OpenGLMatrices& drawnMatrices );
261 
262  /* See base class */
263  virtual GLS_EXPORT void PreDraw( const OpenGLMatrices& current, Culler& culler );
264 
265  /* See base class */
266  virtual GLS_EXPORT void GetResources( std::ostream& outstr, GlsResourceFilter* filter = NULL );
267 
268  /* See base class */
269  virtual GLS_EXPORT DistiAttributeBase& Resource( const char* name );
270 
271  /* Unhides base class implementation. */
272  using Group::Rotate;
273  using Group::Scale;
274 
275  /* See base class */
276  virtual GLS_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis );
277 
278  /* See base class */
279  virtual GLS_EXPORT void Scale( float px, float py, float pz, Vertex* parentAnchor, int handleBar = 0 );
280 
281  /** This will call our parent display frame's SetRedraw() causing
282  this component to be redrawn in the future.
283  */
284  virtual GLS_EXPORT void SetRedraw( void );
285 
286  /* See base class */
287  virtual GLS_EXPORT void Translate( float tr[] );
288 
289  /* See base class */
290  virtual GLS_EXPORT void Translate( float x, float y, float z );
291 
292  /** If UseParentsLighting is true, the component will add
293  * it's lights to those already set by it's parent.
294  * If false, the component will only use it's own lights.
295  */
296  virtual GLS_EXPORT void UseParentsLighting( const bool& );
297 
298  /** If UseParentsLighting is true, the component will add
299  * it's lights to those already set by it's parent.
300  * If false, the component will only use it's own lights.
301  */
302  virtual GLS_EXPORT bool UseParentsLighting();
303 
304  /** Overridden so we will always get -1 for our texture index.
305  * This keeps our children from trying to draw with our texture
306  * index which would be for the wrong palette.
307  */
308  virtual GLS_EXPORT int TextureIndex();
309  virtual GLS_EXPORT void TextureIndex( int index ) { _BaseClass::TextureIndex( index ); }
310 
311  /* See base class */
312  GLS_EXPORT void SetValue( int spec, va_list& args );
313 
314  /** \see DisplayFrame
315  * Returns the parents input handler if a parent exists, else returns this component's input handler
316  */
317  virtual GLS_EXPORT InputHandler* GetInputHandler();
318 
319  /** overrides DisplayObject::NotifyAttributeChanged */
320  GLS_EXPORT void NotifyAttributeChanged( const AttributeName& name ) DISTI_METHOD_OVERRIDE;
321 
322 protected:
323  LiveComponentAccessor* _liveAccessor; /**< /see ComponentBase::LiveAccessor */
324  bool _absolutePlacement; /**< /see ComponentBase::AbsolutePlacement */
325  Vertex _absolutePlacementDelta; /** The delta vector used when using relative placemnt */
326  DisplayFrame* _parentDisplayFrame; /**< /see ComponentBase::ParentDisplayFrame */
327  GlsMatrixType _editorTransformMatrix; /**< The static transformation from the internal component coordinates to the parent's coordinate system */
328 
329  /** Overridden from base class
330  * This adds the _editorTransformMatrix to the DCS. You will need to call CalcDrawMatrix whenever the _editorTransformMatrix changes.*/
331  virtual GLS_EXPORT void CalcDrawMatrix();
332 
333  /* Overridden from base class */
334  virtual GLS_EXPORT void CalculateMatrices( const OpenGLMatrices& newMatrices );
335  GLS_EXPORT void EditorTransformMatrix( const GlsMatrixType& matrix );
336  GLS_EXPORT const GlsMatrixType& EditorTransformMatrix() const;
337 
338 #ifdef GLES
339  /** Set a single attribute from the GLO file.
340  * \param data The attribute to set and its associated data.
341  */
342  virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data );
343 #endif
344 
345 private:
346  DisplayObject* PickFirst( const Vector& winLoc, const Vector& logicalCoords, float scale, const Vector& directionVector, Vector& collisionWinLoc /*Returned*/, const OpenGLMatrices& drawnMatrices );
347  DisplayObject* PickBest( const Vector& winLoc, const Vector& logicalCoords, float scale, const Vector& directionVector, Vector& collisionWinLoc /*Returned*/, const OpenGLMatrices& drawnMatrices );
348 };
349 
350 typedef ComponentBase* ( *ComponentBaseCreateFunc )();
351 /** Returns the directory of the .dll or .so that calls this function. */
352 #ifdef WIN32
353 GLS_EXPORT std::string GetComponentDirectory( HINSTANCE module );
354 #else
355 GLS_EXPORT std::string GetComponentDirectory( void* module );
356 #endif
357 } // namespace disti
358 
359 #endif
Definition: cull.h:49
virtual void PreDraw(const OpenGLMatrices &current, Culler &culler)
Definition: display_frame.h:83
std::string GetComponentDirectory(void *module)
virtual const Vertex & Location(void) const
virtual InputHandler * GetInputHandler()
virtual int TextureIndex()
Definition: vertex.h:408
virtual void CopyProperties(DisplayObject *src)
virtual DisplayObject * FindByNameSameFrame(const char *name)
Definition: dynamic_array.h:62
virtual void Rotate(const Vector &orig, float angle, const Vector &axis)
virtual const Vertex & Location(void) const
Definition: component_base.h:218
The disti::Group class. Implements groups of objects.
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:278
ComponentBase(int generateInstance=0)
virtual DisplayObject * CloneObject(bool generateNames=false)
DisplayFrame * Parent(void) const
Definition: display.h:897
virtual void CopyGeometry(DisplayObject *src)
virtual void GetExtents(float &x, float &y, float &z, float &x1, float &y1, float &z1)
virtual void Draw()
Definition: display.h:97
virtual void CalculateMatrices(const OpenGLMatrices &newMatrices)
GlsMatrixType _editorTransformMatrix
Definition: component_base.h:327
virtual void Translate(float tr[])
LiveComponentAccessor * LiveAccessor()
Definition: component_base.h:215
void SetAbsolutePlacementDefault(bool value)
LiveComponentAccessor * _liveAccessor
Definition: component_base.h:323
A file for all GL Studio files to include.
Definition: gls_glo_file.h:835
bool GetAbsolutePlacementDefault()
virtual void Init()
static ComponentBase * CreateLiveComponent(const char *fileName=NULL, const char *className=NULL, bool performCreate=true, const GlsBuiltVersionInfo &callingVersion=GlsBuiltVersionInfo())
virtual void TextureIndex(int index)
Definition: component_base.h:309
Definition: component_base.h:67
virtual ~ComponentBase()
virtual void SetAvailableAttributes(unsigned int value)
virtual DisplayObject * HandleInput(DisplayEvent *ev)
void ParentDisplayFrame(DisplayFrame *val)
Definition: component_base.h:252
virtual DistiAttributeBase & Resource(const char *name)
virtual DisplayObject * Pick3D(const Vector &winLoc, const Vector &logicalCoords, float scale, const Vector &directionVector, Vector &collisionWinLoc, const OpenGLMatrices &drawnMatrices)
virtual int TextureIndex(void)
DisplayFrame * _parentDisplayFrame
Definition: component_base.h:326
void SetValue(int spec, va_list &args)
static bool CheckLiveVersion(ComponentBase *comp, const GlsBuiltVersionInfo &callingVersion=GlsBuiltVersionInfo())
Definition: input_handler.h:115
bool _absolutePlacement
Definition: component_base.h:324
Definition: disti_metadata.h:174
virtual void DeleteAllChildren()
Definition: events.h:110
virtual void GetTransformedExtents(Vector &min, Vector &max, const GlsMatrixType &matrix, bool resetMinMax=true)
Used for matching version of libraries and headers.
virtual void Initialize()
Definition: version.h:212
The disti::DisplayFrame class.
virtual void SetRedraw(void)
virtual void CalcDrawMatrix()
virtual void ClearDragAndFocus()
Definition: group.h:52
virtual float Scale(void)
Definition: display_frame.h:132
Definition: vertex.h:83
Definition: live_component_accessor.h:54
virtual void Rotate(const Vector &orig, float angle, const Vector &axis)
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
Definition: gls_resources.h:50
DisplayFrame * ParentDisplayFrame() const
Definition: component_base.h:245
bool AbsolutePlacement() const
Definition: component_base.h:112
Definition: disti_metadata.h:79
virtual bool UseParentsLighting()
Definition: bmpimage.h:46
virtual void CreateObjects()
void NotifyAttributeChanged(const AttributeName &name)
virtual void GetResources(std::ostream &outstr, GlsResourceFilter *filter=NULL)
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)