| GL Studio C++ Runtime API

gls_switch.h
Go to the documentation of this file.
1/*! \file
2 \brief The disti::GlsSwitch 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 _GLS_SWITCH_H
41#define _GLS_SWITCH_H
42
43#include "gls_cpp_lang_support.h"
44#include "glsutil.h"
45#include "group.h"
46
47/// Provides support for creating DLLs.
48#if( defined( GLSGEN_EXPORT_GlsSwitch ) || defined( GLSGEN_IMPORT_GlsSwitch ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
49 && defined( _MSC_VER )
50# if defined( GLSGEN_EXPORT_GlsSwitch ) || defined( GLS_EXPORT_GENERATED )
51# define GLSGEN_GlsSwitch_EXPORT __declspec( dllexport )
52# else
53# define GLSGEN_GlsSwitch_EXPORT __declspec( dllimport )
54# endif
55#else
56# define GLSGEN_GlsSwitch_EXPORT
57#endif
58///////////////////////////////////////////////////////////////////////////////
59
60/// Automatically link the runtime library plugin (on Windows).
61#define LIB_BASE_NAME "gls_switch"
62#include "gls_auto_lib.h"
63#undef LIB_BASE_NAME
64
65 namespace disti
66{
67 enum
68{
69 GLS_GLSSWITCH_INITIAL_DETENT_VAL = GLS_LAST_INITIALIZER + 1,
70 GLS_GLSSWITCH_WHICH_OBJECT_BACKGROUND,
71 GLS_GLSSWITCH_FIRST_DETENT_SNAPBACK, // for normal or snapback behavior
72 GLS_GLSSWITCH_LAST_DETENT_SNAPBACK, // for normal or snapback behavior
73 GLS_GLSSWITCH_EMIT_DETENT_VAL_EVENT,
74 GLS_GLSSWITCH_EMIT_LIMIT_EVENT,
75 GLS_GLSSWITCH_EMIT_RELEASE_EVENT
76};
77
78/** Runtime implementation of a switch */
79 class GlsSwitch : public Group
80{
81 private:
82 GlsSwitch& operator=( const GlsSwitch& ) DISTI_SPECIAL_MEM_FUN_DELETE;
83 GlsSwitch( const GlsSwitch& ) DISTI_SPECIAL_MEM_FUN_DELETE;
84
85 public:
86 friend class GlsSwitchEditor;
87 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
88 typedef Group _BaseClass; ///< Deprecated typedef for the base class.
89 typedef Group BaseClass; ///< Typedef for the base class.
90
91 int _detentVal; ///< CurrentPosition
92 bool _firstDetentSnapback; ///< If true, the position will snap from the first detent back to the second detent when released.
93 bool _lastDetentSnapback; ///< If true, the position will snap from the last detent back to the second to last detent when released.
94 int _whichObjectBackground; ///< the geometry index (plus 1) to serve as the switch background. 0 is no background object.
95 bool _emitDetentValEvent; ///< If true, events will be emitted whenever the detent value changes.
96
97 /// Set if a DetentVal event should be emitted.
98 /// \param value The new emit event flag to set.
99 inline void EmitDetentValEvent( const bool& value );
100
101 /// \return Whether or not a DetentVal event should be emitted.
102 inline bool EmitDetentValEvent() { return _emitDetentValEvent; }
103
104 /// Set if a Limit event should be emitted.
105 /// \param value The new emit event flag to set.
106 inline void EmitLimitEvent( const bool& value );
107
108 /// \return Whether or not a Limit event should be emitted.
109 inline bool EmitLimitEvent() { return _emitLimitEvent; }
110
111 /// Set if a Release event should be emitted.
112 /// \param value The new emit event flag to set.
113 inline void EmitReleaseEvent( const bool& value );
114
115 /// \return Whether or not a Release event should be emitted.
116 inline bool EmitReleaseEvent() { return _emitReleaseEvent; }
117
118 /// \return The number of detents on this switch.
119 GLSGEN_GlsSwitch_EXPORT int NumDetents();
120
121 /// \returns The geometry associated with the detent.
122 /// \param detent The index of the detent whose geometry is to be returned.
123 GLSGEN_GlsSwitch_EXPORT DisplayObject* DetentGeometry( int detent ) const;
124
125 /// \return The geometry specified as the background, NULL is returned if none.
126 GLSGEN_GlsSwitch_EXPORT DisplayObject* BackgroundGeometry() const;
127
128 /// Create a new GlsSwitch.
129 /// \param generateInstance Whether or not to generate an instance name for this object.
130 GLSGEN_GlsSwitch_EXPORT GlsSwitch( bool generateInstance = false );
131
132 /// Copy constructor
133 /// \param that The object to copy from.
134 /// \param generateNames Whether or not to generate an instance name for this object.
135 GLSGEN_GlsSwitch_EXPORT GlsSwitch( const GlsSwitch& that, const bool generateNames );
136
137 /** Destroy a GlsSwitch object */
138 virtual GLSGEN_GlsSwitch_EXPORT ~GlsSwitch();
139
140 /// \return A pointer to a new GlsSwitch object.
141 static GLSGEN_GlsSwitch_EXPORT DisplayObject* CreateInstance();
142
143 virtual GLSGEN_GlsSwitch_EXPORT void SetAvailableAttributes( unsigned int value ) DISTI_METHOD_OVERRIDE;
144
145 virtual GLSGEN_GlsSwitch_EXPORT DisplayObject* CloneObject( bool generateNames = false ) DISTI_METHOD_OVERRIDE;
146
147 virtual GLSGEN_GlsSwitch_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler ) DISTI_METHOD_OVERRIDE;
148
149 virtual GLSGEN_GlsSwitch_EXPORT void Draw() DISTI_METHOD_OVERRIDE;
150
151 virtual GLSGEN_GlsSwitch_EXPORT void CopyProperties( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
152
153#ifndef GLES
154 virtual GLSGEN_GlsSwitch_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
155 virtual GLSGEN_GlsSwitch_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
156#endif
157
158 /// \return Whether or not this switch is horizontal or vertical relative to the y axis.
159 InputOrientationEnum InputType();
160
161 GLSGEN_GlsSwitch_EXPORT DisplayObject* handle( DisplayEvent* ev ) DISTI_METHOD_OVERRIDE;
162
163 virtual GLSGEN_GlsSwitch_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
164
165 GLSGEN_GlsSwitch_EXPORT bool IsVisibleInScene( const DisplayObject* obj = NULL ) const DISTI_METHOD_OVERRIDE;
166
167 //////////////////////////////////////////////////
168 // Switch specific operations
169 //////////////////////////////////////////////////
170
171 /** Sets current detent of the switch
172 * \param val New detent of the switch
173 */
174 virtual GLSGEN_GlsSwitch_EXPORT void DetentVal( const int& val );
175
176 /** Returns the current detent of the switch
177 * \return Current switch detent
178 */
179 virtual GLSGEN_GlsSwitch_EXPORT int DetentVal();
180
181 /** Sets current background geometry index value of the switch
182 * \param val New switch background geometry index value
183 */
184 virtual GLSGEN_GlsSwitch_EXPORT void WhichObjectBackground( const int& val );
185
186 /** Returns the current background geometry index value of the switch
187 * \return Current switch background geometry index value
188 */
189 virtual GLSGEN_GlsSwitch_EXPORT int WhichObjectBackground() const;
190
191 /** Returns the current background geometry index value of the switch
192 * \deprecated this method is not const correct, use const version instead
193 * \return Current switch background geometry index value
194 */
195 DISTI_DEPRECATED( "Use the const version instead." )
196 virtual int WhichObjectBackground() DISTI_FINAL
197 {
198 return const_cast<const GlsSwitch*>( this )->WhichObjectBackground();
199 }
200
201 protected:
202 bool _emitLimitEvent; ///< If true, an event will be emitted when the switch hits its maximum or minimum state.
203 bool _emitReleaseEvent; ///< If true, an event will be emitted when the switch is released.
204
205 Vector _mouseDownOCoords; ///< Stores the object coordinates of the last mouse down on this object.
206
207 bool _mouseWasDown; ///< Whether or not the mouse is down on this object.
208 unsigned int _currentCursor; ///< The current cursor used for interaction. Any other cursors are ignored while interacting.
209
210 /// Uses event data to calculate a new switch position based on the DCS of the object.
211 /// \note This is not intended to be called directly.
212 /// \param self This object.
213 /// \param ev The input event.
214 /// \param inputType The input type of this switch.
215 /// \param numPositions The number of positions in this switch.
216 /// \param scale Additional scale to be applied.
217 /// \return The new position of the switch.
218 int CalcSwitchPosDCS( DisplayObject* self, DisplayEvent* ev,
219 InputOrientationEnum inputType, int numPositions,
220 float scale = 1.0f );
221
222#ifdef GLES
223 /** Set a single attribute from the GLO file.
224 * \param data The attribute to set and its associated data.
225 */
226 virtual GLSGEN_GlsSwitch_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
227#endif
228};
229
230} // namespace disti
231
232#endif
disti::Culler
Definition: cull.h:50
disti::DisplayEvent
Definition: events.h:113
disti::DisplayObject
Definition: display.h:96
disti::DynamicArray
Definition: dynamic_array.h:79
disti::GlsGloFileAttribute
Definition: gls_glo_file.h:1243
disti::GlsSwitch
Definition: gls_switch.h:80
disti::GlsSwitch::_detentVal
int _detentVal
CurrentPosition.
Definition: gls_switch.h:91
disti::GlsSwitch::_emitDetentValEvent
bool _emitDetentValEvent
If true, events will be emitted whenever the detent value changes.
Definition: gls_switch.h:95
disti::GlsSwitch::_firstDetentSnapback
bool _firstDetentSnapback
If true, the position will snap from the first detent back to the second detent when released.
Definition: gls_switch.h:92
disti::GlsSwitch::SetAvailableAttributes
virtual void SetAvailableAttributes(unsigned int value) DISTI_METHOD_OVERRIDE
disti::GlsSwitch::Draw
virtual void Draw() DISTI_METHOD_OVERRIDE
disti::GlsSwitch::_currentCursor
unsigned int _currentCursor
The current cursor used for interaction. Any other cursors are ignored while interacting.
Definition: gls_switch.h:208
disti::GlsSwitch::GlsSwitch
GlsSwitch(bool generateInstance=false)
disti::GlsSwitch::NumDetents
int NumDetents()
disti::GlsSwitch::GlsSwitch
GlsSwitch(const GlsSwitch &that, const bool generateNames)
disti::GlsSwitch::CloneObject
virtual DisplayObject * CloneObject(bool generateNames=false) DISTI_METHOD_OVERRIDE
disti::GlsSwitch::SetFromGloData
virtual void SetFromGloData(GlsGloFileAttribute &data) DISTI_METHOD_OVERRIDE
disti::GlsSwitch::PreDraw
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler) DISTI_METHOD_OVERRIDE
disti::GlsSwitch::DetentVal
virtual int DetentVal()
disti::GlsSwitch::SetValue
virtual void SetValue(int spec, va_list &args) DISTI_METHOD_OVERRIDE
disti::GlsSwitch::DetentVal
virtual void DetentVal(const int &val)
disti::GlsSwitch::~GlsSwitch
virtual ~GlsSwitch()
disti::GlsSwitch::_mouseWasDown
bool _mouseWasDown
Whether or not the mouse is down on this object.
Definition: gls_switch.h:207
disti::GlsSwitch::handle
DisplayObject * handle(DisplayEvent *ev) DISTI_METHOD_OVERRIDE
disti::GlsSwitch::CreateInstance
static DisplayObject * CreateInstance()
disti::GlsSwitch::IsVisibleInScene
bool IsVisibleInScene(const DisplayObject *obj=NULL) const DISTI_METHOD_OVERRIDE
disti::GlsSwitch::_emitReleaseEvent
bool _emitReleaseEvent
If true, an event will be emitted when the switch is released.
Definition: gls_switch.h:203
disti::GlsSwitch::InputType
InputOrientationEnum InputType()
disti::GlsSwitch::EmitLimitEvent
void EmitLimitEvent(const bool &value)
disti::GlsSwitch::_mouseDownOCoords
Vector _mouseDownOCoords
Stores the object coordinates of the last mouse down on this object.
Definition: gls_switch.h:205
disti::GlsSwitch::BackgroundGeometry
DisplayObject * BackgroundGeometry() const
disti::GlsSwitch::WhichObjectBackground
virtual void WhichObjectBackground(const int &val)
disti::GlsSwitch::CopyProperties
virtual void CopyProperties(DisplayObject *src) DISTI_METHOD_OVERRIDE
disti::GlsSwitch::_whichObjectBackground
int _whichObjectBackground
the geometry index (plus 1) to serve as the switch background. 0 is no background object.
Definition: gls_switch.h:94
disti::GlsSwitch::EmitDetentValEvent
bool EmitDetentValEvent()
Definition: gls_switch.h:102
disti::GlsSwitch::EmitReleaseEvent
void EmitReleaseEvent(const bool &value)
disti::GlsSwitch::WhichObjectBackground
virtual int WhichObjectBackground() const
disti::GlsSwitch::_emitLimitEvent
bool _emitLimitEvent
If true, an event will be emitted when the switch hits its maximum or minimum state.
Definition: gls_switch.h:202
disti::GlsSwitch::EmitReleaseEvent
bool EmitReleaseEvent()
Definition: gls_switch.h:116
disti::GlsSwitch::_lastDetentSnapback
bool _lastDetentSnapback
If true, the position will snap from the last detent back to the second to last detent when released.
Definition: gls_switch.h:93
disti::GlsSwitch::CalcSwitchPosDCS
int CalcSwitchPosDCS(DisplayObject *self, DisplayEvent *ev, InputOrientationEnum inputType, int numPositions, float scale=1.0f)
disti::GlsSwitch::EmitLimitEvent
bool EmitLimitEvent()
Definition: gls_switch.h:109
disti::GlsSwitch::DetentGeometry
DisplayObject * DetentGeometry(int detent) const
disti::Group
Definition: group.h:53
disti::OpenGLMatrices
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:544
disti::VertexNoColor
Definition: vertex.h:85
gls_auto_lib.h
The gls_auto_lib.
gls_cpp_lang_support.h
Macros and helper code to determine what subset of C++11/14/17 is available.
DISTI_SPECIAL_MEM_FUN_DELETE
#define DISTI_SPECIAL_MEM_FUN_DELETE
Macro to wrap function deletion, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:246
DISTI_DEPRECATED
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:488
DISTI_FINAL
#define DISTI_FINAL
Macro to wrap the final keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:224
DISTI_METHOD_OVERRIDE
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:222
GLSGEN_GlsSwitch_EXPORT
#define GLSGEN_GlsSwitch_EXPORT
Provides support for creating DLLs.
Definition: gls_switch.h:56
glsutil.h
GL Studio helper functions.
group.h
The disti::Group class. Implements groups of objects.
disti
Definition: bmpimage.h:47
disti::InputOrientationEnum
InputOrientationEnum
Enumeration for Input Operators.
Definition: glsutil.h:271