1 // This file is part of VSTGUI. It is subject to the license terms 2 // in the LICENSE file found in the top-level directory of this 3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE 4 5 #ifndef __itouchevent__ 6 #define __itouchevent__ 7 8 #include "vstguifwd.h" 9 #include "cpoint.h" 10 11 #if VSTGUI_TOUCH_EVENT_HANDLING 12 13 #include <map> 14 15 namespace VSTGUI { 16 17 //----------------------------------------------------------------------------- 18 //! @brief a touch event 19 /// @ingroup new_in_4_2 20 //----------------------------------------------------------------------------- 21 class ITouchEvent 22 { 23 public: 24 enum TouchState { 25 kBegan, 26 kMoved, 27 kEnded, 28 kNoChange, 29 kCanceled, 30 kUndefined 31 }; 32 struct Touch { 33 double timeStamp; 34 TouchState state; 35 CPoint location; 36 CView* target; 37 bool targetIsSingleTouch; 38 uint32_t tapCount; 39 TouchTouch40 Touch () : timeStamp (0), state (kUndefined), target (0), targetIsSingleTouch (false), tapCount (0) {} 41 }; 42 using TouchPair = std::pair<int32_t, ITouchEvent::Touch>; 43 using TouchMap = std::map<int32_t, Touch>; 44 numTouches()45 int32_t numTouches () const { return static_cast<int32_t> (touches.size ()); } 46 begin()47 TouchMap::const_iterator begin () const { return touches.begin (); } end()48 TouchMap::const_iterator end () const { return touches.end (); } 49 find(int32_t identifier)50 const Touch* find (int32_t identifier) const 51 { 52 TouchMap::const_iterator it = touches.find (identifier); 53 if (it != touches.end ()) 54 return &(it->second); 55 return 0; 56 } 57 setTouchTarget(int32_t identifier,CView * view,bool targetIsSingleTouch)58 bool setTouchTarget (int32_t identifier, CView* view, bool targetIsSingleTouch) 59 { 60 TouchMap::iterator it = touches.find (identifier); 61 if (it != touches.end () && it->second.target == 0) 62 { 63 it->second.target = view; 64 it->second.targetIsSingleTouch = targetIsSingleTouch; 65 return true; 66 } 67 return false; 68 } 69 unsetTouchTarget(int32_t identifier,CView * view)70 bool unsetTouchTarget (int32_t identifier, CView* view) 71 { 72 TouchMap::iterator it = touches.find (identifier); 73 if (it != touches.end () && it->second.target == view) 74 { 75 it->second.target = nullptr; 76 return true; 77 } 78 return false; 79 } 80 81 virtual double getTimeStamp () const = 0; 82 protected: ITouchEvent()83 ITouchEvent () {} 84 virtual ~ITouchEvent () noexcept = default; 85 86 TouchMap touches; 87 }; 88 89 } // namespace 90 91 #endif // VSTGUI_TOUCH_EVENT_HANDLING 92 93 #endif // __itouchevent__ 94