From 51e558e1be1166a2a54d59d6aff8306951ee8761 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 26 Oct 2010 15:22:17 -0700 Subject: [PATCH] Add jmouse_release/capture functions. --- src/gui/jsystem.cpp | 39 +++++++++++++++++++++++++++++++++++---- src/gui/jsystem.h | 3 +++ src/gui/widget.cpp | 13 ++----------- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/gui/jsystem.cpp b/src/gui/jsystem.cpp index 09b3562d9..fa654c2be 100644 --- a/src/gui/jsystem.cpp +++ b/src/gui/jsystem.cpp @@ -7,8 +7,10 @@ #include "config.h" #include -#ifdef ALLEGRO_WINDOWS -#include +#if defined(ALLEGRO_WINDOWS) + #include +#elif defined(ALLEGRO_UNIX) + #include #endif #include "gui/jintern.h" @@ -362,6 +364,35 @@ void jmouse_set_position(int x, int y) } } +void jmouse_capture() +{ +#if defined(ALLEGRO_WINDOWS) + + SetCapture(win_get_window()); + +#elif defined(ALLEGRO_UNIX) + + XGrabPointer(_xwin.display, _xwin.window, False, + PointerMotionMask | ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, + None, None, CurrentTime); + +#endif +} + +void jmouse_release() +{ +#if defined(ALLEGRO_WINDOWS) + + ::ReleaseCapture(); + +#elif defined(ALLEGRO_UNIX) + + XUngrabPointer(_xwin.display, CurrentTime); + +#endif +} + int jmouse_x(int antique) { return m_x[antique & 1]; } int jmouse_y(int antique) { return m_y[antique & 1]; } int jmouse_z(int antique) { return m_z[antique & 1]; } @@ -407,10 +438,10 @@ static void update_mouse_position() m_y[0] = JI_SCREEN_H * mouse_y / SCREEN_H; } + if (is_windowed_mode()) { #ifdef ALLEGRO_WINDOWS /* this help us (in windows) to get mouse feedback when we capture the mouse but we are outside the Allegro window */ - if (is_windowed_mode()) { POINT pt; RECT rc; @@ -443,8 +474,8 @@ static void update_mouse_position() } } } - } #endif + } } static void capture_covered_area() diff --git a/src/gui/jsystem.h b/src/gui/jsystem.h index f311b91ae..76efc298f 100644 --- a/src/gui/jsystem.h +++ b/src/gui/jsystem.h @@ -70,6 +70,9 @@ bool jmouse_is_shown(); bool jmouse_poll(); void jmouse_set_position(int x, int y); +void jmouse_capture(); +void jmouse_release(); + int jmouse_b(int antique); int jmouse_x(int antique); int jmouse_y(int antique); diff --git a/src/gui/widget.cpp b/src/gui/widget.cpp index 86ca92881..2a714fbb5 100644 --- a/src/gui/widget.cpp +++ b/src/gui/widget.cpp @@ -17,9 +17,6 @@ # include #endif #include -#ifdef ALLEGRO_WINDOWS -#include -#endif #include "gui/jinete.h" #include "gui/jintern.h" @@ -1401,10 +1398,7 @@ void Widget::captureMouse() { if (!jmanager_get_capture()) { jmanager_set_capture(this); - -#ifdef ALLEGRO_WINDOWS - SetCapture(win_get_window()); -#endif + jmouse_capture(); } } @@ -1415,10 +1409,7 @@ void Widget::releaseMouse() { if (jmanager_get_capture() == this) { jmanager_free_capture(); - -#ifdef ALLEGRO_WINDOWS - ::ReleaseCapture(); // Win32 API -#endif + jmouse_release(); } }