Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:59

0001 // Copyright (c) 2016-2019 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
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_Mutex.hxx>
0022 #include <Standard_Transient.hxx>
0023 
0024 //! Structure defining key state.
0025 class Aspect_VKeySet : public Standard_Transient
0026 {
0027   DEFINE_STANDARD_RTTIEXT(Aspect_VKeySet, Standard_Transient)
0028 public:
0029 
0030   //! Main constructor.
0031   Standard_EXPORT Aspect_VKeySet();
0032 
0033   //! Return active modifiers.
0034   Aspect_VKeyFlags Modifiers() const
0035   {
0036     Standard_Mutex::Sentry aLock (myLock);
0037     return myModifiers;
0038   }
0039 
0040   //! Return timestamp of press event.
0041   double DownTime (Aspect_VKey theKey) const
0042   {
0043     Standard_Mutex::Sentry aLock (myLock);
0044     return myKeys[theKey].TimeDown;
0045   }
0046 
0047   //! Return timestamp of release event.
0048   double TimeUp (Aspect_VKey theKey) const
0049   {
0050     Standard_Mutex::Sentry aLock (myLock);
0051     return myKeys[theKey].TimeUp;
0052   }
0053 
0054   //! Return TRUE if key is in Free state.
0055   bool IsFreeKey (Aspect_VKey theKey) const
0056   {
0057     Standard_Mutex::Sentry aLock (myLock);
0058     return myKeys[theKey].KStatus == KeyStatus_Free;
0059   }
0060 
0061   //! Return TRUE if key is in Pressed state.
0062   bool IsKeyDown (Aspect_VKey theKey) const
0063   {
0064     Standard_Mutex::Sentry aLock (myLock);
0065     return myKeys[theKey].KStatus == KeyStatus_Pressed;
0066   }
0067 
0068   //! Return mutex for thread-safe updates.
0069   //! All operations in class implicitly locks this mutex,
0070   //! so this method could be used only for batch processing of keys.
0071   Standard_Mutex& Mutex() { return myLock; }
0072 
0073 public:
0074 
0075   //! Reset the key state into unpressed state.
0076   Standard_EXPORT void Reset();
0077 
0078   //! Press key.
0079   //! @param theKey key pressed
0080   //! @param theTime event timestamp
0081   Standard_EXPORT void KeyDown (Aspect_VKey theKey,
0082                                 double theTime,
0083                                 double thePressure = 1.0);
0084 
0085   //! Release key.
0086   //! @param theKey key pressed
0087   //! @param theTime event timestamp
0088   Standard_EXPORT void KeyUp (Aspect_VKey theKey,
0089                               double theTime);
0090 
0091   //! Simulate key up/down events from axis value.
0092   Standard_EXPORT void KeyFromAxis (Aspect_VKey theNegative,
0093                                     Aspect_VKey thePositive,
0094                                     double theTime,
0095                                     double thePressure);
0096 
0097   //! Return duration of the button in pressed state.
0098   //! @param theKey      key to check
0099   //! @param theTime     current time (for computing duration from key down time)
0100   //! @param theDuration key press duration
0101   //! @return TRUE if key was in pressed state
0102   bool HoldDuration (Aspect_VKey theKey,
0103                      double theTime,
0104                      double& theDuration)
0105   {
0106     double aPressure = -1.0;
0107     return HoldDuration (theKey, theTime, theDuration, aPressure);
0108   }
0109 
0110   //! Return duration of the button in pressed state.
0111   //! @param theKey      key to check
0112   //! @param theTime     current time (for computing duration from key down time)
0113   //! @param theDuration key press duration
0114   //! @param thePressure key pressure
0115   //! @return TRUE if key was in pressed state
0116   Standard_EXPORT bool HoldDuration (Aspect_VKey theKey,
0117                                      double theTime,
0118                                      double& theDuration,
0119                                      double& thePressure);
0120 
0121 private:
0122 
0123   //! Key state.
0124   enum KeyStatus
0125   {
0126     KeyStatus_Free,     //!< free status
0127     KeyStatus_Pressed,  //!< key is in pressed state
0128     KeyStatus_Released, //!< key has been just released (transient state before KeyStatus_Free)
0129   };
0130 
0131   //! Structure defining key state.
0132   struct KeyState
0133   {
0134     KeyState() : TimeDown (0.0), TimeUp (0.0), Pressure (1.0), KStatus (KeyStatus_Free) {}
0135     void Reset()
0136     {
0137       KStatus = KeyStatus_Free;
0138       TimeDown = 0.0;
0139       TimeUp   = 0.0;
0140       Pressure = 1.0;
0141     }
0142 
0143     double    TimeDown; //!< time of key press   event
0144     double    TimeUp;   //!< time of key release event
0145     double    Pressure; //!< key pressure
0146     KeyStatus KStatus;  //!< key status
0147   };
0148 
0149 private:
0150 
0151   NCollection_Array1<KeyState> myKeys;      //!< keys state
0152   mutable Standard_Mutex       myLock;      //!< mutex for thread-safe updates
0153   Aspect_VKeyFlags             myModifiers; //!< active modifiers
0154 
0155 };
0156 
0157 #endif // _Aspect_VKeySet_HeaderFile