Move capture/release mouse function to she layer

This commit is contained in:
David Capello 2014-08-09 22:32:05 -03:00
parent 33706ce6ff
commit 4d4958bf35
6 changed files with 35 additions and 28 deletions

View File

@ -34,6 +34,8 @@
#ifndef WM_MOUSEHWHEEL
#define WM_MOUSEHWHEEL 0x020E
#endif
#elif defined(ALLEGRO_UNIX)
#include <xalleg.h>
#endif
#ifdef WIN32
@ -537,6 +539,33 @@ public:
m_scale * position.y);
}
void captureMouse() {
#ifdef WIN32
SetCapture((HWND)nativeHandle());
#elif defined(ALLEGRO_UNIX)
XGrabPointer(_xwin.display, _xwin.window, False,
PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
GrabModeAsync, GrabModeAsync,
None, None, CurrentTime);
#endif
}
void releaseMouse() {
#ifdef WIN32
ReleaseCapture();
#elif defined(ALLEGRO_UNIX)
XUngrabPointer(_xwin.display, CurrentTime);
#endif
}
void* nativeHandle() OVERRIDE {
#ifdef WIN32
return reinterpret_cast<void*>(win_get_window());

View File

@ -52,6 +52,8 @@ namespace she {
virtual EventQueue* getEventQueue() = 0;
virtual void setMousePosition(const gfx::Point& position) = 0;
virtual void captureMouse() = 0;
virtual void releaseMouse() = 0;
// Returns the HWND on Windows.
virtual void* nativeHandle() = 0;

View File

@ -891,6 +891,8 @@ void Manager::setCapture(Widget* widget)
{
widget->flags |= JI_HASCAPTURE;
capture_widget = widget;
m_display->captureMouse();
}
// Sets the focus to the "magnetic" widget inside the window
@ -929,6 +931,8 @@ void Manager::freeCapture()
if (capture_widget) {
capture_widget->flags &= ~JI_HASCAPTURE;
capture_widget = NULL;
m_display->releaseMouse();
}
}

View File

@ -24,8 +24,6 @@
#include <allegro.h>
#if defined(WIN32)
#include <winalleg.h>
#elif defined(ALLEGRO_UNIX)
#include <xalleg.h>
#endif
namespace ui {
@ -301,27 +299,6 @@ void set_mouse_position(const gfx::Point& newPos)
m_y[1] = m_y[0];
}
void jmouse_capture()
{
#if defined(ALLEGRO_UNIX)
XGrabPointer(_xwin.display, _xwin.window, False,
PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
GrabModeAsync, GrabModeAsync,
None, None, CurrentTime);
#endif
}
void jmouse_release()
{
#if defined(ALLEGRO_UNIX)
XUngrabPointer(_xwin.display, CurrentTime);
#endif
}
MouseButtons jmouse_b(int antique)
{
return (MouseButtons)m_b[antique & 1];

View File

@ -64,9 +64,6 @@ namespace ui {
gfx::Point get_mouse_position();
void set_mouse_position(const gfx::Point& newPos);
void jmouse_capture();
void jmouse_release();
MouseButtons jmouse_b(int antique);
int jmouse_x(int antique);
int jmouse_y(int antique);

View File

@ -1224,7 +1224,6 @@ void Widget::captureMouse()
{
if (!getManager()->getCapture()) {
getManager()->setCapture(this);
jmouse_capture();
}
}
@ -1235,7 +1234,6 @@ void Widget::releaseMouse()
{
if (getManager()->getCapture() == this) {
getManager()->freeCapture();
jmouse_release();
}
}