Browse Source

expose GraphicsWindow::get_pointer and move_pointer

David Rose 22 years ago
parent
commit
d561b66713

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

@@ -84,7 +84,7 @@ do_transmit_data(const DataNodeTransmit &, DataNodeTransmit &output) {
   }
   }
 
 
   if (_window->has_pointer(_device)) {
   if (_window->has_pointer(_device)) {
-    const MouseData &mdata = _window->get_mouse_data(_device);
+    const MouseData &mdata = _window->get_pointer(_device);
 
 
     if (mdata._in_window) {
     if (mdata._in_window) {
       // Get mouse motion in pixels.
       // Get mouse motion in pixels.

+ 20 - 5
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
 //  Description: Returns the MouseData associated with the nth input
-//               device.
+//               device's pointer.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 MouseData GraphicsWindow::
 MouseData GraphicsWindow::
-get_mouse_data(int device) const {
+get_pointer(int device) const {
   MouseData result;
   MouseData result;
   {
   {
     MutexHolder holder(_input_lock);
     MutexHolder holder(_input_lock);
     nassertr(device >= 0 && device < (int)_input_devices.size(), MouseData());
     nassertr(device >= 0 && device < (int)_input_devices.size(), MouseData());
-    result = _input_devices[device].get_mouse_data();
+    result = _input_devices[device].get_pointer();
   }
   }
   return result;
   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
 //     Function: GraphicsWindow::has_button_event
 //       Access: Public
 //       Access: Public

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

@@ -63,9 +63,11 @@ PUBLISHED:
   bool has_pointer(int device) const;
   bool has_pointer(int device) const;
   bool has_keyboard(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:
 public:
   // No need to publish these.
   // No need to publish these.
-  MouseData get_mouse_data(int device) const;
   bool has_button_event(int device) const;
   bool has_button_event(int device) const;
   ButtonEvent get_button_event(int device);
   ButtonEvent get_button_event(int device);
 
 

+ 4 - 4
panda/src/display/graphicsWindowInputDevice.I

@@ -57,13 +57,13 @@ has_keyboard() const {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: GraphicsWindowInputDevice::get_mouse_data
+//     Function: GraphicsWindowInputDevice::get_pointer
 //       Access: Public
 //       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::
 INLINE const MouseData &GraphicsWindowInputDevice::
-get_mouse_data() const {
+get_pointer() const {
   return _mouse_data;
   return _mouse_data;
 }
 }
 
 

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

@@ -54,7 +54,7 @@ public:
   INLINE bool has_pointer() const;
   INLINE bool has_pointer() const;
   INLINE bool has_keyboard() const;
   INLINE bool has_keyboard() const;
 
 
-  INLINE const MouseData &get_mouse_data() const;
+  INLINE const MouseData &get_pointer() const;
 
 
   bool has_button_event() const;
   bool has_button_event() const;
   ButtonEvent get_button_event();
   ButtonEvent get_button_event();

+ 25 - 0
panda/src/glxdisplay/glxGraphicsWindow.cxx

@@ -68,6 +68,31 @@ glxGraphicsWindow::
 ~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
 //     Function: glxGraphicsWindow::make_context
 //       Access: Public, Virtual
 //       Access: Public, Virtual

+ 2 - 0
panda/src/glxdisplay/glxGraphicsWindow.h

@@ -36,6 +36,8 @@ public:
                     const string &name);
                     const string &name);
   virtual ~glxGraphicsWindow();
   virtual ~glxGraphicsWindow();
 
 
+  virtual bool move_pointer(int device, int x, int y);
+
   virtual bool make_context();
   virtual bool make_context();
   virtual void make_current();
   virtual void make_current();
   virtual void release_gsg();
   virtual void release_gsg();

+ 6 - 0
panda/src/putil/mouseData.I

@@ -83,3 +83,9 @@ INLINE bool MouseData::
 get_in_window() const {
 get_in_window() const {
   return _in_window;
   return _in_window;
 }
 }
+
+
+INLINE ostream &operator << (ostream &out, const MouseData &md) {
+  md.output(out);
+  return out;
+}

+ 14 - 0
panda/src/putil/mouseData.cxx

@@ -17,3 +17,17 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 
 
 #include "mouseData.h"
 #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 << ")";
+  }
+}

+ 4 - 0
panda/src/putil/mouseData.h

@@ -39,12 +39,16 @@ PUBLISHED:
   INLINE int get_y() const;
   INLINE int get_y() const;
   INLINE bool get_in_window() const;
   INLINE bool get_in_window() const;
 
 
+  void output(ostream &out) const;
+
 public:
 public:
   bool _in_window;
   bool _in_window;
   int _xpos;
   int _xpos;
   int _ypos;
   int _ypos;
 };
 };
 
 
+INLINE ostream &operator << (ostream &out, const MouseData &md);
+
 #include "mouseData.I"
 #include "mouseData.I"
 
 
 #endif
 #endif