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