Fixed mouse coordinate range on Mac OS X
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403255
This commit is contained in:
parent
be449ce8ef
commit
ad090cd0f8
5 changed files with 33 additions and 37 deletions
|
@ -34,7 +34,6 @@ static SDL_Mouse **SDL_mice = NULL;
|
||||||
static int *SDL_IdIndex = NULL;
|
static int *SDL_IdIndex = NULL;
|
||||||
static int SDL_highestId = -1;
|
static int SDL_highestId = -1;
|
||||||
static int last_x, last_y; /* the last reported x and y coordinates by the system cursor */
|
static int last_x, last_y; /* the last reported x and y coordinates by the system cursor */
|
||||||
int x_max, y_max; /* current window width and height */
|
|
||||||
|
|
||||||
|
|
||||||
/* Public functions */
|
/* Public functions */
|
||||||
|
@ -365,6 +364,21 @@ SDL_SetMouseFocus(int id, SDL_WindowID windowID)
|
||||||
if (!focus) {
|
if (!focus) {
|
||||||
SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
|
SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
|
||||||
}
|
}
|
||||||
|
SDL_GetWindowSize(windowID, &mouse->x_max, &mouse->y_max);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SDL_SetMouseFocusSize(SDL_WindowID windowID, int w, int h)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < SDL_num_mice; ++i) {
|
||||||
|
SDL_Mouse *mouse = SDL_GetMouse(i);
|
||||||
|
if (mouse && mouse->focus == windowID) {
|
||||||
|
mouse->x_max = w;
|
||||||
|
mouse->y_max = h;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,15 +421,6 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
|
||||||
int xrel;
|
int xrel;
|
||||||
int yrel;
|
int yrel;
|
||||||
|
|
||||||
/* while using the relative mode and many windows, we have to be sure,
|
|
||||||
that the pointers find themselves inside the windows */
|
|
||||||
if (x > x_max) {
|
|
||||||
x = x_max;
|
|
||||||
}
|
|
||||||
if (y > y_max) {
|
|
||||||
y = y_max;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mouse || mouse->flush_motion) {
|
if (!mouse || mouse->flush_motion) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -445,15 +450,17 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
|
||||||
mouse->x = x;
|
mouse->x = x;
|
||||||
mouse->y = y;
|
mouse->y = y;
|
||||||
} else {
|
} else {
|
||||||
if (mouse->x + xrel > x_max) {
|
/* while using the relative mode and many windows, we have to be
|
||||||
mouse->x = x_max;
|
sure that the pointers find themselves inside the windows */
|
||||||
|
if (mouse->x + xrel > mouse->x_max) {
|
||||||
|
mouse->x = mouse->x_max;
|
||||||
} else if (mouse->x + xrel < 0) {
|
} else if (mouse->x + xrel < 0) {
|
||||||
mouse->x = 0;
|
mouse->x = 0;
|
||||||
} else {
|
} else {
|
||||||
mouse->x += xrel;
|
mouse->x += xrel;
|
||||||
}
|
}
|
||||||
if (mouse->y + yrel > y_max) {
|
if (mouse->y + yrel > mouse->y_max) {
|
||||||
mouse->y = y_max;
|
mouse->y = mouse->y_max;
|
||||||
} else if (mouse->y + yrel < 0) {
|
} else if (mouse->y + yrel < 0) {
|
||||||
mouse->y = 0;
|
mouse->y = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -778,13 +785,6 @@ SDL_GetMouseName(int index)
|
||||||
return mouse->name;
|
return mouse->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
SDL_UpdateCoordinates(int x, int y)
|
|
||||||
{
|
|
||||||
x_max = x;
|
|
||||||
y_max = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SDL_ChangeEnd(int id, int end)
|
SDL_ChangeEnd(int id, int end)
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,8 +66,8 @@ struct SDL_Mouse
|
||||||
/* Data common to all mice */
|
/* Data common to all mice */
|
||||||
SDL_WindowID focus;
|
SDL_WindowID focus;
|
||||||
int which;
|
int which;
|
||||||
int x;
|
int x, x_max;
|
||||||
int y;
|
int y, y_max;
|
||||||
int z; /* for future use */
|
int z; /* for future use */
|
||||||
int xdelta;
|
int xdelta;
|
||||||
int ydelta;
|
int ydelta;
|
||||||
|
@ -112,6 +112,9 @@ extern void SDL_ResetMouse(int index);
|
||||||
/* Set the mouse focus window */
|
/* Set the mouse focus window */
|
||||||
extern void SDL_SetMouseFocus(int id, SDL_WindowID windowID);
|
extern void SDL_SetMouseFocus(int id, SDL_WindowID windowID);
|
||||||
|
|
||||||
|
/* Set the size of the mouse focus window */
|
||||||
|
extern void SDL_SetMouseFocusSize(SDL_WindowID windowID, int w, int h);
|
||||||
|
|
||||||
/* Send a mouse motion event for a mouse */
|
/* Send a mouse motion event for a mouse */
|
||||||
extern int SDL_SendMouseMotion(int id, int relative, int x, int y, int z);
|
extern int SDL_SendMouseMotion(int id, int relative, int x, int y, int z);
|
||||||
|
|
||||||
|
@ -128,7 +131,6 @@ extern int SDL_SendProximity(int id, int x, int y, int type);
|
||||||
extern void SDL_MouseQuit(void);
|
extern void SDL_MouseQuit(void);
|
||||||
|
|
||||||
/* FIXME: Where do these functions go in this header? */
|
/* FIXME: Where do these functions go in this header? */
|
||||||
extern void SDL_UpdateCoordinates(int x, int y);
|
|
||||||
extern void SDL_ChangeEnd(int id, int end);
|
extern void SDL_ChangeEnd(int id, int end);
|
||||||
|
|
||||||
#endif /* _SDL_mouse_c_h */
|
#endif /* _SDL_mouse_c_h */
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "SDL_events.h"
|
#include "SDL_events.h"
|
||||||
#include "SDL_events_c.h"
|
#include "SDL_events_c.h"
|
||||||
|
#include "SDL_mouse_c.h"
|
||||||
#include "../video/SDL_sysvideo.h"
|
#include "../video/SDL_sysvideo.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -73,6 +74,7 @@ SDL_SendWindowEvent(SDL_WindowID windowID, Uint8 windowevent, int data1,
|
||||||
window->w = data1;
|
window->w = data1;
|
||||||
window->h = data2;
|
window->h = data2;
|
||||||
SDL_OnWindowResized(window);
|
SDL_OnWindowResized(window);
|
||||||
|
SDL_SetMouseFocusSize(windowID, window->w, window->h);
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_MINIMIZED:
|
case SDL_WINDOWEVENT_MINIMIZED:
|
||||||
if (window->flags & SDL_WINDOW_MINIMIZED) {
|
if (window->flags & SDL_WINDOW_MINIMIZED) {
|
||||||
|
|
|
@ -240,13 +240,11 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* FIXME: Doesn't this defeat the point of using raw input? */
|
||||||
GetCursorPos(&point);
|
GetCursorPos(&point);
|
||||||
ScreenToClient(hwnd, &point);
|
|
||||||
SDL_GetWindowSize(data->windowID, &w, &h);
|
|
||||||
SDL_UpdateCoordinates(w, h); /* we're updating the current window size */
|
|
||||||
|
|
||||||
/* if the message was sent by a tablet we have to send also pressure */
|
/* if the message was sent by a tablet we have to send also pressure */
|
||||||
if (i == tablet) {
|
if (index == tablet) {
|
||||||
SDL_SendMouseMotion(index, 0, point.x, point.y, pressure);
|
SDL_SendMouseMotion(index, 0, point.x, point.y, pressure);
|
||||||
} else {
|
} else {
|
||||||
SDL_SendMouseMotion(index, 0, point.x, point.y, 0);
|
SDL_SendMouseMotion(index, 0, point.x, point.y, 0);
|
||||||
|
|
|
@ -278,16 +278,10 @@ X11_DispatchEvent(_THIS)
|
||||||
|
|
||||||
default:{
|
default:{
|
||||||
if (xevent.type == motion) { /* MotionNotify */
|
if (xevent.type == motion) { /* MotionNotify */
|
||||||
#ifdef DEBUG_MOTION
|
|
||||||
printf("X11 motion: %d,%d\n", xevent.xmotion.x,
|
|
||||||
xevent.xmotion.y);
|
|
||||||
#endif
|
|
||||||
XWindowAttributes attrib;
|
|
||||||
XGetWindowAttributes(videodata->display,
|
|
||||||
((XAnyEvent *) & xevent)->window,
|
|
||||||
&attrib);
|
|
||||||
SDL_UpdateCoordinates(attrib.width, attrib.height);
|
|
||||||
XDeviceMotionEvent *move = (XDeviceMotionEvent *) & xevent;
|
XDeviceMotionEvent *move = (XDeviceMotionEvent *) & xevent;
|
||||||
|
#ifdef DEBUG_MOTION
|
||||||
|
printf("X11 motion: %d,%d\n", move->x, move->y);
|
||||||
|
#endif
|
||||||
SDL_SendMouseMotion(move->deviceid, 0, move->x,
|
SDL_SendMouseMotion(move->deviceid, 0, move->x,
|
||||||
move->y, move->axis_data[2]);
|
move->y, move->axis_data[2]);
|
||||||
} else if (xevent.type == button_pressed) { /* ButtonPress */
|
} else if (xevent.type == button_pressed) { /* ButtonPress */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue