From d561b66713cc041cd82c8c00be41831906f270d8 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 3 Mar 2004 19:38:28 +0000 Subject: [PATCH] expose GraphicsWindow::get_pointer and move_pointer --- panda/src/device/mouseAndKeyboard.cxx | 2 +- panda/src/display/graphicsWindow.cxx | 25 +++++++++++++++---- panda/src/display/graphicsWindow.h | 4 ++- panda/src/display/graphicsWindowInputDevice.I | 8 +++--- panda/src/display/graphicsWindowInputDevice.h | 2 +- panda/src/glxdisplay/glxGraphicsWindow.cxx | 25 +++++++++++++++++++ panda/src/glxdisplay/glxGraphicsWindow.h | 2 ++ panda/src/putil/mouseData.I | 6 +++++ panda/src/putil/mouseData.cxx | 14 +++++++++++ panda/src/putil/mouseData.h | 4 +++ 10 files changed, 80 insertions(+), 12 deletions(-) diff --git a/panda/src/device/mouseAndKeyboard.cxx b/panda/src/device/mouseAndKeyboard.cxx index a7051e49a3..4ba14c9c1d 100644 --- a/panda/src/device/mouseAndKeyboard.cxx +++ b/panda/src/device/mouseAndKeyboard.cxx @@ -84,7 +84,7 @@ do_transmit_data(const DataNodeTransmit &, DataNodeTransmit &output) { } if (_window->has_pointer(_device)) { - const MouseData &mdata = _window->get_mouse_data(_device); + const MouseData &mdata = _window->get_pointer(_device); if (mdata._in_window) { // Get mouse motion in pixels. diff --git a/panda/src/display/graphicsWindow.cxx b/panda/src/display/graphicsWindow.cxx index 87e5842ced..76ee58942d 100644 --- a/panda/src/display/graphicsWindow.cxx +++ b/panda/src/display/graphicsWindow.cxx @@ -268,22 +268,37 @@ has_keyboard(int device) const { } //////////////////////////////////////////////////////////////////// -// Function: GraphicsWindow::get_mouse_data -// Access: Public +// Function: GraphicsWindow::get_pointer +// Access: Published // Description: Returns the MouseData associated with the nth input -// device. +// device's pointer. //////////////////////////////////////////////////////////////////// MouseData GraphicsWindow:: -get_mouse_data(int device) const { +get_pointer(int device) const { MouseData result; { MutexHolder holder(_input_lock); nassertr(device >= 0 && device < (int)_input_devices.size(), MouseData()); - result = _input_devices[device].get_mouse_data(); + result = _input_devices[device].get_pointer(); } return result; } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindow::move_pointer +// Access: Published, Virtual +// Description: Forces the pointer to the indicated position within +// the window, if possible. +// +// Returns true if successful, false on failure. This +// may fail if the mouse is not currently within the +// window, or if the API doesn't support this operation. +//////////////////////////////////////////////////////////////////// +bool GraphicsWindow:: +move_pointer(int, int, int) { + return false; +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsWindow::has_button_event // Access: Public diff --git a/panda/src/display/graphicsWindow.h b/panda/src/display/graphicsWindow.h index da3669a342..740c2a48e9 100644 --- a/panda/src/display/graphicsWindow.h +++ b/panda/src/display/graphicsWindow.h @@ -63,9 +63,11 @@ PUBLISHED: bool has_pointer(int device) const; bool has_keyboard(int device) const; + MouseData get_pointer(int device) const; + virtual bool move_pointer(int device, int x, int y); + public: // No need to publish these. - MouseData get_mouse_data(int device) const; bool has_button_event(int device) const; ButtonEvent get_button_event(int device); diff --git a/panda/src/display/graphicsWindowInputDevice.I b/panda/src/display/graphicsWindowInputDevice.I index f4aab7361f..51d41f9da6 100644 --- a/panda/src/display/graphicsWindowInputDevice.I +++ b/panda/src/display/graphicsWindowInputDevice.I @@ -57,13 +57,13 @@ has_keyboard() const { } //////////////////////////////////////////////////////////////////// -// Function: GraphicsWindowInputDevice::get_mouse_data +// Function: GraphicsWindowInputDevice::get_pointer // Access: Public -// Description: Returns the MouseData associated with the nth input -// device. +// Description: Returns the MouseData associated with the input +// device's pointer. //////////////////////////////////////////////////////////////////// INLINE const MouseData &GraphicsWindowInputDevice:: -get_mouse_data() const { +get_pointer() const { return _mouse_data; } diff --git a/panda/src/display/graphicsWindowInputDevice.h b/panda/src/display/graphicsWindowInputDevice.h index 545dd8671d..25fc16dc14 100644 --- a/panda/src/display/graphicsWindowInputDevice.h +++ b/panda/src/display/graphicsWindowInputDevice.h @@ -54,7 +54,7 @@ public: INLINE bool has_pointer() const; INLINE bool has_keyboard() const; - INLINE const MouseData &get_mouse_data() const; + INLINE const MouseData &get_pointer() const; bool has_button_event() const; ButtonEvent get_button_event(); diff --git a/panda/src/glxdisplay/glxGraphicsWindow.cxx b/panda/src/glxdisplay/glxGraphicsWindow.cxx index 9b99722af8..505bb2eba7 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.cxx +++ b/panda/src/glxdisplay/glxGraphicsWindow.cxx @@ -68,6 +68,31 @@ glxGraphicsWindow:: ~glxGraphicsWindow() { } +//////////////////////////////////////////////////////////////////// +// Function: glxGraphicsWindow::move_pointer +// Access: Published, Virtual +// Description: Forces the pointer to the indicated position within +// the window, if possible. +// +// Returns true if successful, false on failure. This +// may fail if the mouse is not currently within the +// window, or if the API doesn't support this operation. +//////////////////////////////////////////////////////////////////// +bool glxGraphicsWindow:: +move_pointer(int device, int x, int y) { + // Note: this is not thread-safe; it should be called only from App. + // Probably not an issue. + nassertr(device == 0, false); + if (!_input_devices[0].get_pointer().get_in_window()) { + // If the mouse isn't currently within the window, forget it. + return false; + } + + XWarpPointer(_display, None, _xwindow, 0, 0, 0, 0, x, y); + _input_devices[0].set_pointer_in_window(x, y); + return true; +} + //////////////////////////////////////////////////////////////////// // Function: glxGraphicsWindow::make_context // Access: Public, Virtual diff --git a/panda/src/glxdisplay/glxGraphicsWindow.h b/panda/src/glxdisplay/glxGraphicsWindow.h index 2dd473f074..99e0b24a72 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.h +++ b/panda/src/glxdisplay/glxGraphicsWindow.h @@ -36,6 +36,8 @@ public: const string &name); virtual ~glxGraphicsWindow(); + virtual bool move_pointer(int device, int x, int y); + virtual bool make_context(); virtual void make_current(); virtual void release_gsg(); diff --git a/panda/src/putil/mouseData.I b/panda/src/putil/mouseData.I index 2168e0775f..51e9ac2efc 100644 --- a/panda/src/putil/mouseData.I +++ b/panda/src/putil/mouseData.I @@ -83,3 +83,9 @@ INLINE bool MouseData:: get_in_window() const { return _in_window; } + + +INLINE ostream &operator << (ostream &out, const MouseData &md) { + md.output(out); + return out; +} diff --git a/panda/src/putil/mouseData.cxx b/panda/src/putil/mouseData.cxx index a04c3b12c5..64eb9af752 100644 --- a/panda/src/putil/mouseData.cxx +++ b/panda/src/putil/mouseData.cxx @@ -17,3 +17,17 @@ //////////////////////////////////////////////////////////////////// #include "mouseData.h" + +//////////////////////////////////////////////////////////////////// +// Function: MouseData::output +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void MouseData:: +output(ostream &out) const { + if (!_in_window) { + out << "MouseData: Not in window"; + } else { + out << "MouseData: (" << _xpos << ", " << _ypos << ")"; + } +} diff --git a/panda/src/putil/mouseData.h b/panda/src/putil/mouseData.h index 24b825a6a6..8cb5173766 100644 --- a/panda/src/putil/mouseData.h +++ b/panda/src/putil/mouseData.h @@ -39,12 +39,16 @@ PUBLISHED: INLINE int get_y() const; INLINE bool get_in_window() const; + void output(ostream &out) const; + public: bool _in_window; int _xpos; int _ypos; }; +INLINE ostream &operator << (ostream &out, const MouseData &md); + #include "mouseData.I" #endif