Add jmouse_release/capture functions.

This commit is contained in:
David Capello 2010-10-26 15:22:17 -07:00
parent 7341d3b091
commit 51e558e1be
3 changed files with 40 additions and 15 deletions

View File

@ -7,8 +7,10 @@
#include "config.h"
#include <allegro.h>
#ifdef ALLEGRO_WINDOWS
#include <winalleg.h>
#if defined(ALLEGRO_WINDOWS)
#include <winalleg.h>
#elif defined(ALLEGRO_UNIX)
#include <xalleg.h>
#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()

View File

@ -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);

View File

@ -17,9 +17,6 @@
# include <cstdio>
#endif
#include <allegro.h>
#ifdef ALLEGRO_WINDOWS
#include <winalleg.h>
#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();
}
}