1 // Copyright (c) 2016-2019 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Aspect_VKeySet_HeaderFile
15 #define _Aspect_VKeySet_HeaderFile
17 #include <Aspect_VKey.hxx>
19 #include <NCollection_Array1.hxx>
20 #include <OSD_Timer.hxx>
21 #include <Standard_Mutex.hxx>
22 #include <Standard_Transient.hxx>
24 //! Structure defining key state.
25 class Aspect_VKeySet : public Standard_Transient
27 DEFINE_STANDARD_RTTIEXT(Aspect_VKeySet, Standard_Transient)
31 Standard_EXPORT Aspect_VKeySet();
33 //! Return active modifiers.
34 Aspect_VKeyFlags Modifiers() const
36 Standard_Mutex::Sentry aLock (myLock);
40 //! Return timestamp of press event.
41 double DownTime (Aspect_VKey theKey) const
43 Standard_Mutex::Sentry aLock (myLock);
44 return myKeys[theKey].TimeDown;
47 //! Return timestamp of release event.
48 double TimeUp (Aspect_VKey theKey) const
50 Standard_Mutex::Sentry aLock (myLock);
51 return myKeys[theKey].TimeUp;
54 //! Return TRUE if key is in Free state.
55 bool IsFreeKey (Aspect_VKey theKey) const
57 Standard_Mutex::Sentry aLock (myLock);
58 return myKeys[theKey].Status == KeyStatus_Free;
61 //! Return TRUE if key is in Pressed state.
62 bool IsKeyDown (Aspect_VKey theKey) const
64 Standard_Mutex::Sentry aLock (myLock);
65 return myKeys[theKey].Status == KeyStatus_Pressed;
68 //! Return mutex for thread-safe updates.
69 //! All operations in class implicitly locks this mutex,
70 //! so this method could be used only for batch processing of keys.
71 Standard_Mutex& Mutex() { return myLock; }
75 //! Reset the key state into unpressed state.
76 Standard_EXPORT void Reset();
79 //! @param theKey key pressed
80 //! @param theTime event timestamp
81 Standard_EXPORT void KeyDown (Aspect_VKey theKey,
83 double thePressure = 1.0);
86 //! @param theKey key pressed
87 //! @param theTime event timestamp
88 Standard_EXPORT void KeyUp (Aspect_VKey theKey,
91 //! Simulate key up/down events from axis value.
92 Standard_EXPORT void KeyFromAxis (Aspect_VKey theNegative,
93 Aspect_VKey thePositive,
97 //! Return duration of the button in pressed state.
98 //! @param theKey key to check
99 //! @param theTime current time (for computing duration from key down time)
100 //! @param theDuration key press duration
101 //! @return TRUE if key was in pressed state
102 bool HoldDuration (Aspect_VKey theKey,
106 double aPressure = -1.0;
107 return HoldDuration (theKey, theTime, theDuration, aPressure);
110 //! Return duration of the button in pressed state.
111 //! @param theKey key to check
112 //! @param theTime current time (for computing duration from key down time)
113 //! @param theDuration key press duration
114 //! @param thePressure key pressure
115 //! @return TRUE if key was in pressed state
116 Standard_EXPORT bool HoldDuration (Aspect_VKey theKey,
119 double& thePressure);
126 KeyStatus_Free, //!< free status
127 KeyStatus_Pressed, //!< key is in pressed state
128 KeyStatus_Released, //!< key has been just released (transient state before KeyStatus_Free)
131 //! Structure defining key state.
134 KeyState() : TimeDown (0.0), TimeUp (0.0), Pressure (1.0), Status (KeyStatus_Free) {}
137 Status = KeyStatus_Free;
143 double TimeDown; //!< time of key press event
144 double TimeUp; //!< time of key release event
145 double Pressure; //!< key pressure
146 KeyStatus Status; //!< key status
151 NCollection_Array1<KeyState> myKeys; //!< keys state
152 mutable Standard_Mutex myLock; //!< mutex for thread-safe updates
153 Aspect_VKeyFlags myModifiers; //!< active modifiers
157 #endif // _Aspect_VKeySet_HeaderFile