瀏覽代碼

multitouch: Add pointer state information to PointerData, to be used in lieu of a dedicated mouse button for touch events.

Donny Lawrence 6 年之前
父節點
當前提交
b724cfc709

+ 2 - 2
direct/src/gui/DirectButton.py

@@ -101,11 +101,11 @@ class DirectButton(DirectFrame):
 
 
         # Tapping with the finger
         # Tapping with the finger
         if DGG.TOUCH in self['commandButtons']:
         if DGG.TOUCH in self['commandButtons']:
-            self.guiItem.addClickButton(MouseButton.touch())
+            # self.guiItem.addClickButton(MouseButton.touch())
             self.bind(DGG.TOUCHCLICK, self.commandFunc)
             self.bind(DGG.TOUCHCLICK, self.commandFunc)
         else:
         else:
             self.unbind(DGG.TOUCHCLICK)
             self.unbind(DGG.TOUCHCLICK)
-            self.guiItem.removeClickButton(MouseButton.touch())
+            # self.guiItem.removeClickButton(MouseButton.touch())
 
 
     def commandFunc(self, event):
     def commandFunc(self, event):
         if self['command']:
         if self['command']:

+ 3 - 3
direct/src/gui/DirectGuiGlobals.py

@@ -64,15 +64,15 @@ WITHOUT = PGButton.getWithoutPrefix()
 B1CLICK = PGButton.getClickPrefix() + MouseButton.one().getName() + '-'
 B1CLICK = PGButton.getClickPrefix() + MouseButton.one().getName() + '-'
 B2CLICK = PGButton.getClickPrefix() + MouseButton.two().getName() + '-'
 B2CLICK = PGButton.getClickPrefix() + MouseButton.two().getName() + '-'
 B3CLICK = PGButton.getClickPrefix() + MouseButton.three().getName() + '-'
 B3CLICK = PGButton.getClickPrefix() + MouseButton.three().getName() + '-'
-TOUCHCLICK = PGButton.getClickPrefix() + MouseButton.touch().getName() + '-'
+TOUCHCLICK = PGButton.getClickPrefix() + 'touch-'
 B1PRESS = PGButton.getPressPrefix() + MouseButton.one().getName() + '-'
 B1PRESS = PGButton.getPressPrefix() + MouseButton.one().getName() + '-'
 B2PRESS = PGButton.getPressPrefix() + MouseButton.two().getName() + '-'
 B2PRESS = PGButton.getPressPrefix() + MouseButton.two().getName() + '-'
 B3PRESS = PGButton.getPressPrefix() + MouseButton.three().getName() + '-'
 B3PRESS = PGButton.getPressPrefix() + MouseButton.three().getName() + '-'
-TOUCHPRESS = PGButton.getPressPrefix() + MouseButton.touch().getName() + '-'
+TOUCHPRESS = PGButton.getPressPrefix() + 'touch-'
 B1RELEASE = PGButton.getReleasePrefix() + MouseButton.one().getName() + '-'
 B1RELEASE = PGButton.getReleasePrefix() + MouseButton.one().getName() + '-'
 B2RELEASE = PGButton.getReleasePrefix() + MouseButton.two().getName() + '-'
 B2RELEASE = PGButton.getReleasePrefix() + MouseButton.two().getName() + '-'
 B3RELEASE = PGButton.getReleasePrefix() + MouseButton.three().getName() + '-'
 B3RELEASE = PGButton.getReleasePrefix() + MouseButton.three().getName() + '-'
-TOUCHRELEASE = PGButton.getPressPrefix() + MouseButton.touch().getName() + '-'
+TOUCHRELEASE = PGButton.getReleasePrefix() + 'touch-'
 # For DirectEntry widgets
 # For DirectEntry widgets
 OVERFLOW = PGEntry.getOverflowPrefix()
 OVERFLOW = PGEntry.getOverflowPrefix()
 ACCEPT = PGEntry.getAcceptPrefix() + KeyboardButton.enter().getName() + '-'
 ACCEPT = PGEntry.getAcceptPrefix() + KeyboardButton.enter().getName() + '-'

+ 2 - 2
panda/src/cocoadisplay/cocoaGraphicsWindow.mm

@@ -998,7 +998,7 @@ set_properties_now(WindowProperties &properties) {
 
 
   if (properties.has_cursor_hidden()) {
   if (properties.has_cursor_hidden()) {
     if (properties.get_cursor_hidden() != _properties.get_cursor_hidden()) {
     if (properties.get_cursor_hidden() != _properties.get_cursor_hidden()) {
-      if (properties.get_cursor_hidden() && _input->get_pointer().get_in_window()) {
+      if (properties.get_cursor_hidden() && _input->get_pointer_in_window()) {
         [NSCursor hide];
         [NSCursor hide];
         _mouse_hidden = true;
         _mouse_hidden = true;
       } else if (_mouse_hidden) {
       } else if (_mouse_hidden) {
@@ -1731,7 +1731,7 @@ handle_mouse_moved_event(bool in_window, double x, double y, bool absolute) {
 
 
   if (absolute) {
   if (absolute) {
     if (cocoadisplay_cat.is_spam()) {
     if (cocoadisplay_cat.is_spam()) {
-      if (in_window != _input->get_pointer().get_in_window()) {
+      if (in_window != _input->get_pointer_in_window()) {
         if (in_window) {
         if (in_window) {
           cocoadisplay_cat.spam() << "Mouse pointer entered window\n";
           cocoadisplay_cat.spam() << "Mouse pointer entered window\n";
         } else {
         } else {

+ 23 - 17
panda/src/device/inputDevice.cxx

@@ -158,6 +158,16 @@ get_pointer(int id) {
   }
   }
 }
 }
 
 
+/**
+ * Add an event that will eventually be sent down the data graph.
+ */
+void InputDevice::
+throw_event(const PointerData &data) {
+  if (_enable_pointer_events) {
+    double time = ClockObject::get_global_clock()->get_frame_time();
+    _pointer_events->add_event(data, time);
+  }
+}
 
 
 /**
 /**
  * Records that a new pointer was found.
  * Records that a new pointer was found.
@@ -177,33 +187,29 @@ add_pointer(PointerType type, int id, bool primary) {
 }
 }
 
 
 /**
 /**
- * Removes a previously added pointer.  If the current pressure is not zero,
- * it will generate an event doing so.
+ * Updates a pointer. Use this instead of PointerData::update if you want to
+ * throw an event.
  */
  */
 void InputDevice::
 void InputDevice::
-remove_pointer(int id) {
-  assert(_lock.debug_is_locked());
-
+update_pointer(int id, double x, double y, double pressure, PointerPhase phase) {
   PointerData &pointer = _pointers.at(id);
   PointerData &pointer = _pointers.at(id);
-  if (pointer.get_pressure() != 0.0) {
-    pointer.set_pressure(0.0);
-    if (_enable_pointer_events) {
-      double time = ClockObject::get_global_clock()->get_frame_time();
-      _pointer_events->add_event(pointer, time);
-    }
-  }
+
+  pointer.update(x, y, pressure, phase);
+  throw_event(pointer);
 }
 }
 
 
+/**
+ * Removes a previously added pointer.  If the current pressure is not zero,
+ * it will generate an event doing so.
+ */
 void InputDevice::
 void InputDevice::
-pointer_moved_absolute(int id, double x, double y, double pressure, double time) {
+remove_pointer(int id) {
   assert(_lock.debug_is_locked());
   assert(_lock.debug_is_locked());
 
 
   PointerData &pointer = _pointers.at(id);
   PointerData &pointer = _pointers.at(id);
-  pointer.update(x, y, pressure);
+  pointer.set_pressure(0.0);
 
 
-  if (_enable_pointer_events) {
-    _pointer_events->add_event(pointer, time);
-  }
+  throw_event(pointer);
 }
 }
 
 
 /**
 /**

+ 2 - 1
panda/src/device/inputDevice.h

@@ -288,9 +288,10 @@ protected:
 
 
   PointerData& add_pointer(PointerType type, int id, bool primary = false);
   PointerData& add_pointer(PointerType type, int id, bool primary = false);
   void remove_pointer(int id);
   void remove_pointer(int id);
+  void update_pointer(int id, double x, double y, double pressure, PointerPhase phase);
+  void throw_event(const PointerData &data);
 
 
   void pointer_moved(int id, double x, double y, double time);
   void pointer_moved(int id, double x, double y, double time);
-  void pointer_moved_absolute(int id, double x, double y, double pressure, double time);
 
 
   void button_changed(int index, bool down);
   void button_changed(int index, bool down);
   void axis_changed(int index, int value);
   void axis_changed(int index, int value);

+ 12 - 6
panda/src/display/graphicsWindowInputDevice.I

@@ -56,12 +56,6 @@ pointer_moved(int id, double x, double y, double time) {
   InputDevice::pointer_moved(id, x, y, time);
   InputDevice::pointer_moved(id, x, y, time);
 }
 }
 
 
-INLINE void GraphicsWindowInputDevice::
-pointer_moved_absolute(int id, double x, double y, double pressure, double time) {
-  LightMutexHolder holder(_lock);
-  InputDevice::pointer_moved_absolute(id, x, y, pressure, time);
-}
-
 /**
 /**
  * To be called by a particular kind of GraphicsWindow to indicate that the
  * To be called by a particular kind of GraphicsWindow to indicate that the
  * pointer no longer exists.
  * pointer no longer exists.
@@ -71,3 +65,15 @@ remove_pointer(int id) {
   LightMutexHolder holder(_lock);
   LightMutexHolder holder(_lock);
   InputDevice::remove_pointer(id);
   InputDevice::remove_pointer(id);
 }
 }
+
+INLINE void GraphicsWindowInputDevice::
+update_pointer(int id, double x, double y, double pressure, PointerPhase phase) {
+  LightMutexHolder holder(_lock);
+  InputDevice::update_pointer(id, x, y, pressure, phase);
+}
+
+INLINE bool GraphicsWindowInputDevice::
+get_pointer_in_window() {
+  LightMutexHolder holder(_lock);
+  return _pointers.find(0) != _pointers.end();
+}

+ 29 - 19
panda/src/display/graphicsWindowInputDevice.cxx

@@ -34,7 +34,6 @@ GraphicsWindowInputDevice(GraphicsWindow *host, const string &name, bool pointer
 {
 {
   if (pointer) {
   if (pointer) {
     enable_feature(Feature::pointer);
     enable_feature(Feature::pointer);
-    add_pointer(PointerType::mouse, 0, true);
   }
   }
   if (keyboard) {
   if (keyboard) {
     enable_feature(Feature::keyboard);
     enable_feature(Feature::keyboard);
@@ -76,6 +75,11 @@ button_down(ButtonHandle button, double time) {
   LightMutexHolder holder(_lock);
   LightMutexHolder holder(_lock);
   _button_events->add_event(ButtonEvent(button, ButtonEvent::T_down, time));
   _button_events->add_event(ButtonEvent(button, ButtonEvent::T_down, time));
   _buttons_held.insert(button);
   _buttons_held.insert(button);
+
+  PointerData &data = InputDevice::get_pointer(0);
+  if (button == MouseButton::one() && data.get_type() == PointerType::mouse) {
+    data.set_phase(PointerPhase::began);
+  }
 }
 }
 
 
 /**
 /**
@@ -98,6 +102,11 @@ button_up(ButtonHandle button, double time) {
   LightMutexHolder holder(_lock);
   LightMutexHolder holder(_lock);
   _button_events->add_event(ButtonEvent(button, ButtonEvent::T_up, time));
   _button_events->add_event(ButtonEvent(button, ButtonEvent::T_up, time));
   _buttons_held.erase(button);
   _buttons_held.erase(button);
+
+  PointerData &data = InputDevice::get_pointer(0);
+  if (button == MouseButton::one() && data.get_type() == PointerType::mouse) {
+    data.set_phase(PointerPhase::ended);
+  }
 }
 }
 
 
 /**
 /**
@@ -161,22 +170,35 @@ raw_button_up(ButtonHandle button, double time) {
 /**
 /**
  * To be called by a particular kind of GraphicsWindow to indicate that the
  * To be called by a particular kind of GraphicsWindow to indicate that the
  * pointer is within the window, at the given pixel coordinates.
  * pointer is within the window, at the given pixel coordinates.
+ *
+ * @deprecated Only used for existing mouse support, use add_pointer() and
+ *             PointerData::update instead.
  */
  */
 void GraphicsWindowInputDevice::
 void GraphicsWindowInputDevice::
 set_pointer_in_window(double x, double y, double time) {
 set_pointer_in_window(double x, double y, double time) {
   LightMutexHolder holder(_lock);
   LightMutexHolder holder(_lock);
 
 
-  PointerData &pointer = _pointers.size() == 0
-                         ? InputDevice::add_pointer(PointerType::mouse, 0, true)
-                         : InputDevice::get_pointer(0);
+  double pressure = 0.0;
+  PointerPhase phase = PointerPhase::hover;
+
+  if (_pointers.find(0) == _pointers.end()) {
+    _pointers[0] = PointerData::make_primary_mouse();
+  } else {
+    if (_buttons_held.find(MouseButton::one()) != _buttons_held.end()) {
+      pressure = 1.0;
+      phase = PointerPhase::moved;
+    }
+  }
 
 
-  pointer.update(x, y, 1.0);
-  pointer.set_in_window(true);
+  InputDevice::update_pointer(_pointers[0].get_id(), x, y, pressure, phase);
 }
 }
 
 
 /**
 /**
  * To be called by a particular kind of GraphicsWindow to indicate that the
  * To be called by a particular kind of GraphicsWindow to indicate that the
  * pointer is no longer within the window.
  * pointer is no longer within the window.
+ *
+ * @deprecated Only used for existing mouse support, use remove_pointer()
+ *             instead.
  */
  */
 void GraphicsWindowInputDevice::
 void GraphicsWindowInputDevice::
 set_pointer_out_of_window(double time) {
 set_pointer_out_of_window(double time) {
@@ -185,17 +207,5 @@ set_pointer_out_of_window(double time) {
     return;
     return;
   }
   }
 
 
-  PointerData &pointer = InputDevice::get_pointer(0);
-
-  pointer.set_pressure(0.0);
-  pointer.set_in_window(false);
-
-  if (_enable_pointer_events) {
-    int seq = _event_sequence++;
-    if (_pointer_events.is_null()) {
-      _pointer_events = new PointerEventList();
-    }
-
-    _pointer_events->add_event(pointer);
-  }
+  InputDevice::remove_pointer(0);
 }
 }

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

@@ -61,9 +61,11 @@ PUBLISHED:
   INLINE PointerData& add_pointer(PointerType type, int id, bool primary = false);
   INLINE PointerData& add_pointer(PointerType type, int id, bool primary = false);
   INLINE void pointer_moved(double x, double y, 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 pointer_moved(int id, double x, double y, double time = ClockObject::get_global_clock()->get_frame_time());
   INLINE void pointer_moved(int id, double x, double y, double time = ClockObject::get_global_clock()->get_frame_time());
-  INLINE void pointer_moved_absolute(int id, double x, double y, double pressure, double time = ClockObject::get_global_clock()->get_frame_time());
+  INLINE void update_pointer(int id, double x, double y, double pressure, PointerPhase phase);
   INLINE void remove_pointer(int id);
   INLINE void remove_pointer(int id);
 
 
+  INLINE bool get_pointer_in_window();
+
 private:
 private:
   typedef pset<ButtonHandle> ButtonsHeld;
   typedef pset<ButtonHandle> ButtonsHeld;
   ButtonsHeld _buttons_held;
   ButtonsHeld _buttons_held;

+ 17 - 16
panda/src/display/mouseAndKeyboard.cxx

@@ -72,17 +72,20 @@ do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &,
     PT(PointerEventList) all_events = device->get_pointer_events();
     PT(PointerEventList) all_events = device->get_pointer_events();
     PT(PointerEventList) output_events;
     PT(PointerEventList) output_events;
 
 
-    if (touch_emulates_mouse) {
+    if (touch_emulates_mouse && device->get_pointer().get_type() != PointerType::mouse) {
       output_events = new PointerEventList;
       output_events = new PointerEventList;
       for (int i = 0; i < all_events->get_num_events(); i++) {
       for (int i = 0; i < all_events->get_num_events(); i++) {
         const PointerEvent &event = all_events->get_event(i);
         const PointerEvent &event = all_events->get_event(i);
-        if (event._data.get_type() == PointerType::mouse || event._data.get_primary()) {
-          if (event._data.get_pressure() > 0) {
+        if (event._data.get_type() != PointerType::mouse && event._data.get_primary()) {
+          if (event._data.get_pressure() > 0 && event._data.get_phase() == PointerPhase::began) {
             device->button_down(MouseButton::one());
             device->button_down(MouseButton::one());
-          } else {
+          } else if (event._data.get_phase() == PointerPhase::ended) {
             device->button_up(MouseButton::one());
             device->button_up(MouseButton::one());
           }
           }
-          output_events->add_event(event);
+
+          PointerData emulated_data = PointerData::make_primary_mouse();
+          emulated_data.update(event._data.get_x(), event._data.get_y(), event._data.get_pressure() > 0 ? 1.0 : 0.0, event._data.get_phase());
+          output_events->add_event(emulated_data);
         }
         }
       }
       }
     } else {
     } else {
@@ -105,24 +108,22 @@ do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &,
     _pixel_size->set_value(LPoint2(w, h));
     _pixel_size->set_value(LPoint2(w, h));
     output.set_data(_pixel_size_output, EventParameter(_pixel_size));
     output.set_data(_pixel_size_output, EventParameter(_pixel_size));
 
 
-    if (device->has_pointer()) {
+    if (device->has_pointer() && device->get_pointer_in_window()) {
       PointerData mdata = device->get_pointer();
       PointerData mdata = device->get_pointer();
 
 
       // We're only going to use the pixel_xy and xy wires if the pointer is
       // We're only going to use the pixel_xy and xy wires if the pointer is
       // a mouse or is emulating a mouse.
       // a mouse or is emulating a mouse.
       if (mdata.get_type() == PointerType::mouse || touch_emulates_mouse) {
       if (mdata.get_type() == PointerType::mouse || touch_emulates_mouse) {
-        if (mdata.get_in_window()) {
-          // Get mouse motion in pixels.
-          _pixel_xy->set_value(LPoint2(mdata.get_x(), mdata.get_y()));
-          output.set_data(_pixel_xy_output, EventParameter(_pixel_xy));
+        // Get mouse motion in pixels.
+        _pixel_xy->set_value(LPoint2(mdata.get_x(), mdata.get_y()));
+        output.set_data(_pixel_xy_output, EventParameter(_pixel_xy));
 
 
-          // Normalize pixel motion to range [-1,1].
-          PN_stdfloat xf = (PN_stdfloat)(2 * mdata.get_x()) / (PN_stdfloat)w - 1.0f;
-          PN_stdfloat yf = 1.0f - (PN_stdfloat)(2 * mdata.get_y()) / (PN_stdfloat)h;
+        // Normalize pixel motion to range [-1,1].
+        PN_stdfloat xf = (PN_stdfloat)(2 * mdata.get_x()) / (PN_stdfloat)w - 1.0f;
+        PN_stdfloat yf = 1.0f - (PN_stdfloat)(2 * mdata.get_y()) / (PN_stdfloat)h;
 
 
-          _xy->set_value(LPoint2(xf, yf));
-          output.set_data(_xy_output, EventParameter(_xy));
-        }
+        _xy->set_value(LPoint2(xf, yf));
+        output.set_data(_xy_output, EventParameter(_xy));
       }
       }
     }
     }
   }
   }

+ 4 - 9
panda/src/eagldisplay/eaglGraphicsWindow.mm

@@ -269,14 +269,12 @@ touches_began(NSSet<UITouch *> *touch_set) {
     NSLog(@"%d, %d", point.x, point.y);
     NSLog(@"%d, %d", point.x, point.y);
     float scale = _view.layer.contentsScale;
     float scale = _view.layer.contentsScale;
 
 
-    PointerData &data = _input->add_pointer(PointerType::finger, [next_id intValue], _primary_touch == nil);
-    data.update(point.x * scale, point.y * scale, 1.0);
+    _input->add_pointer(PointerType::finger, [next_id intValue], _primary_touch == nil);
+    _input->update_pointer([next_id intValue], point.x * scale, point.y * scale, 1.0, PointerPhase::began);
 
 
     if (_primary_touch == nil) {
     if (_primary_touch == nil) {
       _primary_touch = touch;
       _primary_touch = touch;
     }
     }
-
-    printf("Touch %d began at %d, %d\n", [next_id intValue], point.x, point.y);
   }];
   }];
 }
 }
 
 
@@ -288,7 +286,7 @@ touches_moved(NSSet<UITouch *> *touch_set) {
     CGPoint point = [touch locationInView:_view];
     CGPoint point = [touch locationInView:_view];
     float scale = _view.layer.contentsScale;
     float scale = _view.layer.contentsScale;
 
 
-    _input->pointer_moved_absolute([touch_id intValue], point.x * scale, point.y * scale, 1.0);
+    _input->update_pointer([touch_id intValue], point.x * scale, point.y * scale, 1.0, PointerPhase::moved);
   }];
   }];
 }
 }
 
 
@@ -304,15 +302,12 @@ touches_ended(NSSet<UITouch *> *touch_set) {
                              OBJC_ASSOCIATION_ASSIGN);
                              OBJC_ASSOCIATION_ASSIGN);
 
 
     PointerData &ptr = _input->get_pointer([touch_id intValue]);
     PointerData &ptr = _input->get_pointer([touch_id intValue]);
-    int x = ptr.get_x();
-    int y = ptr.get_y();
+    ptr.set_phase(PointerPhase::ended);
 
 
     _input->remove_pointer([touch_id intValue]);
     _input->remove_pointer([touch_id intValue]);
     if (_primary_touch == touch) {
     if (_primary_touch == touch) {
       _primary_touch = nil;
       _primary_touch = nil;
     }
     }
-
-    printf("Touch %d ended at %d, %d\n", [touch_id intValue], x, y);
   }];
   }];
 }
 }
 
 

+ 1 - 2
panda/src/event/pointerEvent.cxx

@@ -26,6 +26,5 @@ PointerEvent(PointerData data, double time) :
  */
  */
 void PointerEvent::
 void PointerEvent::
 output(std::ostream &out) const {
 output(std::ostream &out) const {
-  out << (_data.get_in_window() ? "In@" : "Out@")
-      << _data.get_x() << "," << _data.get_y() << " ";
+  out << "In@" << _data.get_x() << "," << _data.get_y() << " ";
 }
 }

+ 5 - 5
panda/src/event/pointerEventList.I

@@ -62,11 +62,11 @@ get_event(size_t n) const {
 /**
 /**
  * Get the in-window flag of the nth event.
  * Get the in-window flag of the nth event.
  */
  */
-INLINE bool PointerEventList::
-get_in_window(size_t n) const {
-  nassertr(n < _events.size(), 0);
-  return _events[n]._data.get_in_window();
-}
+// INLINE bool PointerEventList::
+// get_in_window(size_t n) const {
+//   nassertr(n < _events.size(), 0);
+//   return _events[n]._data.get_in_window();
+// }
 
 
 /**
 /**
  * Get the x-coordinate of the nth event.
  * Get the x-coordinate of the nth event.

+ 1 - 1
panda/src/event/pointerEventList.h

@@ -35,7 +35,7 @@ PUBLISHED:
   INLINE PointerEventList();
   INLINE PointerEventList();
 
 
   INLINE size_t get_num_events() const;
   INLINE size_t get_num_events() const;
-  INLINE bool   get_in_window(size_t n) const;
+  // INLINE bool   get_in_window(size_t n) const;
   INLINE int    get_xpos(size_t n) const;
   INLINE int    get_xpos(size_t n) const;
   INLINE int    get_ypos(size_t n) const;
   INLINE int    get_ypos(size_t n) const;
   // INLINE double get_dx(size_t n) const;
   // INLINE double get_dx(size_t n) const;

+ 0 - 1
panda/src/pgui/pgButton.cxx

@@ -30,7 +30,6 @@ PGButton(const std::string &name) : PGItem(name)
 {
 {
   _button_down = false;
   _button_down = false;
   _click_buttons.insert(MouseButton::one());
   _click_buttons.insert(MouseButton::one());
-  _click_buttons.insert(MouseButton::touch());
 
 
   set_active(true);
   set_active(true);
 }
 }

+ 0 - 11
panda/src/putil/mouseButton.cxx

@@ -22,7 +22,6 @@ ButtonHandle MouseButton::_wheel_up;
 ButtonHandle MouseButton::_wheel_down;
 ButtonHandle MouseButton::_wheel_down;
 ButtonHandle MouseButton::_wheel_left;
 ButtonHandle MouseButton::_wheel_left;
 ButtonHandle MouseButton::_wheel_right;
 ButtonHandle MouseButton::_wheel_right;
-ButtonHandle MouseButton::_touch;
 
 
 /**
 /**
  * Returns the ButtonHandle associated with the particular numbered mouse
  * Returns the ButtonHandle associated with the particular numbered mouse
@@ -112,15 +111,6 @@ ButtonHandle MouseButton::
 wheel_right() {
 wheel_right() {
   return _wheel_right;
   return _wheel_right;
 }
 }
-
-/**
- * Returns the ButtonHandle generated when a finger touches the screen.
- */
-ButtonHandle MouseButton::
-touch() {
-  return _touch;
-}
-
 /**
 /**
  * Returns true if the indicated ButtonHandle is a mouse button, false if it
  * Returns true if the indicated ButtonHandle is a mouse button, false if it
  * is some other kind of button.
  * is some other kind of button.
@@ -155,5 +145,4 @@ init_mouse_buttons() {
   ButtonRegistry::ptr()->register_button(_wheel_down, "wheel_down");
   ButtonRegistry::ptr()->register_button(_wheel_down, "wheel_down");
   ButtonRegistry::ptr()->register_button(_wheel_left, "wheel_left");
   ButtonRegistry::ptr()->register_button(_wheel_left, "wheel_left");
   ButtonRegistry::ptr()->register_button(_wheel_right, "wheel_right");
   ButtonRegistry::ptr()->register_button(_wheel_right, "wheel_right");
-  ButtonRegistry::ptr()->register_button(_touch, "touch");
 }
 }

+ 0 - 2
panda/src/putil/mouseButton.h

@@ -34,7 +34,6 @@ PUBLISHED:
   static ButtonHandle wheel_down();
   static ButtonHandle wheel_down();
   static ButtonHandle wheel_left();
   static ButtonHandle wheel_left();
   static ButtonHandle wheel_right();
   static ButtonHandle wheel_right();
-  static ButtonHandle touch();
 
 
   static bool is_mouse_button(ButtonHandle button);
   static bool is_mouse_button(ButtonHandle button);
 
 
@@ -47,7 +46,6 @@ public:
   static ButtonHandle _wheel_down;
   static ButtonHandle _wheel_down;
   static ButtonHandle _wheel_left;
   static ButtonHandle _wheel_left;
   static ButtonHandle _wheel_right;
   static ButtonHandle _wheel_right;
-  static ButtonHandle _touch;
 };
 };
 
 
 #endif
 #endif

+ 8 - 12
panda/src/putil/pointerData.I

@@ -27,15 +27,6 @@ get_y() const {
   return _ypos;
   return _ypos;
 }
 }
 
 
-/**
- * If this returns false, the pointer is not currently present in the window
- * and the values returned by get_x() and get_y() may not be meaningful.
- */
-INLINE bool PointerData::
-get_in_window() const {
-  return _in_window;
-}
-
 /**
 /**
  * Returns a unique identifier for this pointer.  This is for tracking
  * Returns a unique identifier for this pointer.  This is for tracking
  * individual fingers.  This value should not be assumed to have a specific
  * individual fingers.  This value should not be assumed to have a specific
@@ -69,21 +60,26 @@ get_pressure() const {
   return _pressure;
   return _pressure;
 }
 }
 
 
+INLINE PointerPhase PointerData::
+get_phase() const {
+  return _phase;
+}
 INLINE void PointerData::
 INLINE void PointerData::
 set_pressure(double pressure) {
 set_pressure(double pressure) {
   _pressure = pressure;
   _pressure = pressure;
 }
 }
 
 
 INLINE void PointerData::
 INLINE void PointerData::
-set_in_window(bool in_window) {
-  _in_window = in_window;
+set_phase(PointerPhase phase) {
+  _phase = phase;
 }
 }
 
 
 INLINE void PointerData::
 INLINE void PointerData::
-update(double x, double y, double pressure) {
+update(double x, double y, double pressure, PointerPhase phase) {
   _xpos = x;
   _xpos = x;
   _ypos = y;
   _ypos = y;
   _pressure = pressure;
   _pressure = pressure;
+  _phase = phase;
 }
 }
 
 
 INLINE void PointerData::
 INLINE void PointerData::

+ 6 - 5
panda/src/putil/pointerData.cxx

@@ -22,14 +22,15 @@ PointerData(int id, bool primary, PointerType type) :
 
 
 }
 }
 
 
+PointerData PointerData::
+make_primary_mouse() {
+  return PointerData(0, true, PointerType::mouse);
+}
+
 /**
 /**
  *
  *
  */
  */
 void PointerData::
 void PointerData::
 output(std::ostream &out) const {
 output(std::ostream &out) const {
-  if (!_in_window) {
-    out << "PointerData: Not in window";
-  } else {
-    out << "PointerData: (" << _xpos << ", " << _ypos << ")";
-  }
+  out << "PointerData: (" << _xpos << ", " << _ypos << ")";
 }
 }

+ 36 - 7
panda/src/putil/pointerData.h

@@ -29,6 +29,18 @@ enum class PointerType {
   stylus,
   stylus,
   eraser,
   eraser,
 };
 };
+
+/**
+ * The current "phase" of the pointer's lifecycle.
+ */
+enum class PointerPhase {
+  began, // made contact with the screen during the last frame
+  moved, // continued interaction with the screen
+  ended, // contact ended normally by lifting the pointer or leaving the window.
+  cancelled, // contact was interrupted
+  hover, // For pointers that don't make contact with the screen; indicates
+         // the primary button is not being pressed.
+};
 END_PUBLISH
 END_PUBLISH
 
 
 /**
 /**
@@ -41,16 +53,19 @@ public:
   PointerData() = default;
   PointerData() = default;
   PointerData(int id, bool primary, PointerType type);
   PointerData(int id, bool primary, PointerType type);
 
 
+  static PointerData make_primary_mouse();
+
   INLINE double get_x() const;
   INLINE double get_x() const;
   INLINE double get_y() const;
   INLINE double get_y() const;
-  INLINE bool get_in_window() const;
   INLINE bool get_primary() const;
   INLINE bool get_primary() const;
   INLINE int get_id() const;
   INLINE int get_id() const;
   INLINE PointerType get_type() const;
   INLINE PointerType get_type() const;
   INLINE double get_pressure() const;
   INLINE double get_pressure() const;
+  INLINE PointerPhase get_phase() const;
 
 
-  INLINE void set_in_window(bool in_window);
+  INLINE void set_type(PointerType type);
   INLINE void set_pressure(double pressure);
   INLINE void set_pressure(double pressure);
+  INLINE void set_phase(PointerPhase phase);
 
 
   void output(std::ostream &out) const;
   void output(std::ostream &out) const;
 
 
@@ -60,20 +75,34 @@ PUBLISHED:
   MAKE_PROPERTY(type, get_type);
   MAKE_PROPERTY(type, get_type);
   MAKE_PROPERTY(primary, get_primary);
   MAKE_PROPERTY(primary, get_primary);
   MAKE_PROPERTY(id, get_id);
   MAKE_PROPERTY(id, get_id);
-  MAKE_PROPERTY(in_window, get_in_window, set_in_window);
   MAKE_PROPERTY(pressure, get_pressure, set_pressure);
   MAKE_PROPERTY(pressure, get_pressure, set_pressure);
 
 
-  INLINE void update(double x, double y, double pressure);
+  INLINE void update(double x, double y, double pressure, PointerPhase phase);
   INLINE void rel_move(double rx, double ry);
   INLINE void rel_move(double rx, double ry);
 
 
 protected:
 protected:
+  int _id = 0;
+
+  /**
+   * The primary pointer is what interacts with UI elements and emulates the
+   * mouse, if applicable. In the case of touch, this is usually the first
+   * finger that makes contact with the screen.
+   */
   bool _primary = false;
   bool _primary = false;
-  bool _in_window = true;
+
+  /**
+   * The pressure of the pointer's contact with the screen. This is really only
+   * meaningful for a touchscreen or graphics tablet. For other types of pointer,
+   * this will only be 0.0 or 1.0 when one of the primary buttons are being
+   * pressed.
+   */
+  double _pressure = 0.0;
+
   double _xpos = 0.0;
   double _xpos = 0.0;
   double _ypos = 0.0;
   double _ypos = 0.0;
-  double _pressure = 0.0;
+
   PointerType _type = PointerType::unknown;
   PointerType _type = PointerType::unknown;
-  int _id = 0;
+  PointerPhase _phase = PointerPhase::hover;
 };
 };
 
 
 INLINE std::ostream &operator << (std::ostream &out, const PointerData &md);
 INLINE std::ostream &operator << (std::ostream &out, const PointerData &md);

+ 6 - 12
panda/src/tform/mouseWatcher.cxx

@@ -921,8 +921,7 @@ pointer_down(const PointerData &ptr, const LPoint2 &region_pos) {
   param.set_modifier_buttons(_mods);
   param.set_modifier_buttons(_mods);
   param.set_mouse(region_pos);
   param.set_mouse(region_pos);
   param.set_outside(false);
   param.set_outside(false);
-  param._pressure = ptr.get_pressure();
-  param._pointer_id = ptr.get_id();
+  param.set_pointer(ptr);
 
 
   Regions regions;
   Regions regions;
   get_over_regions(regions, region_pos);
   get_over_regions(regions, region_pos);
@@ -931,7 +930,7 @@ pointer_down(const PointerData &ptr, const LPoint2 &region_pos) {
   _active_regions[ptr.get_id()] = region;
   _active_regions[ptr.get_id()] = region;
 
 
   if (region != nullptr && ptr.get_type() != PointerType::mouse) {
   if (region != nullptr && ptr.get_type() != PointerType::mouse) {
-    param.set_button(MouseButton::touch());
+    param.set_button(MouseButton::one());
     region->press(param);
     region->press(param);
   }
   }
 }
 }
@@ -946,8 +945,7 @@ pointer_move(const PointerData &ptr, const LPoint2 &region_pos) {
   MouseWatcherParameter param;
   MouseWatcherParameter param;
   param.set_modifier_buttons(_mods);
   param.set_modifier_buttons(_mods);
   param.set_mouse(region_pos);
   param.set_mouse(region_pos);
-  param._pressure = ptr.get_pressure();
-  param._pointer_id = ptr.get_id();
+  param.set_pointer(ptr);
 
 
   // pointer._max_pressure = std::max(pointer._max_pressure, pressure);
   // pointer._max_pressure = std::max(pointer._max_pressure, pressure);
 
 
@@ -970,7 +968,8 @@ pointer_up(const PointerData &ptr, const LPoint2 &region_pos) {
     MouseWatcherParameter param;
     MouseWatcherParameter param;
     param.set_modifier_buttons(_mods);
     param.set_modifier_buttons(_mods);
     param.set_mouse(region_pos);
     param.set_mouse(region_pos);
-    param.set_button(MouseButton::touch());
+    param.set_button(MouseButton::one());
+    param.set_pointer(ptr);
 
 
     // Are we still within the same region?
     // Are we still within the same region?
     PN_stdfloat mx = (region_pos[0] + 1.0f) * 0.5f * (_frame[1] - _frame[0]) + _frame[0];
     PN_stdfloat mx = (region_pos[0] + 1.0f) * 0.5f * (_frame[1] - _frame[0]) + _frame[0];
@@ -985,8 +984,7 @@ pointer_up(const PointerData &ptr, const LPoint2 &region_pos) {
     } else {
     } else {
       param.set_outside(true);
       param.set_outside(true);
     }
     }
-
-    param._pointer_id = ptr.get_id();
+    
     region->release(param);
     region->release(param);
   }
   }
 }
 }
@@ -1002,7 +1000,6 @@ move() {
   MouseWatcherParameter param;
   MouseWatcherParameter param;
   param.set_modifier_buttons(_mods);
   param.set_modifier_buttons(_mods);
   param.set_mouse(_mouse);
   param.set_mouse(_mouse);
-  param._pressure = 1.0;
 
 
   if (_preferred_button_down_region != nullptr) {
   if (_preferred_button_down_region != nullptr) {
     _preferred_button_down_region->move(param);
     _preferred_button_down_region->move(param);
@@ -1021,7 +1018,6 @@ press(ButtonHandle button, bool keyrepeat) {
   param.set_keyrepeat(keyrepeat);
   param.set_keyrepeat(keyrepeat);
   param.set_modifier_buttons(_mods);
   param.set_modifier_buttons(_mods);
   param.set_mouse(_mouse);
   param.set_mouse(_mouse);
-  param._pressure = 1.0;
 
 
   if (MouseButton::is_mouse_button(button)) {
   if (MouseButton::is_mouse_button(button)) {
     // Mouse buttons are inextricably linked to the mouse position.
     // Mouse buttons are inextricably linked to the mouse position.
@@ -1073,7 +1069,6 @@ release(ButtonHandle button) {
   param.set_button(button);
   param.set_button(button);
   param.set_modifier_buttons(_mods);
   param.set_modifier_buttons(_mods);
   param.set_mouse(_mouse);
   param.set_mouse(_mouse);
-  param._pressure = 0.0;
 
 
   if (MouseButton::is_mouse_button(button)) {
   if (MouseButton::is_mouse_button(button)) {
     // Button up.  Send the up event associated with the region(s) we were
     // Button up.  Send the up event associated with the region(s) we were
@@ -1115,7 +1110,6 @@ keystroke(int keycode) {
   param.set_keycode(keycode);
   param.set_keycode(keycode);
   param.set_modifier_buttons(_mods);
   param.set_modifier_buttons(_mods);
   param.set_mouse(_mouse);
   param.set_mouse(_mouse);
-  param._pressure = 1.0;
 
 
   // Make sure there are no duplicates in the regions vector.
   // Make sure there are no duplicates in the regions vector.
   if (!_sorted) {
   if (!_sorted) {

+ 19 - 10
panda/src/tform/mouseWatcherParameter.I

@@ -28,7 +28,7 @@ MouseWatcherParameter(const MouseWatcherParameter &copy) :
   _button(copy._button),
   _button(copy._button),
   _keycode(copy._keycode),
   _keycode(copy._keycode),
   _mods(copy._mods),
   _mods(copy._mods),
-  _mouse(copy._mouse),
+  _pointer(copy._pointer),
   _flags(copy._flags)
   _flags(copy._flags)
 {
 {
 }
 }
@@ -41,7 +41,7 @@ operator = (const MouseWatcherParameter &copy) {
   _button = copy._button;
   _button = copy._button;
   _keycode = copy._keycode;
   _keycode = copy._keycode;
   _mods = copy._mods;
   _mods = copy._mods;
-  _mouse = copy._mouse;
+  _pointer = copy._pointer;
   _flags = copy._flags;
   _flags = copy._flags;
 }
 }
 
 
@@ -50,6 +50,7 @@ operator = (const MouseWatcherParameter &copy) {
  */
  */
 INLINE MouseWatcherParameter::
 INLINE MouseWatcherParameter::
 ~MouseWatcherParameter() {
 ~MouseWatcherParameter() {
+
 }
 }
 
 
 /**
 /**
@@ -107,6 +108,14 @@ set_modifier_buttons(const ModifierButtons &mods) {
   _mods = mods;
   _mods = mods;
 }
 }
 
 
+INLINE void MouseWatcherParameter::
+set_pointer(const PointerData &pointer) {
+  // _pointer = new PointerData(pointer.get_id(), pointer.get_primary(), pointer.get_type());
+  // _pointer->update(pointer.get_x(), pointer.get_y(), pointer.get_pressure(), pointer.get_phase());
+  _has_pointer = true;
+  _pointer = pointer;
+}
+
 /**
 /**
  * Sets the mouse position that was current at the time the event was
  * Sets the mouse position that was current at the time the event was
  * generated.
  * generated.
@@ -134,19 +143,19 @@ set_outside(bool flag) {
 /**
 /**
  * Returns the identifier of the pointer that caused this event.
  * Returns the identifier of the pointer that caused this event.
  */
  */
-INLINE int MouseWatcherParameter::
-get_pointer_id() const {
-  return _pointer_id;
-}
+// INLINE int MouseWatcherParameter::
+// get_pointer_id() const {
+//   return _pointer.get_id();
+// }
 
 
 /**
 /**
  * Returns the pressure with which this button or pointer was pressed down,
  * Returns the pressure with which this button or pointer was pressed down,
  * where 0.0 is the minimum and 1.0 is the maximum amount of pressure.
  * where 0.0 is the minimum and 1.0 is the maximum amount of pressure.
  */
  */
-INLINE int MouseWatcherParameter::
-get_pressure() const {
-  return _pressure;
-}
+// INLINE int MouseWatcherParameter::
+// get_pressure() const {
+//   return _pointer.get_pressure();
+// }
 
 
 /**
 /**
  * Returns true if this parameter has an associated mouse or keyboard button,
  * Returns true if this parameter has an associated mouse or keyboard button,

+ 9 - 7
panda/src/tform/mouseWatcherParameter.h

@@ -19,6 +19,7 @@
 #include "buttonHandle.h"
 #include "buttonHandle.h"
 #include "modifierButtons.h"
 #include "modifierButtons.h"
 #include "textEncoder.h"
 #include "textEncoder.h"
+#include "pointerData.h"
 #include "luse.h"
 #include "luse.h"
 
 
 /**
 /**
@@ -40,12 +41,12 @@ public:
                             size_t higlight_end,
                             size_t higlight_end,
                             size_t cursor_pos);
                             size_t cursor_pos);
   INLINE void set_modifier_buttons(const ModifierButtons &mods);
   INLINE void set_modifier_buttons(const ModifierButtons &mods);
+
   INLINE void set_mouse(const LPoint2 &mouse);
   INLINE void set_mouse(const LPoint2 &mouse);
+  INLINE void set_pointer(const PointerData &pointer);
+  INLINE void set_region_pos(const LPoint2 &pos);
   INLINE void set_outside(bool flag);
   INLINE void set_outside(bool flag);
 
 
-  INLINE int get_pointer_id() const;
-  INLINE int get_pressure() const;
-
 PUBLISHED:
 PUBLISHED:
   INLINE bool has_button() const;
   INLINE bool has_button() const;
   INLINE ButtonHandle get_button() const;
   INLINE ButtonHandle get_button() const;
@@ -79,8 +80,6 @@ PUBLISHED:
   MAKE_PROPERTY2(button, has_button, get_button);
   MAKE_PROPERTY2(button, has_button, get_button);
   MAKE_PROPERTY(modifier_buttons, get_modifier_buttons);
   MAKE_PROPERTY(modifier_buttons, get_modifier_buttons);
   MAKE_PROPERTY2(keycode, has_keycode, get_keycode);
   MAKE_PROPERTY2(keycode, has_keycode, get_keycode);
-  MAKE_PROPERTY2(pointer_id, has_mouse, get_pointer_id);
-  MAKE_PROPERTY(pressure, get_pressure);
 
 
 public:
 public:
   ButtonHandle _button = ButtonHandle::none();
   ButtonHandle _button = ButtonHandle::none();
@@ -91,8 +90,8 @@ public:
   size_t _cursor_pos;
   size_t _cursor_pos;
   ModifierButtons _mods;
   ModifierButtons _mods;
   LPoint2 _mouse;
   LPoint2 _mouse;
-  int _pointer_id = 0;
-  double _pressure = 0.0;
+
+  PointerData _pointer;
 
 
   enum Flags {
   enum Flags {
     F_has_button    = 0x001,
     F_has_button    = 0x001,
@@ -103,6 +102,9 @@ public:
     F_is_keyrepeat  = 0x020,
     F_is_keyrepeat  = 0x020,
   };
   };
   int _flags;
   int _flags;
+
+protected:
+  bool _has_pointer;
 };
 };
 
 
 INLINE std::ostream &operator << (std::ostream &out, const MouseWatcherParameter &parm);
 INLINE std::ostream &operator << (std::ostream &out, const MouseWatcherParameter &parm);