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