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 #define LIB_BASE_NAME "gls_switch"
61 #include "gls_auto_lib.h"
62 #undef LIB_BASE_NAME
63 
64 namespace disti
65 {
66 enum
67 {
68  GLS_GLSSWITCH_INITIAL_DETENT_VAL = GLS_LAST_INITIALIZER + 1,
69  GLS_GLSSWITCH_WHICH_OBJECT_BACKGROUND,
70  GLS_GLSSWITCH_FIRST_DETENT_SNAPBACK, // for normal or snapback behavior
71  GLS_GLSSWITCH_LAST_DETENT_SNAPBACK, // for normal or snapback behavior
72  GLS_GLSSWITCH_EMIT_DETENT_VAL_EVENT,
73  GLS_GLSSWITCH_EMIT_LIMIT_EVENT,
74  GLS_GLSSWITCH_EMIT_RELEASE_EVENT
75 };
76 
77 /** Runtime implementation of a switch */
78 class GlsSwitch : public Group
79 {
80 private:
81  GlsSwitch& operator=( const GlsSwitch& ) DISTI_SPECIAL_MEM_FUN_DELETE;
82  GlsSwitch( const GlsSwitch& ) DISTI_SPECIAL_MEM_FUN_DELETE;
83 
84 public:
85  friend class GlsSwitchEditor;
86  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
87  typedef Group _BaseClass;
88  typedef Group BaseClass;
89 
90  int _detentVal; // CurrentPosition
91  bool _firstDetentSnapback;
92  bool _lastDetentSnapback;
93  int _whichObjectBackground; // the geometry index (plus 1) to serve as the switch background. 0 is no background object.
94  bool _emitDetentValEvent;
95 
96  /** Set if a DetentVal event should be emitted */
97  inline void EmitDetentValEvent( const bool& value );
98  /** Get if a DetentVal event should be emitted */
99  inline bool EmitDetentValEvent() { return _emitDetentValEvent; }
100 
101  /** Set if a Limit event should be emitted */
102  inline void EmitLimitEvent( const bool& value );
103  /** Get if a Limit event should be emitted */
104  inline bool EmitLimitEvent() { return _emitLimitEvent; }
105 
106  /** Set if a Release event should be emitted */
107  inline void EmitReleaseEvent( const bool& value );
108  /** Get if a Release event should be emitted */
109  inline bool EmitReleaseEvent() { return _emitReleaseEvent; }
110 
111  /** Returns the number of detents on this switch */
112  GLSGEN_GlsSwitch_EXPORT int NumDetents();
113  /** Returns the geometry associated with the detent */
114  GLSGEN_GlsSwitch_EXPORT DisplayObject* DetentGeometry( int detent ) const;
115  /** Returns the geometry specified as the background.
116  * NULL is returned if none
117  */
118  GLSGEN_GlsSwitch_EXPORT DisplayObject* BackgroundGeometry() const;
119 
120  /** Create a new GlsSwitch.
121  * \param generateInstance Whether or not to generate an instance name
122  * for this inputdevice */
123  GLSGEN_GlsSwitch_EXPORT GlsSwitch( bool generateInstance = false );
124 
125  GLSGEN_GlsSwitch_EXPORT GlsSwitch( const GlsSwitch& that, const bool generateNames );
126 
127  /** Destroy a GlsSwitch object */
128  virtual GLSGEN_GlsSwitch_EXPORT ~GlsSwitch();
129 
130  static GLSGEN_GlsSwitch_EXPORT DisplayObject* CreateInstance();
131 
132  virtual GLSGEN_GlsSwitch_EXPORT void SetAvailableAttributes( unsigned int value ) DISTI_METHOD_OVERRIDE;
133 
134  virtual GLSGEN_GlsSwitch_EXPORT DisplayObject* CloneObject( bool generateNames = false ) DISTI_METHOD_OVERRIDE;
135 
136  virtual GLSGEN_GlsSwitch_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler ) DISTI_METHOD_OVERRIDE;
137 
138  virtual GLSGEN_GlsSwitch_EXPORT void Draw( void ) DISTI_METHOD_OVERRIDE;
139 
140  virtual GLSGEN_GlsSwitch_EXPORT void CopyProperties( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
141 
142 #ifndef GLES
143  /* See base class */
144  virtual GLSGEN_GlsSwitch_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
145  virtual GLSGEN_GlsSwitch_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
146 #endif
147 
148  /* Calculates if this switch is horizontal or vertical relative to the y axis */
149  InputOrientationEnum InputType( void );
150 
151  GLSGEN_GlsSwitch_EXPORT DisplayObject* handle( DisplayEvent* ev ) DISTI_METHOD_OVERRIDE;
152 
153  /* See base class */
154  virtual GLSGEN_GlsSwitch_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
155 
156  /** Traverses upward in the hierarchy to determine if this object is visible in the scene.
157  */
158  GLSGEN_GlsSwitch_EXPORT bool IsVisibleInScene( const DisplayObject* obj = NULL ) const DISTI_METHOD_OVERRIDE;
159 
160  //////////////////////////////////////////////////
161  // Switch specific operations
162  //////////////////////////////////////////////////
163 
164  /** Sets current detent of the switch
165  * \param val New detent of the switch
166  */
167  virtual GLSGEN_GlsSwitch_EXPORT void DetentVal( const int& val );
168 
169  /** Returns the current detent of the switch
170  * \return Current switch detent
171  */
172  virtual GLSGEN_GlsSwitch_EXPORT int DetentVal();
173 
174  /** Sets current background geometry index value of the switch
175  * \param val New switch background geometry index value
176  */
177  virtual GLSGEN_GlsSwitch_EXPORT void WhichObjectBackground( const int& val );
178 
179  /** Returns the current background geometry index value of the switch
180  * \return Current switch background geometry index value
181  */
182  virtual GLSGEN_GlsSwitch_EXPORT int WhichObjectBackground() const;
183 
184  /** Returns the current background geometry index value of the switch
185  * \deprecated this method is not const correct, use const version instead
186  * \return Current switch background geometry index value
187  */
188  DISTI_DEPRECATED( "Use the const version instead." )
189  virtual int WhichObjectBackground() DISTI_FINAL
190  {
191  return const_cast<const GlsSwitch*>( this )->WhichObjectBackground();
192  }
193 
194 protected:
195  bool _emitLimitEvent;
196  bool _emitReleaseEvent;
197 
198  Vector _mouseDownOCoords;
199 
200  bool _mouseWasDown;
201  unsigned int _currentCursor; // the current cursor used for interaction. Any other cursors are ignored while interacting.
202 
203  /** Uses event data to calculate a new switch position based on the DCS of the object.
204  * This is not intended to be called directly.
205  */
207  InputOrientationEnum inputType, int numPositions,
208  float scale = 1.0f );
209 
210 #ifdef GLES
211  /** Set a single attribute from the GLO file.
212  * \param data The attribute to set and its associated data.
213  */
214  virtual GLSGEN_GlsSwitch_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
215 #endif
216 };
217 
218 } // namespace disti
219 
220 #endif
Definition: cull.h:49
virtual ~GlsSwitch()
DisplayObject * handle(DisplayEvent *ev) DISTI_METHOD_OVERRIDE
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:436
Definition: dynamic_array.h:66
The disti::Group class. Implements groups of objects.
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:471
virtual DisplayObject * CloneObject(bool generateNames=false) DISTI_METHOD_OVERRIDE
bool EmitDetentValEvent()
Definition: gls_switch.h:99
Definition: display.h:98
virtual int WhichObjectBackground() const
int CalcSwitchPosDCS(DisplayObject *self, DisplayEvent *ev, InputOrientationEnum inputType, int numPositions, float scale=1.0f)
InputOrientationEnum
Enumeration for Input Operators.
Definition: glsutil.h:262
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler) DISTI_METHOD_OVERRIDE
bool EmitLimitEvent()
Definition: gls_switch.h:104
Definition: gls_glo_file.h:988
virtual void CopyProperties(DisplayObject *src) DISTI_METHOD_OVERRIDE
Definition: gls_switch.h:78
virtual void Draw(void) DISTI_METHOD_OVERRIDE
DisplayObject * BackgroundGeometry() const
virtual void SetAvailableAttributes(unsigned int value) DISTI_METHOD_OVERRIDE
bool IsVisibleInScene(const DisplayObject *obj=NULL) const DISTI_METHOD_OVERRIDE
Definition: events.h:112
The gls_auto_lib.
DisplayObject * DetentGeometry(int detent) const
Definition: group.h:52
Definition: vertex.h:84
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) DISTI_METHOD_OVERRIDE
virtual int DetentVal()
Macros and helper code to determine what subset of C++11/14/17 is available.
GL Studio helper functions.
Definition: bmpimage.h:46
bool EmitReleaseEvent()
Definition: gls_switch.h:109
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array) DISTI_METHOD_OVERRIDE
virtual void SetValue(int spec, va_list &args) DISTI_METHOD_OVERRIDE