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