Kaynağa Gözat

event: Make PointerEvent a TypedWritableReferenceCount, add gesture sequencing information back.

Donny Lawrence 6 yıl önce
ebeveyn
işleme
e88a676180

+ 1 - 0
panda/src/event/config_event.cxx

@@ -44,6 +44,7 @@ ConfigureFn(config_event) {
   AsyncTaskPause::init_type();
   AsyncTaskSequence::init_type();
   ButtonEventList::init_type();
+  PointerEvent::init_type();
   PointerEventList::init_type();
   Event::init_type();
   EventHandler::init_type();

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

@@ -13,9 +13,12 @@
 
 #include "pointerEvent.h"
 
+TypeHandle PointerEvent::_type_handle;
+
 PointerEvent::
-PointerEvent(PointerData data, double time) :
+PointerEvent(PointerData data, int sequence, double time) :
   _data(data),
+  _sequence(sequence),
   _time(time)
 {
 

+ 38 - 2
panda/src/event/pointerEvent.h

@@ -20,9 +20,10 @@
 /**
  * Records a pointer movement event.
  */
-class EXPCL_PANDA_EVENT PointerEvent {
+class EXPCL_PANDA_EVENT PointerEvent : public TypedWritableReferenceCount {
 public:
-  PointerEvent(PointerData data, double time = ClockObject::get_global_clock()->get_frame_time());
+  PointerEvent() = default;
+  PointerEvent(PointerData data, int sequence, double time = ClockObject::get_global_clock()->get_frame_time());
 
   // INLINE bool operator == (const PointerEvent &other) const;
   // INLINE bool operator != (const PointerEvent &other) const;
@@ -31,8 +32,43 @@ public:
   void output(std::ostream &out) const;
 
 public:
+  /**
+   * Captured copy of the pointer data for this event.
+   */
   PointerData _data;
+  
+  /**
+   * Time in seconds.
+   */
   double _time = 0.0;
+
+  /**
+   * nth touch since the primary pointer touched the screen.
+   */
+  int _sequence = 0;
+  
+  /**
+   * Change in positon since the last PointerEvent with this id. Will be (0,0)
+   * if the _data.get_phase() is PointerPhase::began.
+   */
+  LVecBase2 _pos_change;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    TypedWritableReferenceCount::init_type();
+    register_type(_type_handle, "PointerEvent",
+                  TypedWritableReferenceCount::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
 };
 
 INLINE std::ostream &operator << (std::ostream &out, const PointerEvent &pe) {

+ 13 - 30
panda/src/event/pointerEventList.cxx

@@ -78,7 +78,7 @@ write(std::ostream &out, int indent_level) const {
 
 void PointerEventList::
 add_event(const PointerEvent &event) {
-  _events.push_back(event);
+  do_add_event(event);
 }
 
 /**
@@ -86,35 +86,18 @@ add_event(const PointerEvent &event) {
  */
 void PointerEventList::
 add_event(const PointerData &data, double time) {
-  // PointerEvent pe;
-  // pe._in_window = data.get_in_window();
-  // pe._type = data.get_type();
-  // pe._id = data.get_id();
-  // pe._xpos = data.get_x();
-  // pe._ypos = data.get_y();
-  // pe._pressure = data.get_pressure();
-  // pe._sequence = seq;
-  // pe._time = time;
-  // if (_events.size() > 0) {
-  //   pe._dx = data._xpos - _events.back()._xpos;
-  //   pe._dy = data._ypos - _events.back()._ypos;
-  //   double ddx = pe._dx;
-  //   double ddy = pe._dy;
-  //   pe._length = csqrt(ddx*ddx + ddy*ddy);
-  //   if (pe._length > 0.0) {
-  //     pe._direction = normalize_angle(rad_2_deg(catan2(-ddy,ddx)));
-  //   } else {
-  //     pe._direction = _events.back()._direction;
-  //   }
-  //   pe._rotation = delta_angle(_events.back()._direction, pe._direction);
-  // } else {
-  //   pe._dx = 0;
-  //   pe._dy = 0;
-  //   pe._length = 0.0;
-  //   pe._direction = 0.0;
-  //   pe._rotation = 0.0;
-  // }
-  _events.push_back(PointerEvent(data, time));
+  if (data.get_primary()) {
+    _current_sequence = 0;
+  }
+
+  auto event = PointerEvent(data, _current_sequence++, time);
+  
+  do_add_event(event);
+}
+
+void PointerEventList::
+do_add_event(const PointerEvent &event) {
+  _events.push_back(event);
 }
 
 /**

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

@@ -50,7 +50,7 @@ PUBLISHED:
   INLINE void   pop_front();
 
   void add_event(const PointerEvent &event);
-  void add_event(const PointerData &data, double time);
+  void add_event(const PointerData &data, double time = ClockObject::get_global_clock()->get_frame_time());
   // void add_event(bool in_win, int xpos, int ypos, int seq, double time);
   // void add_event(bool in_win, int xpos, int ypos, double xdelta, double ydelta,
   //                int seq, double time);
@@ -71,9 +71,12 @@ public:
 
 private:
   void parse_pattern(const std::string &ascpat, vector_double &pattern);
+  void do_add_event(const PointerEvent &event);
   typedef pdeque<PointerEvent> Events;
   Events _events;
 
+  int _current_sequence;
+
 public:
   static TypeHandle get_class_type() {
     return _type_handle;