mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
expose GraphicsWindow::get_pointer and move_pointer
This commit is contained in:
parent
d1f9162c8e
commit
d561b66713
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 << ")";
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user