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