Browse Source

input: fix for Windows compilation, reenable raw input

rdb 8 years ago
parent
commit
9d2e1f92cb

+ 21 - 0
panda/src/device/inputDevice.cxx

@@ -156,6 +156,27 @@ set_pointer_out_of_window(double time) {
   }
 }
 
+/**
+ * Records that a relative mouse movement has taken place.
+ */
+void InputDevice::
+pointer_moved(double x, double y, double time) {
+  nassertv(_lock.debug_is_locked());
+  _pointer_data._xpos += x;
+  _pointer_data._ypos += y;
+
+  if (_enable_pointer_events) {
+    int seq = _event_sequence++;
+    if (_pointer_events.is_null()) {
+      _pointer_events = new PointerEventList();
+    }
+    _pointer_events->add_event(_pointer_data._in_window,
+                               _pointer_data._xpos,
+                               _pointer_data._ypos,
+                               x, y, seq, time);
+  }
+}
+
 /**
  * Sets the state of the indicated button index, where true indicates down,
  * and false indicates up.  This may generate a ButtonEvent if the button has

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

@@ -185,6 +185,7 @@ PUBLISHED:
 protected:
   void set_pointer(bool inwin, double x, double y, double time);
   void set_pointer_out_of_window(double time);
+  void pointer_moved(double x, double y, double time);
   void set_button_state(int index, bool down);
   void set_control_state(int index, double state);
   void set_tracker(const LPoint3 &pos, const LOrientation &orient, double time);

+ 1 - 1
panda/src/device/xInputDevice.cxx

@@ -378,7 +378,7 @@ init_device(const XINPUT_CAPABILITIES &caps, const XINPUT_STATE &state) {
   for (int i = 0; i < 16; ++i) {
     if (buttons & mask) {
       // Set the state without triggering a button event.
-      _buttons[i]._state = (buttons & mask) ? S_down : S_up;
+      _buttons[i].state = (buttons & mask) ? S_down : S_up;
     }
     mask <<= 1;
     if (i == 10) {

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

@@ -37,3 +37,13 @@ set_pointer_out_of_window(double time) {
   LightMutexHolder holder(_lock);
   InputDevice::set_pointer_out_of_window(time);
 }
+
+/**
+ * To be called by a particular kind of GraphicsWindow to indicate that the
+ * pointer has moved by the given relative amount.
+ */
+INLINE void GraphicsWindowInputDevice::
+pointer_moved(double x, double y, double time) {
+  LightMutexHolder holder(_lock);
+  InputDevice::pointer_moved(x, y, time);
+}

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

@@ -57,6 +57,7 @@ PUBLISHED:
 
   INLINE void set_pointer_in_window(double x, double y, double time = ClockObject::get_global_clock()->get_frame_time());
   INLINE void set_pointer_out_of_window(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());
 
 private:
   typedef pset<ButtonHandle> ButtonsHeld;

+ 0 - 35
panda/src/event/pointerEvent.I

@@ -29,41 +29,6 @@ PointerEvent() :
 {
 }
 
-/**
- *
- */
-INLINE PointerEvent::
-PointerEvent(const PointerEvent &copy) :
-  _in_window(copy._in_window),
-  _xpos(copy._xpos),
-  _ypos(copy._ypos),
-  _dx(copy._dx),
-  _dy(copy._dy),
-  _length(copy._length),
-  _direction(copy._direction),
-  _rotation(copy._rotation),
-  _sequence(copy._sequence),
-  _time(copy._time)
-{
-}
-
-/**
- *
- */
-INLINE void PointerEvent::
-operator = (const PointerEvent &copy) {
-  _in_window = copy._in_window;
-  _xpos = copy._xpos;
-  _ypos = copy._ypos;
-  _dx = copy._dx;
-  _dy = copy._dy;
-  _sequence = copy._sequence;
-  _length = copy._length;
-  _direction = copy._direction;
-  _rotation = copy._rotation;
-  _time = copy._time;
-}
-
 /**
  * The equality operator does not consider time significant.
  */

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

@@ -25,10 +25,7 @@ class DatagramIterator;
  */
 class EXPCL_PANDA_EVENT PointerEvent {
 public:
-
   INLINE PointerEvent();
-  INLINE PointerEvent(const PointerEvent &copy);
-  INLINE void operator = (const PointerEvent &copy);
 
   INLINE bool operator == (const PointerEvent &other) const;
   INLINE bool operator != (const PointerEvent &other) const;
@@ -43,8 +40,8 @@ public:
   bool      _in_window;
   int       _xpos;
   int       _ypos;
-  int       _dx;
-  int       _dy;
+  double    _dx;
+  double    _dy;
   double    _length;
   double    _direction;
   double    _rotation;

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

@@ -38,7 +38,7 @@ operator = (const PointerEventList &copy) {
 /**
  * Returns the number of events in the list.
  */
-INLINE int PointerEventList::
+INLINE size_t PointerEventList::
 get_num_events() const {
   return _events.size();
 }
@@ -47,90 +47,90 @@ get_num_events() const {
  * Get the in-window flag of the nth event.
  */
 INLINE bool PointerEventList::
-get_in_window(int evt) const {
-  nassertr((evt >= 0) && (evt < (int)_events.size()), 0);
-  return _events[evt]._in_window;
+get_in_window(size_t n) const {
+  nassertr(n < _events.size(), 0);
+  return _events[n]._in_window;
 }
 
 /**
  * Get the x-coordinate of the nth event.
  */
 INLINE int PointerEventList::
-get_xpos(int evt) const {
-  nassertr((evt >= 0) && (evt < (int)_events.size()), 0);
-  return _events[evt]._xpos;
+get_xpos(size_t n) const {
+  nassertr(n < _events.size(), 0);
+  return _events[n]._xpos;
 }
 
 /**
  * Get the y-coordinate of the nth event.
  */
 INLINE int PointerEventList::
-get_ypos(int evt) const {
-  nassertr((evt >= 0) && (evt < (int)_events.size()), 0);
-  return _events[evt]._ypos;
+get_ypos(size_t n) const {
+  nassertr(n < _events.size(), 0);
+  return _events[n]._ypos;
 }
 
 /**
- * Get the x-coordinate of the nth event.
+ * Get the x-delta of the nth event.
  */
-INLINE int PointerEventList::
-get_dx(int evt) const {
-  nassertr((evt >= 0) && (evt < (int)_events.size()), 0);
-  return _events[evt]._dx;
+INLINE double PointerEventList::
+get_dx(size_t n) const {
+  nassertr(n < _events.size(), 0);
+  return _events[n]._dx;
 }
 
 /**
- * Get the y-coordinate of the nth event.
+ * Get the y-delta of the nth event.
  */
-INLINE int PointerEventList::
-get_dy(int evt) const {
-  nassertr((evt >= 0) && (evt < (int)_events.size()), 0);
-  return _events[evt]._dy;
+INLINE double PointerEventList::
+get_dy(size_t n) const {
+  nassertr(n < _events.size(), 0);
+  return _events[n]._dy;
 }
 
 /**
  * Get the length of the nth event.
  */
 INLINE double PointerEventList::
-get_length(int evt) const {
-  nassertr((evt >= 0) && (evt < (int)_events.size()), 0);
-  return _events[evt]._length;
+get_length(size_t n) const {
+  nassertr(n < _events.size(), 0);
+  return _events[n]._length;
 }
 
 /**
  * Get the direction of the nth event.
  */
 INLINE double PointerEventList::
-get_direction(int evt) const {
-  nassertr((evt >= 0) && (evt < (int)_events.size()), 0);
-  return _events[evt]._direction;
+get_direction(size_t n) const {
+  nassertr(n < _events.size(), 0);
+  return _events[n]._direction;
 }
 
 /**
  * Get the rotation of the nth event.
  */
 INLINE double PointerEventList::
-get_rotation(int evt) const {
-  nassertr((evt >= 0) && (evt < (int)_events.size()), 0);
-  return _events[evt]._rotation;
+get_rotation(size_t n) const {
+  nassertr(n < _events.size(), 0);
+  return _events[n]._rotation;
 }
 
 /**
  * Get the sequence number of the nth event.
  */
 INLINE int PointerEventList::
-get_sequence(int evt) const {
-  nassertr((evt >= 0) && (evt < (int)_events.size()), 0);
-  return _events[evt]._sequence;
+get_sequence(size_t n) const {
+  nassertr(n < _events.size(), 0);
+  return _events[n]._sequence;
 }
 
 /**
  * Get the timestamp of the nth event.
  */
 INLINE double PointerEventList::
-get_time(int evt) const {
-  nassertr((evt >= 0) && (evt < (int)_events.size()), 0);
-  return _events[evt]._time;
+get_time(size_t n) const {
+  nassertr(n < _events.size(), 0);
+  return _events[n]._time;
 }
 
 /**

+ 29 - 0
panda/src/event/pointerEventList.cxx

@@ -110,6 +110,35 @@ add_event(bool in_win, int xpos, int ypos, int seq, double time) {
   _events.push_back(pe);
 }
 
+/**
+ * Adds a new event to the end of the list based on the given mouse movement.
+ */
+void PointerEventList::
+add_event(bool in_win, int xpos, int ypos, double xdelta, double ydelta, int seq, double time) {
+  PointerEvent pe;
+  pe._in_window = in_win;
+  pe._xpos = xpos;
+  pe._ypos = ypos;
+  pe._dx = xdelta;
+  pe._dy = ydelta;
+  pe._sequence = seq;
+  pe._time = time;
+  pe._length = csqrt(xdelta*xdelta + ydelta*ydelta);
+  if (pe._length > 0.0) {
+    pe._direction = normalize_angle(rad_2_deg(catan2(-ydelta,xdelta)));
+  } else if (!_events.empty()) {
+    pe._direction = _events.back()._direction;
+  } else {
+    pe._direction = 0.0;
+  }
+  if (!_events.empty()) {
+    pe._rotation = delta_angle(_events.back()._direction, pe._direction);
+  } else {
+    pe._rotation = 0.0;
+  }
+  _events.push_back(pe);
+}
+
 /**
  * Returns true if the trail loops around the specified point.
  */

+ 14 - 12
panda/src/event/pointerEventList.h

@@ -34,21 +34,23 @@ class EXPCL_PANDA_EVENT PointerEventList : public ParamValueBase {
 PUBLISHED:
   INLINE PointerEventList();
 
-  INLINE int get_num_events() const;
-  INLINE bool   get_in_window(int n) const;
-  INLINE int    get_xpos(int n) const;
-  INLINE int    get_ypos(int n) const;
-  INLINE int    get_dx(int n) const;
-  INLINE int    get_dy(int n) const;
-  INLINE int    get_sequence(int n) const;
-  INLINE double get_length(int n) const;
-  INLINE double get_direction(int n) const;
-  INLINE double get_rotation(int n) const;
-  INLINE double get_time(int n) const;
+  INLINE size_t get_num_events() const;
+  INLINE bool   get_in_window(size_t n) const;
+  INLINE int    get_xpos(size_t n) const;
+  INLINE int    get_ypos(size_t n) const;
+  INLINE double get_dx(size_t n) const;
+  INLINE double get_dy(size_t n) const;
+  INLINE int    get_sequence(size_t n) const;
+  INLINE double get_length(size_t n) const;
+  INLINE double get_direction(size_t n) const;
+  INLINE double get_rotation(size_t n) const;
+  INLINE double get_time(size_t n) const;
 
   INLINE void   clear();
   INLINE void   pop_front();
-  void   add_event(bool in_win, int xpos, int ypos, int seq, double 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);
 
   bool   encircles(int x, int y) const;
   double total_turns(double sec) const;

+ 22 - 21
panda/src/windisplay/winGraphicsWindow.cxx

@@ -617,15 +617,16 @@ initialize_input_devices() {
           char *pound3 = pound2 ? strchr(pound2+1,'#') : 0;
           if (pound3) *pound3 = 0;
           for (char *p = psName; *p; p++) {
-            if (((*p<'a')||(*p>'z')) && ((*p<'A')||(*p>'Z')) && ((*p<'0')||(*p>'9'))) {
+            if (!isalnum(*p)) {
               *p = '_';
             }
           }
           if (pound2) *pound2 = '.';
           _input_device_handle[_input_devices.size()] = pRawInputDeviceList[i].hDevice;
-          //GraphicsWindowInputDevice device = GraphicsWindowInputDevice::pointer_only(this, psName);
-          //device.set_pointer_in_window(0,0);
-          //add_input_device(device);
+
+          PT(GraphicsWindowInputDevice) device = GraphicsWindowInputDevice::pointer_only(this, psName);
+          device->set_pointer_in_window(0, 0);
+          add_input_device(device);
         }
       }
     }
@@ -2654,53 +2655,53 @@ handle_raw_input(HRAWINPUT hraw) {
   if (raw->header.hDevice == 0) {
     return;
   }
-/*
-  for (int i = 1; i < (int)(_input_devices.size()); ++i) {
+
+  for (size_t i = 1; i < _input_devices.size(); ++i) {
     if (_input_device_handle[i] == raw->header.hDevice) {
+      PT(GraphicsWindowInputDevice) input =
+        DCAST(GraphicsWindowInputDevice, _input_devices[i]);
+
       int adjx = raw->data.mouse.lLastX;
       int adjy = raw->data.mouse.lLastY;
 
       if (raw->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE) {
-        _input_devices[i].set_pointer_in_window(adjx, adjy);
+        input->set_pointer_in_window(adjx, adjy);
       } else {
-        //int oldx = _input_devices[i].get_raw_pointer().get_x();
-        //int oldy = _input_devices[i].get_raw_pointer().get_y();
-        //_input_devices[i].set_pointer_in_window(oldx + adjx, oldy + adjy);
+        input->pointer_moved(adjx, adjy);
       }
 
       if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_1_DOWN) {
-        _input_devices[i].button_down(MouseButton::button(0), get_message_time());
+        input->button_down(MouseButton::button(0), get_message_time());
       }
       if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_1_UP) {
-        _input_devices[i].button_up(MouseButton::button(0), get_message_time());
+        input->button_up(MouseButton::button(0), get_message_time());
       }
       if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_2_DOWN) {
-        _input_devices[i].button_down(MouseButton::button(2), get_message_time());
+        input->button_down(MouseButton::button(2), get_message_time());
       }
       if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_2_UP) {
-        _input_devices[i].button_up(MouseButton::button(2), get_message_time());
+        input->button_up(MouseButton::button(2), get_message_time());
       }
       if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_3_DOWN) {
-        _input_devices[i].button_down(MouseButton::button(1), get_message_time());
+        input->button_down(MouseButton::button(1), get_message_time());
       }
       if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_3_UP) {
-        _input_devices[i].button_up(MouseButton::button(1), get_message_time());
+        input->button_up(MouseButton::button(1), get_message_time());
       }
       if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) {
-        _input_devices[i].button_down(MouseButton::button(3), get_message_time());
+        input->button_down(MouseButton::button(3), get_message_time());
       }
       if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_4_UP) {
-        _input_devices[i].button_up(MouseButton::button(3), get_message_time());
+        input->button_up(MouseButton::button(3), get_message_time());
       }
       if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) {
-        _input_devices[i].button_down(MouseButton::button(4), get_message_time());
+        input->button_down(MouseButton::button(4), get_message_time());
       }
       if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_UP) {
-        _input_devices[i].button_up(MouseButton::button(4), get_message_time());
+        input->button_up(MouseButton::button(4), get_message_time());
       }
     }
   }
-*/
 }
 
 /**