File indexing completed on 2026-10-28 09:15:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _Aspect_VKeySet_HeaderFile
0015 #define _Aspect_VKeySet_HeaderFile
0016
0017 #include <Aspect_VKey.hxx>
0018
0019 #include <NCollection_Array1.hxx>
0020 #include <OSD_Timer.hxx>
0021 #include <Standard_Transient.hxx>
0022
0023 #include <shared_mutex>
0024
0025
0026 class Aspect_VKeySet : public Standard_Transient
0027 {
0028 DEFINE_STANDARD_RTTIEXT(Aspect_VKeySet, Standard_Transient)
0029 public:
0030
0031 Standard_EXPORT Aspect_VKeySet();
0032
0033
0034 Aspect_VKeyFlags Modifiers() const
0035 {
0036 std::shared_lock<std::shared_mutex> aLock(myLock);
0037 return myModifiers;
0038 }
0039
0040
0041 double DownTime(Aspect_VKey theKey) const
0042 {
0043 std::shared_lock<std::shared_mutex> aLock(myLock);
0044 return myKeys[theKey].TimeDown;
0045 }
0046
0047
0048 double TimeUp(Aspect_VKey theKey) const
0049 {
0050 std::shared_lock<std::shared_mutex> aLock(myLock);
0051 return myKeys[theKey].TimeUp;
0052 }
0053
0054
0055 bool IsFreeKey(Aspect_VKey theKey) const
0056 {
0057 std::shared_lock<std::shared_mutex> aLock(myLock);
0058 return myKeys[theKey].KStatus == KeyStatus_Free;
0059 }
0060
0061
0062 bool IsKeyDown(Aspect_VKey theKey) const
0063 {
0064 std::shared_lock<std::shared_mutex> aLock(myLock);
0065 return myKeys[theKey].KStatus == KeyStatus_Pressed;
0066 }
0067
0068
0069
0070
0071 std::shared_mutex& Mutex() { return myLock; }
0072
0073 public:
0074
0075 Standard_EXPORT void Reset();
0076
0077
0078
0079
0080 Standard_EXPORT void KeyDown(Aspect_VKey theKey, double theTime, double thePressure = 1.0);
0081
0082
0083
0084
0085 Standard_EXPORT void KeyUp(Aspect_VKey theKey, double theTime);
0086
0087
0088 Standard_EXPORT void KeyFromAxis(Aspect_VKey theNegative,
0089 Aspect_VKey thePositive,
0090 double theTime,
0091 double thePressure);
0092
0093
0094
0095
0096
0097
0098 bool HoldDuration(Aspect_VKey theKey, double theTime, double& theDuration)
0099 {
0100 double aPressure = -1.0;
0101 return HoldDuration(theKey, theTime, theDuration, aPressure);
0102 }
0103
0104
0105
0106
0107
0108
0109
0110 Standard_EXPORT bool HoldDuration(Aspect_VKey theKey,
0111 double theTime,
0112 double& theDuration,
0113 double& thePressure);
0114
0115 private:
0116
0117 void KeyDown_Unlocked(Aspect_VKey theKey, double theTime, double thePressure);
0118
0119
0120 void KeyUp_Unlocked(Aspect_VKey theKey, double theTime);
0121
0122 private:
0123
0124 enum KeyStatus
0125 {
0126 KeyStatus_Free,
0127 KeyStatus_Pressed,
0128 KeyStatus_Released,
0129 };
0130
0131
0132 struct KeyState
0133 {
0134 KeyState()
0135 : TimeDown(0.0),
0136 TimeUp(0.0),
0137 Pressure(1.0),
0138 KStatus(KeyStatus_Free)
0139 {
0140 }
0141
0142 void Reset()
0143 {
0144 KStatus = KeyStatus_Free;
0145 TimeDown = 0.0;
0146 TimeUp = 0.0;
0147 Pressure = 1.0;
0148 }
0149
0150 double TimeDown;
0151 double TimeUp;
0152 double Pressure;
0153 KeyStatus KStatus;
0154 };
0155
0156 private:
0157 NCollection_Array1<KeyState> myKeys;
0158 mutable std::shared_mutex myLock;
0159 Aspect_VKeyFlags myModifiers;
0160 };
0161
0162 #endif