Browse Source

display: Generate "touch" events while any touch is active

rdb 4 years ago
parent
commit
ff3fc785bf

+ 0 - 20
panda/src/display/graphicsWindowInputDevice.I

@@ -25,16 +25,6 @@ get_pointer() const {
   }
 }
 
-/**
- * To be called by a particular kind of GraphicsWindow to indicate that the
- * pointer data has changed.
- */
-INLINE void GraphicsWindowInputDevice::
-update_pointer(PointerData data, double time) {
-  LightMutexHolder holder(_lock);
-  InputDevice::update_pointer(std::move(data), time);
-}
-
 /**
  * To be called by a particular kind of GraphicsWindow to indicate that the
  * pointer has moved by the given relative amount.
@@ -44,13 +34,3 @@ pointer_moved(double x, double y, double time) {
   LightMutexHolder holder(_lock);
   InputDevice::pointer_moved(0, x, y, time);
 }
-
-/**
- * To be called by a particular kind of GraphicsWindow to indicate that the
- * pointer no longer exists.
- */
-INLINE void GraphicsWindowInputDevice::
-remove_pointer(int id) {
-  LightMutexHolder holder(_lock);
-  InputDevice::remove_pointer(id);
-}

+ 37 - 0
panda/src/display/graphicsWindowInputDevice.cxx

@@ -199,3 +199,40 @@ set_pointer_out_of_window(double time) {
                                seq, time);
   }
 }
+
+/**
+ * To be called by a particular kind of GraphicsWindow to indicate that the
+ * pointer data has changed.
+ */
+void GraphicsWindowInputDevice::
+update_pointer(PointerData data, double time) {
+  LightMutexHolder holder(_lock);
+  if (data._type == PointerType::touch) {
+    if (data._pressure > 0.0) {
+      if (_touches.empty()) {
+        _button_events->add_event(ButtonEvent(MouseButton::touch(), ButtonEvent::T_down, time));
+        _buttons_held.insert(MouseButton::touch());
+      }
+      _touches.insert(data._id);
+    }
+    else if (_touches.erase(data._id) && _touches.empty()) {
+      _button_events->add_event(ButtonEvent(MouseButton::touch(), ButtonEvent::T_up, time));
+      _buttons_held.erase(MouseButton::touch());
+    }
+  }
+  InputDevice::update_pointer(std::move(data), time);
+}
+
+/**
+ * To be called by a particular kind of GraphicsWindow to indicate that the
+ * pointer no longer exists.
+ */
+void GraphicsWindowInputDevice::
+remove_pointer(int id, double time) {
+  LightMutexHolder holder(_lock);
+  if (_touches.erase(id) && _touches.empty()) {
+    _button_events->add_event(ButtonEvent(MouseButton::touch(), ButtonEvent::T_up, time));
+    _buttons_held.erase(MouseButton::touch());
+  }
+  InputDevice::remove_pointer(id);
+}

+ 3 - 2
panda/src/display/graphicsWindowInputDevice.h

@@ -56,13 +56,14 @@ PUBLISHED:
   INLINE PointerData get_pointer() const;
   void set_pointer_in_window(double x, double y, double time = ClockObject::get_global_clock()->get_frame_time());
   void set_pointer_out_of_window(double time = ClockObject::get_global_clock()->get_frame_time());
-  INLINE void update_pointer(PointerData data, double time = ClockObject::get_global_clock()->get_frame_time());
+  void update_pointer(PointerData data, double time = ClockObject::get_global_clock()->get_frame_time());
   INLINE void pointer_moved(double x, double y, double time = ClockObject::get_global_clock()->get_frame_time());
-  INLINE void remove_pointer(int id);
+  void remove_pointer(int id, double time = ClockObject::get_global_clock()->get_frame_time());
 
 private:
   typedef pset<ButtonHandle> ButtonsHeld;
   ButtonsHeld _buttons_held;
+  pset<int> _touches;
 
 public:
   static TypeHandle get_class_type() {

+ 1 - 1
panda/src/putil/pointerData.h

@@ -25,7 +25,7 @@ BEGIN_PUBLISH
 enum class PointerType {
   unknown,
   mouse,
-  finger,
+  touch,
   stylus,
   eraser,
 };

+ 1 - 1
panda/src/windisplay/winGraphicsWindow.cxx

@@ -2328,7 +2328,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
       for (UINT i = 0; i < _num_touches; ++i) {
         PointerData data;
         data._id = (int)_touches[i].dwID;
-        data._type = PointerType::finger;
+        data._type = PointerType::touch;
         data._xpos = _touches[i].x * 0.01 + offset.x;
         data._ypos = _touches[i].y * 0.01 + offset.y;
 

+ 1 - 1
panda/src/x11display/x11GraphicsWindow.cxx

@@ -473,7 +473,7 @@ process_events() {
           {
             PointerData data;
             data._id = device_event->detail;
-            data._type = PointerType::finger;
+            data._type = PointerType::touch;
             data._xpos = device_event->event_x;
             data._ypos = device_event->event_y;
             data._pressure = 1.0;