From dcdc6d9877f7ee3a8666f21d1315fd3202aa3bd8 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 3 Aug 2012 12:00:08 +0000 Subject: [PATCH] mouse coordinates are now stored as doubles, not ints --- panda/src/display/graphicsWindowInputDevice.I | 2 +- .../src/display/graphicsWindowInputDevice.cxx | 36 ++++++++----------- panda/src/display/graphicsWindowInputDevice.h | 6 ++-- panda/src/putil/mouseData.I | 4 +-- panda/src/putil/mouseData.h | 8 ++--- 5 files changed, 24 insertions(+), 32 deletions(-) diff --git a/panda/src/display/graphicsWindowInputDevice.I b/panda/src/display/graphicsWindowInputDevice.I index f4000f9df7..fe04d98b42 100644 --- a/panda/src/display/graphicsWindowInputDevice.I +++ b/panda/src/display/graphicsWindowInputDevice.I @@ -125,7 +125,7 @@ disable_pointer_events() { // the given pixel coordinates. //////////////////////////////////////////////////////////////////// INLINE void GraphicsWindowInputDevice:: -set_pointer_in_window(int x, int y, double time) { +set_pointer_in_window(double x, double y, double time) { // mutex is handled in set pointer .. convience function set_pointer(true, x, y, time); } diff --git a/panda/src/display/graphicsWindowInputDevice.cxx b/panda/src/display/graphicsWindowInputDevice.cxx index 4891499ddf..e6f9fdf483 100644 --- a/panda/src/display/graphicsWindowInputDevice.cxx +++ b/panda/src/display/graphicsWindowInputDevice.cxx @@ -49,8 +49,6 @@ GraphicsWindowInputDevice(GraphicsWindow *host, const string &name, int flags) : _event_sequence(0), _pointer_mode_enable(false), _pointer_speed(1.0), - _pointer_true_x(0.0), - _pointer_true_y(0.0), _enable_pointer_events(false) { } @@ -117,8 +115,6 @@ operator = (const GraphicsWindowInputDevice ©) _event_sequence = copy._event_sequence; _pointer_mode_enable = copy._pointer_mode_enable; _pointer_speed = copy._pointer_speed; - _pointer_true_x = copy._pointer_true_x; - _pointer_true_y = copy._pointer_true_y; _enable_pointer_events = copy._enable_pointer_events; _mouse_data = copy._mouse_data; _true_mouse_data = copy._true_mouse_data; @@ -216,11 +212,9 @@ enable_pointer_mode(double speed) { nassertv(_device_index != 0); _pointer_mode_enable = true; _pointer_speed = speed; - _pointer_true_x = _host->get_x_size() * 0.5; - _pointer_true_y = _host->get_y_size() * 0.5; + _mouse_data._xpos = _host->get_x_size() * 0.5; + _mouse_data._ypos = _host->get_y_size() * 0.5; _mouse_data._in_window = true; - _mouse_data._xpos = int(_pointer_true_x + 0.5); - _mouse_data._ypos = int(_pointer_true_y + 0.5); } //////////////////////////////////////////////////////////////////// @@ -234,8 +228,6 @@ disable_pointer_mode() { nassertv(_device_index != 0); _pointer_mode_enable = false; _pointer_speed = 1.0; - _pointer_true_x = 0.0; - _pointer_true_y = 0.0; _mouse_data = _true_mouse_data; } @@ -245,27 +237,29 @@ disable_pointer_mode() { // Description: Records that a mouse movement has taken place. //////////////////////////////////////////////////////////////////// void GraphicsWindowInputDevice:: -set_pointer(bool inwin, int x, int y, double time) { +set_pointer(bool inwin, double x, double y, double time) { LightMutexHolder holder(_lock); - int delta_x = x - _true_mouse_data._xpos; - int delta_y = y - _true_mouse_data._ypos; + double delta_x = x - _true_mouse_data._xpos; + double delta_y = y - _true_mouse_data._ypos; _true_mouse_data._in_window = inwin; _true_mouse_data._xpos = x; _true_mouse_data._ypos = y; if (_pointer_mode_enable) { - _pointer_true_x += (delta_x * _pointer_speed); - _pointer_true_y += (delta_y * _pointer_speed); + double pointer_x = _mouse_data._xpos; + double pointer_y = _mouse_data._ypos; + pointer_x += (delta_x * _pointer_speed); + pointer_y += (delta_y * _pointer_speed); double xhi = _host->get_x_size(); double yhi = _host->get_y_size(); - if (_pointer_true_x < 0.0) _pointer_true_x = 0.0; - if (_pointer_true_y < 0.0) _pointer_true_y = 0.0; - if (_pointer_true_x > xhi) _pointer_true_x = xhi; - if (_pointer_true_y > yhi) _pointer_true_y = yhi; + if (pointer_x < 0.0) pointer_x = 0.0; + if (pointer_y < 0.0) pointer_y = 0.0; + if (pointer_x > xhi) pointer_x = xhi; + if (pointer_y > yhi) pointer_y = yhi; _mouse_data._in_window = true; - _mouse_data._xpos = int(_pointer_true_x + 0.5); - _mouse_data._ypos = int(_pointer_true_y + 0.5); + _mouse_data._xpos = pointer_x; + _mouse_data._ypos = pointer_y; } else { _mouse_data = _true_mouse_data; } diff --git a/panda/src/display/graphicsWindowInputDevice.h b/panda/src/display/graphicsWindowInputDevice.h index 282735fbc7..367feebd26 100644 --- a/panda/src/display/graphicsWindowInputDevice.h +++ b/panda/src/display/graphicsWindowInputDevice.h @@ -82,9 +82,9 @@ PUBLISHED: size_t highlight_end, size_t cursor_pos); void focus_lost(double time = ClockObject::get_global_clock()->get_frame_time()); - INLINE void set_pointer_in_window(int x, int y, double time = ClockObject::get_global_clock()->get_frame_time()); + 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()); - void set_pointer(bool inwin, int x, int y, double time); + void set_pointer(bool inwin, double x, double y, double time); public: // We need these methods to make VC++ happy when we try to @@ -112,8 +112,6 @@ private: bool _pointer_mode_enable; double _pointer_speed; - double _pointer_true_x; - double _pointer_true_y; bool _enable_pointer_events; MouseData _mouse_data; diff --git a/panda/src/putil/mouseData.I b/panda/src/putil/mouseData.I index 18e8057a6d..517832ef7b 100644 --- a/panda/src/putil/mouseData.I +++ b/panda/src/putil/mouseData.I @@ -55,7 +55,7 @@ operator = (const MouseData ©) { // Access: Published // Description: //////////////////////////////////////////////////////////////////// -INLINE int MouseData:: +INLINE double MouseData:: get_x() const { return _xpos; } @@ -65,7 +65,7 @@ get_x() const { // Access: Published // Description: //////////////////////////////////////////////////////////////////// -INLINE int MouseData:: +INLINE double MouseData:: get_y() const { return _ypos; } diff --git a/panda/src/putil/mouseData.h b/panda/src/putil/mouseData.h index a82241ac4d..b0b581a816 100644 --- a/panda/src/putil/mouseData.h +++ b/panda/src/putil/mouseData.h @@ -31,16 +31,16 @@ PUBLISHED: INLINE MouseData(const MouseData ©); INLINE void operator = (const MouseData ©); - INLINE int get_x() const; - INLINE int get_y() const; + INLINE double get_x() const; + INLINE double get_y() const; INLINE bool get_in_window() const; void output(ostream &out) const; public: bool _in_window; - int _xpos; - int _ypos; + double _xpos; + double _ypos; }; INLINE ostream &operator << (ostream &out, const MouseData &md);