GL Studio SCECpp Runtime Library
gls_input_manager.h
Go to the documentation of this file.
1 #ifndef _GLS_INPUT_MANAGER_H
2 #define _GLS_INPUT_MANAGER_H
3 
4 /*! \file gls_input_manager.h
5 \brief This header defines the Input Manager class for managing user input
6  in the GL Studio DO-178B Runtime Library.
7 
8 \par Copyright Information
9 Copyright (C) 1999-2012 The DiSTI Corporation<br>
10 Orlando, FL USA<br>
11 All rights reserved.<br>
12 
13  This file is copyrighted software and contains proprietary trade secrets of
14 DiSTI, and embodies substantial creative efforts as well as confidential
15 information, ideas, and expressions.
16 
17  Permission to use, and copy this software and its documentation for any
18 purpose is hereby granted per the Distribution Agreement and/or the Licensing
19 Agreement signed with DiSTI. This permission is granted provided that:
20  1. The above copyright notice appears in all copies.
21  2. That both the copyright notice and this permission notice appear in
22  the supporting documentation.
23  3. That the names DiSTI and GL Studio not be used in advertising or
24  publicity pertaining to distribution of the software without specific,
25  written prior permission of DiSTI.
26 
27  Permission to modify the software is granted, but not the right to
28 distribute the source code whether modified, or non-modified. Modifying the
29 software might invalidate the DO-178B certification package.
30 
31  Permission to distribute binaries produced by compiling source code, or
32 modified source code is granted, provided you:
33  1. Provide your name and address as the primary contact for the support
34  of your modified version.
35  2. Retain our contact information in regard to use of the base software.
36 
37  DiSTI does not provide warranty for this software or guarantee that it
38 satisfies any specification or requirement unless otherwise stated in a
39 specific contractual arrangement between the customer and DiSTI.
40 
41 */
42 
43 #include "gls_include.h"
44 #include "gls_types.h"
46 #include "gls_display_object.h"
47 #include "gls_class_invariant.h"
48 
49 /** This class manages user input.
50  * \invariant GLMatrixAffineFIsValid( _projMatrix )
51  * GLMatrixAffineFIsValid( _modelMatrix )
52  */
54 {
55 public:
57 
58  /** describes a rectangular render viewport */
59  struct Viewport
60  {
61  GlsInt32 x; /**< x coord of lower left corner in pixels */
62  GlsInt32 y; /**< y coord of lower left corner in pixels */
63  GlsUInt32 width; /**< width of viewport in pixels */
64  GlsUInt32 height; /**< height of viewport in pixels */
65  };
66 
67  /** initialization parameters for a GlsInputManager */
69  {
70  const Viewport viewport; /**< initial GL viewport */
71  const GlsMatrixAffineD::GLMatrixAffineF projMatrix; /**< initial GL projection matrix */
72  const GlsMatrixAffineD::GLMatrixAffineF modelMatrix; /**< initial GL model matrix */
73  GlsDisplayObject &topLevelObject; /**< top level object receiving input */
74 
75  #if defined( GLS_DEBUG )
76  /** Determine if the initialization parameters are valid
77  * \return GLS_TRUE if valid else GLS_FALSE
78  * \pre none
79  * \post none
80  */
81  GlsBool IsValid( void ) const;
82  #endif // GLS_DEBUG
83  };
84 
85  /** Initialize (and create) the singleton GlsInputManager instance. Can only be called once
86  * \param initParameters initialization parameters
87  * \pre singleton must not already exist, initParameters.IsValid()
88  * \post GlsInputManager singleton instance is created and initialized
89  */
90  static void Initialize( InitParameters &initParameters );
91 
92  /** Get the singleton GlsInputManager instance
93  * \return the singleton GlsInputManager instance
94  * \pre singleton instance must exist ( must have called Initialize() )
95  * \post none
96  */
97  static GlsInputManager& GetInputManager( void );
98 
99  /** Handle the given event
100  * \param event event in question
101  * \return GLS_TRUE if event was handled else GLS_FALSE
102  * \pre event.IsValid()
103  * \post event is handled if return value is GLS_TRUE
104  */
105  GlsBool HandleEvent( GlsEvent &event );
106 
107  /** Update the input manager with the current GL viewport. Call if/when
108  * GL viewport changes from initial viewport given to Initialize() call.
109  * \param viewport updated GL viewport
110  * \pre none
111  * \post view port is updated
112  */
113  void UpdateViewport( const Viewport &viewport );
114 
115  /** Update the input manager with the current GL projection matrix. Call if/when
116  * GL projection matrix changes from initial projection matrix given to Initialize() call.
117  * \param projMatrix updated projection matrix
118  * \pre GLMatrixAffineFIsValid( projMatrix )
119  * \post projection matrix is updated
120  */
122 
123  /** Update the input manager with the current top level GL model matrix. Call if/when
124  * top level GL model matrix changes from initial model matrix given to Initialize() call.
125  * \param modelMatrix updated model matrix
126  * \pre GLMatrixAffineFIsValid( modelMatrix )
127  * \post model matrix is updated
128  */
129  void UpdateModelMatrix( const GlsMatrixAffineD::GLMatrixAffineF &modelMatrix );
130 
131  /** Project the given point into screen coordinates using the given GL draw matrix and
132  * the current projection matrix and viewport
133  * \param p point in question
134  * \param drawMatrix GL draw matrix
135  * \param projected [out] receives projected point in screen coordinates
136  * \pre p.IsValid(), GLMatrixAffineFIsValid( drawMatrix )
137  * \post projected contains p projected into screen space
138  */
139  void ProjectPoint( const GlsVector3D &p, const GlsMatrixAffineD::GLMatrixAffineF &drawMatrix,
140  GlsVector2D &projected ) const;
141 
142 protected:
143  Viewport _viewport; /**< current GL display viewport */
144  GlsMatrixAffineD::GLMatrixAffineF _projMatrix; /**< current GL projection matrix */
145  GlsMatrixAffineD::GLMatrixAffineF _modelMatrix; /**< current GL model matrix */
146  GlsDisplayObject &_topLevelObject; /**< top level object receiving input */
147  GlsDisplayObject *_focusObject; /**< current object with focus else GLS_NULL */
148  GlsDisplayObject *_dragObject; /**< current object for dragging else GLS_NULL */
149 
150  GlsBool _invalidatePickCache; /**< GLS_TRUE if pick cache of top level component needs to
151  * be invalidated before the next pick can occur */
152 
153  /** Constructor - create an instance
154  * \param initParameters initialization parameters
155  * \pre initParameters.IsValid()
156  * \post instance created
157  */
158  GlsInputManager( InitParameters &initParameters );
159 
160  /** Destructor - shall never be called
161  * \pre none
162  * \post none
163  */
164  virtual ~GlsInputManager();
165 
166 private:
167  // Disable implicit generated Members
168  GlsInputManager& operator=( const GlsInputManager &rhs );
169  GlsInputManager( const GlsInputManager &src );
170 };
171 
172 #endif // _GLS_INPUT_MANAGER_H
int GlsInt32
Definition: gls_types.h:66
void ProjectPoint(const GlsVector3D &p, const GlsMatrixAffineD::GLMatrixAffineF &drawMatrix, GlsVector2D &projected) const
void UpdateViewport(const Viewport &viewport)
bool GlsBool
Definition: gls_types.h:96
GlsMatrixAffineD::GLMatrixAffineF _modelMatrix
Definition: gls_input_manager.h:145
GlsUInt32 width
Definition: gls_input_manager.h:63
Definition: gls_input_manager.h:59
#define GLS_CLASS_INVARIANT_DECLARATION(ClassName)
Definition: gls_class_invariant.h:80
Definition: gls_vertex.h:65
static void Initialize(InitParameters &initParameters)
GlsDisplayObject & topLevelObject
Definition: gls_input_manager.h:73
GlsInt32 y
Definition: gls_input_manager.h:62
Definition: gls_input_manager.h:53
GlsBool HandleEvent(GlsEvent &event)
This header defines The GlsMatrixAffineD class for use in the GL Studio DO-178B Runtime Library...
Definition: gls_input_manager.h:68
unsigned int GlsUInt32
Definition: gls_types.h:73
GlsBool _invalidatePickCache
Definition: gls_input_manager.h:150
Definition: gls_event.h:52
GlsMatrixAffineD::GLMatrixAffineF _projMatrix
Definition: gls_input_manager.h:144
This header defines the basic types used by the GL Studio DO-178B Runtime Library.
This header defines any preprocessor defines needed to configure the GL Studio DO-178B Runtime Librar...
virtual ~GlsInputManager()
GlsDisplayObject & _topLevelObject
Definition: gls_input_manager.h:146
GLfloat GLMatrixAffineF[DIMENSION *DIMENSION]
Definition: gls_matrix_affine_double.h:63
void UpdateModelMatrix(const GlsMatrixAffineD::GLMatrixAffineF &modelMatrix)
GlsUInt32 height
Definition: gls_input_manager.h:64
GlsDisplayObject * _dragObject
Definition: gls_input_manager.h:148
Definition: gls_display_object.h:64
void UpdateProjectionMatrix(const GlsMatrixAffineD::GLMatrixAffineF &projMatrix)
This header defines a GLS_DEBUG only macro for facilitating evaluating class invariants in the GL Stu...
GlsInt32 x
Definition: gls_input_manager.h:61
GlsDisplayObject * _focusObject
Definition: gls_input_manager.h:147
Definition: gls_vertex.h:49
static GlsInputManager & GetInputManager(void)
This header defines the base class for all graphical objects in the GL Studio DO-178B Runtime Library...
Viewport _viewport
Definition: gls_input_manager.h:143
const Viewport viewport
Definition: gls_input_manager.h:70
const GlsMatrixAffineD::GLMatrixAffineF projMatrix
Definition: gls_input_manager.h:71
const GlsMatrixAffineD::GLMatrixAffineF modelMatrix
Definition: gls_input_manager.h:72
GlsInputManager(InitParameters &initParameters)