Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Date: Sun, 07 Dec 2008 13:35:23 +0100
From: Couriersud
Subject: SDL: Mouse last_x, last_y into SDL_Mouse

the attached diff moves the static vars last_x and last_y into
SDL_Mouse. These, as far as I understand it, should be tied to the
individual mouse.

The patch also makes the code check for out of window conditions of
mouse->x,y when relative movements are passed to MouseSendMotion.

Also attached is the latest DirectFB code (dfb20081208) supporting
multiple mice and keyboards. This works quite well with sdlmame now. It
however needs more testing with different directfb configurations.
  • Loading branch information
slouken committed Dec 8, 2008
1 parent fd3a9cb commit 14055323675f6bd367e85760b8ada88de2e88e34
@@ -33,7 +33,6 @@ static int SDL_current_mouse = -1;
static SDL_Mouse **SDL_mice = NULL;
static int *SDL_IdIndex = NULL;
static int SDL_highestId = -1;
static int last_x, last_y; /* the last reported x and y coordinates by the system cursor */


/* Public functions */
@@ -61,12 +60,15 @@ SDL_SetMouseIndexId(int id, int index)
}
if (id > SDL_highestId) {
int *indexes;
int i;
indexes = (int *) SDL_realloc(SDL_IdIndex, (id + 1) * sizeof(int));
if (!indexes) {
SDL_OutOfMemory();
return -1;
}
SDL_IdIndex = indexes;
for (i = SDL_highestId + 1; i <= id; i++)
SDL_IdIndex[i] = -1;
SDL_IdIndex[id] = index;
SDL_highestId = id;
} else {
@@ -378,8 +380,8 @@ SDL_SendProximity(int id, int x, int y, int type)
return 0;
}

last_x = x;
last_y = y;
mouse->last_x = x;
mouse->last_y = y;
if (SDL_ProcessEvents[type] == SDL_ENABLE) {
SDL_Event event;
event.proximity.which = (Uint8) index;
@@ -405,27 +407,28 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
int posted;
int xrel;
int yrel;
int x_max = 0, y_max = 0;

if (!mouse || mouse->flush_motion) {
return 0;
}

/* if the mouse is out of proximity we don't to want to have any motion from it */
if (mouse->proximity == SDL_FALSE) {
last_x = x;
last_y = y;
mouse->last_x = x;
mouse->last_y = y;
return 0;
}

/* the relative motion is calculated regarding the system cursor last position */
if (relative) {
xrel = x;
yrel = y;
x = (last_x + x);
y = (last_y + y);
x = (mouse->last_x + x);
y = (mouse->last_y + y);
} else {
xrel = x - last_x;
yrel = y - last_y;
xrel = x - mouse->last_x;
yrel = y - mouse->last_y;
}

/* Drop events that don't change state */
@@ -441,27 +444,26 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
mouse->x = x;
mouse->y = y;
} else {
/* while using the relative mode and many windows, we have to be
sure that the pointers find themselves inside the windows */
int x_max, y_max;
mouse->x += xrel;
mouse->y += yrel;
}

SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
SDL_GetWindowSize(mouse->focus, &x_max, &y_max);

if (mouse->x + xrel > x_max) {
mouse->x = x_max;
} else if (mouse->x + xrel < 0) {
mouse->x = 0;
} else {
mouse->x += xrel;
}
if (mouse->y + yrel > y_max) {
mouse->y = y_max;
} else if (mouse->y + yrel < 0) {
mouse->y = 0;
} else {
mouse->y += yrel;
}
/* make sure that the pointers find themselves inside the windows */
/* only check if mouse->xmax is set ! */
if (x_max && mouse->x > x_max) {
mouse->x = x_max;
} else if (mouse->x < 0) {
mouse->x = 0;
}

if (y_max && mouse->y > y_max) {
mouse->y = y_max;
} else if (mouse->y < 0) {
mouse->y = 0;
}

mouse->xdelta += xrel;
mouse->ydelta += yrel;
mouse->pressure = pressure;
@@ -491,8 +493,8 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
event.motion.cursor = mouse->current_end;
posted = (SDL_PushEvent(&event) > 0);
}
last_x = x;
last_y = y;
mouse->last_x = x;
mouse->last_y = y;
return posted;
}

@@ -71,6 +71,7 @@ struct SDL_Mouse
int z; /* for future use */
int xdelta;
int ydelta;
int last_x, last_y; /* the last reported x and y coordinates */
char *name;
Uint8 buttonstate;
SDL_bool relative_mode;
@@ -1054,7 +1054,7 @@ SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *h)
{
SDL_Window *window = SDL_GetWindowFromID(windowID);

if (!window) {
if (window) {
if (w) {
*w = window->w;
}

0 comments on commit 1405532

Please sign in to comment.