Platform/Unix/X11Mouse: adding a basic implementation to get things going.
This commit is contained in:
parent
6426679845
commit
dd8a4a0583
2 changed files with 87 additions and 1 deletions
|
|
@ -1,15 +1,33 @@
|
|||
|
||||
#include <Spectre/System/Event.h>
|
||||
#include <Spectre/System/Log.h>
|
||||
#include "X11Mouse.h"
|
||||
|
||||
#include "X11SharedDisplay.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
X11Mouse::X11Mouse() :
|
||||
m_disp(NULL),
|
||||
m_btn_state(0)
|
||||
{
|
||||
}
|
||||
|
||||
X11Mouse::~X11Mouse()
|
||||
{
|
||||
if (m_disp) {
|
||||
XReleaseDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
void X11Mouse::init()
|
||||
{
|
||||
|
||||
m_disp = XGetDisplay();
|
||||
}
|
||||
|
||||
Vector2f X11Mouse::getPosition() const
|
||||
{
|
||||
// TODO: Translate to window.
|
||||
return m_position;
|
||||
}
|
||||
|
||||
|
|
@ -20,12 +38,68 @@ Vector2f X11Mouse::getAbsPosition() const
|
|||
|
||||
bool X11Mouse::isButtonDown(Mouse::Button button) const
|
||||
{
|
||||
// TODO: Button1 and 2 is defined in x11 and
|
||||
// therefore clashes with Mouse::Button::Button1 and 2.
|
||||
switch(button) {
|
||||
case Mouse::Button::Left :
|
||||
return m_btn_state & Button1Mask;
|
||||
case Mouse::Button::Right :
|
||||
return m_btn_state & Button3Mask;
|
||||
case Mouse::Button::Middle :
|
||||
return m_btn_state & Button2Mask;
|
||||
default :
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void X11Mouse::update(InputModule *input)
|
||||
{
|
||||
::Window root, child;
|
||||
int rx, ry, x = 0, y = 0;
|
||||
|
||||
// Query position and button state.
|
||||
XQueryPointer(m_disp, ::XDefaultRootWindow(m_disp),
|
||||
&root, &child,
|
||||
&rx, &ry,
|
||||
&x, &y, &m_btn_state);
|
||||
|
||||
// Update position
|
||||
m_position.x = x;
|
||||
m_position.y = y;
|
||||
}
|
||||
|
||||
bool X11Mouse::handleMessage(XEvent* xevent, Event& event)
|
||||
{
|
||||
if (xevent->type == MotionNotify) {
|
||||
event.type = Event::MouseMove;
|
||||
event.mouseMove.x = xevent->xmotion.x;
|
||||
event.mouseMove.y = xevent->xmotion.y;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (xevent->type == ButtonPress || xevent->type == ButtonRelease) {
|
||||
|
||||
Mouse::Button trans = Mouse::Button::Unknown;
|
||||
|
||||
switch(xevent->xbutton.button) {
|
||||
case Button1 : trans = Mouse::Button::Left; break;
|
||||
case Button2 : trans = Mouse::Button::Middle; break;
|
||||
case Button3 : trans = Mouse::Button::Right; break;
|
||||
// TODO: name clash, need to rename Mouse::Button enums.
|
||||
// case Button4 : trans = Mouse::Button::Button1; break; // clashes with X11's "Button1" define.
|
||||
// case Button5 : trans = Mouse::Button::Button2; break; // clashes with X11's "Button2" define.
|
||||
}
|
||||
|
||||
if (trans != Mouse::Button::Unknown) {
|
||||
event.type = Event::MouseButton;
|
||||
event.mouseButton.pressed = xevent->type == ButtonPress;
|
||||
event.mouseButton.button = trans;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue