Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright (c) 2021 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_WindowInputListener_HeaderFile
0015 #define _Aspect_WindowInputListener_HeaderFile
0016 
0017 #include <Aspect_VKeySet.hxx>
0018 #include <Aspect_TouchMap.hxx>
0019 #include <Graphic3d_Vec.hxx>
0020 
0021 struct Aspect_ScrollDelta;
0022 class WNT_HIDSpaceMouse;
0023 
0024 //! Defines a listener for window input events.
0025 class Aspect_WindowInputListener
0026 {
0027 public:
0028   ///DEFINE_STANDARD_ALLOC
0029 public:
0030 
0031   //! Destructor.
0032   Standard_EXPORT virtual ~Aspect_WindowInputListener();
0033 
0034   //! Return event time (e.g. current time).
0035   double EventTime() const { return myEventTimer.ElapsedTime(); }
0036 
0037   //! Handle expose event (window content has been invalidation and should be redrawn).
0038   virtual void ProcessExpose() = 0;
0039 
0040   //! Handle window resize event.
0041   virtual void ProcessConfigure (bool theIsResized) = 0;
0042 
0043   //! Handle window input event immediately (flush input buffer or ignore).
0044   virtual void ProcessInput() = 0;
0045 
0046   //! Handle focus event.
0047   virtual void ProcessFocus (bool theIsActivated) = 0;
0048 
0049   //! Handle window close event.
0050   virtual void ProcessClose() = 0;
0051 
0052 public: //! @name keyboard input
0053 
0054   //! Return keyboard state.
0055   const Aspect_VKeySet& Keys() const { return myKeys; }
0056 
0057   //! Return keyboard state.
0058   Aspect_VKeySet& ChangeKeys() { return myKeys; }
0059 
0060   //! Press key.
0061   //! Default implementation updates internal cache.
0062   //! @param theKey key pressed
0063   //! @param theTime event timestamp
0064   Standard_EXPORT virtual void KeyDown (Aspect_VKey theKey,
0065                                         double theTime,
0066                                         double thePressure = 1.0) = 0;
0067 
0068   //! Release key.
0069   //! Default implementation updates internal cache.
0070   //! @param theKey key pressed
0071   //! @param theTime event timestamp
0072   Standard_EXPORT virtual void KeyUp (Aspect_VKey theKey,
0073                                       double theTime) = 0;
0074 
0075   //! Simulate key up/down events from axis value.
0076   //! Default implementation updates internal cache.
0077   Standard_EXPORT virtual void KeyFromAxis (Aspect_VKey theNegative,
0078                                             Aspect_VKey thePositive,
0079                                             double theTime,
0080                                             double thePressure) = 0;
0081 
0082 public: //! @name mouse input
0083 
0084   //! Update mouse scroll event.
0085   //! This method is expected to be called from UI thread.
0086   //! @param theDelta mouse cursor position and delta
0087   //! @return TRUE if new event has been created or FALSE if existing one has been updated
0088   virtual bool UpdateMouseScroll (const Aspect_ScrollDelta& theDelta) = 0;
0089 
0090   //! Handle mouse button press/release event.
0091   //! This method is expected to be called from UI thread.
0092   //! @param thePoint      mouse cursor position
0093   //! @param theButtons    pressed buttons
0094   //! @param theModifiers  key modifiers
0095   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
0096   //!                      but emulated from non-precise input like touch on screen
0097   //! @return TRUE if window content should be redrawn
0098   virtual bool UpdateMouseButtons (const Graphic3d_Vec2i& thePoint,
0099                                    Aspect_VKeyMouse theButtons,
0100                                    Aspect_VKeyFlags theModifiers,
0101                                    bool theIsEmulated) = 0;
0102 
0103   //! Handle mouse cursor movement event.
0104   //! This method is expected to be called from UI thread.
0105   //! Default implementation does nothing.
0106   //! @param thePoint      mouse cursor position
0107   //! @param theButtons    pressed buttons
0108   //! @param theModifiers  key modifiers
0109   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
0110   //!                      but emulated from non-precise input like touch on screen
0111   //! @return TRUE if window content should be redrawn
0112   virtual bool UpdateMousePosition (const Graphic3d_Vec2i& thePoint,
0113                                     Aspect_VKeyMouse theButtons,
0114                                     Aspect_VKeyFlags theModifiers,
0115                                     bool theIsEmulated) = 0;
0116 
0117   //! Handle mouse button press event.
0118   //! This method is expected to be called from UI thread.
0119   //! Default implementation redirects to UpdateMousePosition().
0120   //! @param thePoint      mouse cursor position
0121   //! @param theButton     pressed button
0122   //! @param theModifiers  key modifiers
0123   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
0124   //!                      but emulated from non-precise input like touch on screen
0125   //! @return TRUE if window content should be redrawn
0126   bool PressMouseButton (const Graphic3d_Vec2i& thePoint,
0127                          Aspect_VKeyMouse theButton,
0128                          Aspect_VKeyFlags theModifiers,
0129                          bool theIsEmulated)
0130   {
0131     return UpdateMouseButtons (thePoint, myMousePressed | theButton, theModifiers, theIsEmulated);
0132   }
0133 
0134   //! Handle mouse button release event.
0135   //! This method is expected to be called from UI thread.
0136   //! Default implementation redirects to UpdateMousePosition().
0137   //! @param thePoint      mouse cursor position
0138   //! @param theButton     released button
0139   //! @param theModifiers  key modifiers
0140   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
0141   //!                      but emulated from non-precise input like touch on screen
0142   //! @return TRUE if window content should be redrawn
0143   bool ReleaseMouseButton (const Graphic3d_Vec2i& thePoint,
0144                            Aspect_VKeyMouse theButton,
0145                            Aspect_VKeyFlags theModifiers,
0146                            bool theIsEmulated)
0147   {
0148     Aspect_VKeyMouse aButtons = myMousePressed & (~theButton);
0149     return UpdateMouseButtons (thePoint, aButtons, theModifiers, theIsEmulated);
0150   }
0151 
0152   //! Return currently pressed mouse buttons.
0153   Aspect_VKeyMouse PressedMouseButtons() const { return myMousePressed; }
0154 
0155   //! Return active key modifiers passed with last mouse event.
0156   Aspect_VKeyFlags LastMouseFlags() const { return myMouseModifiers; }
0157 
0158   //! Return last mouse position.
0159   const Graphic3d_Vec2i& LastMousePosition() const { return myMousePositionLast; }
0160 
0161 public: //! @name multi-touch input
0162 
0163   //! Return TRUE if touches map is not empty.
0164   bool HasTouchPoints() const { return !myTouchPoints.IsEmpty(); }
0165 
0166   //! Return map of active touches.
0167   const Aspect_TouchMap& TouchPoints() const { return myTouchPoints; }
0168 
0169   //! Add touch point with the given ID.
0170   //! This method is expected to be called from UI thread.
0171   //! @param theId touch unique identifier
0172   //! @param thePnt touch coordinates
0173   //! @param theClearBefore if TRUE previously registered touches will be removed
0174   Standard_EXPORT virtual void AddTouchPoint (Standard_Size theId,
0175                                               const Graphic3d_Vec2d& thePnt,
0176                                               Standard_Boolean theClearBefore = false);
0177 
0178   //! Remove touch point with the given ID.
0179   //! This method is expected to be called from UI thread.
0180   //! @param theId touch unique identifier
0181   //! @param theClearSelectPnts if TRUE will initiate clearing of selection points
0182   //! @return TRUE if point has been removed
0183   Standard_EXPORT virtual bool RemoveTouchPoint (Standard_Size theId,
0184                                                  Standard_Boolean theClearSelectPnts = false);
0185 
0186   //! Update touch point with the given ID.
0187   //! If point with specified ID was not registered before, it will be added.
0188   //! This method is expected to be called from UI thread.
0189   //! @param theId touch unique identifier
0190   //! @param thePnt touch coordinates
0191   Standard_EXPORT virtual void UpdateTouchPoint (Standard_Size theId,
0192                                                  const Graphic3d_Vec2d& thePnt);
0193 
0194 public: //! @name 3d mouse input
0195 
0196   //! Return acceleration ratio for translation event; 2.0 by default.
0197   float Get3dMouseTranslationScale() const { return my3dMouseAccelTrans; }
0198 
0199   //! Set acceleration ratio for translation event.
0200   void Set3dMouseTranslationScale (float theScale) { my3dMouseAccelTrans = theScale; }
0201 
0202   //! Return acceleration ratio for rotation event; 4.0 by default.
0203   float Get3dMouseRotationScale() const { return my3dMouseAccelRotate; }
0204 
0205   //! Set acceleration ratio for rotation event.
0206   void Set3dMouseRotationScale (float theScale) { my3dMouseAccelRotate = theScale; }
0207 
0208   //! Return quadric acceleration flag; TRUE by default.
0209   bool To3dMousePreciseInput() const { return my3dMouseIsQuadric; }
0210 
0211   //! Set quadric acceleration flag.
0212   void Set3dMousePreciseInput (bool theIsQuadric) { my3dMouseIsQuadric = theIsQuadric; }
0213 
0214   //! Return 3d mouse rotation axes (tilt/roll/spin) ignore flag; (FALSE, FALSE, FALSE) by default.
0215   const NCollection_Vec3<bool>& Get3dMouseIsNoRotate() const { return my3dMouseNoRotate; }
0216 
0217   //! Return 3d mouse rotation axes (tilt/roll/spin) ignore flag; (FALSE, FALSE, FALSE) by default.
0218   NCollection_Vec3<bool>& Change3dMouseIsNoRotate() { return my3dMouseNoRotate; }
0219 
0220   //! Return 3d mouse rotation axes (tilt/roll/spin) reverse flag; (TRUE, FALSE, FALSE) by default.
0221   const NCollection_Vec3<bool>& Get3dMouseToReverse() const { return my3dMouseToReverse; }
0222 
0223   //! Return 3d mouse rotation axes (tilt/roll/spin) reverse flag; (TRUE, FALSE, FALSE) by default.
0224   NCollection_Vec3<bool>& Change3dMouseToReverse() { return my3dMouseToReverse; }
0225 
0226   //! Process 3d mouse input event (redirects to translation, rotation and keys).
0227   virtual bool Update3dMouse (const WNT_HIDSpaceMouse& theEvent) = 0;
0228 
0229   //! Process 3d mouse input translation event.
0230   Standard_EXPORT virtual bool update3dMouseTranslation (const WNT_HIDSpaceMouse& theEvent);
0231 
0232   //! Process 3d mouse input rotation event.
0233   Standard_EXPORT virtual bool update3dMouseRotation (const WNT_HIDSpaceMouse& theEvent);
0234 
0235   //! Process 3d mouse input keys event.
0236   Standard_EXPORT virtual bool update3dMouseKeys (const WNT_HIDSpaceMouse& theEvent);
0237 
0238 protected:
0239 
0240   //! Empty constructor.
0241   Standard_EXPORT Aspect_WindowInputListener();
0242 
0243 protected:
0244 
0245   OSD_Timer        myEventTimer;        //!< timer for timestamping events
0246 
0247 protected: //! @name keyboard input variables
0248 
0249   Aspect_VKeySet   myKeys;              //!< keyboard state
0250 
0251 protected: //! @name mouse input variables
0252 
0253   Graphic3d_Vec2i  myMousePositionLast; //!< last mouse position
0254   Aspect_VKeyMouse myMousePressed;      //!< active mouse buttons
0255   Aspect_VKeyFlags myMouseModifiers;    //!< active key modifiers passed with last mouse event
0256 
0257 protected:
0258 
0259   Aspect_TouchMap  myTouchPoints;       //!< map of active touches
0260 
0261 protected: //! @name 3d mouse input variables
0262 
0263   bool                   my3dMouseButtonState[32];//!< cached button state
0264   NCollection_Vec3<bool> my3dMouseNoRotate;       //!< ignore  3d mouse rotation axes
0265   NCollection_Vec3<bool> my3dMouseToReverse;      //!< reverse 3d mouse rotation axes
0266   float                  my3dMouseAccelTrans;     //!< acceleration ratio for translation event
0267   float                  my3dMouseAccelRotate;    //!< acceleration ratio for rotation event
0268   bool                   my3dMouseIsQuadric;      //!< quadric acceleration
0269 
0270 };
0271 
0272 #endif // _Aspect_WindowInputListener_HeaderFile