mirror of https://github.com/encounter/SDL.git
haiku: Add support for relative mouse mode.
Partially fixes Bugzilla #4442.
This commit is contained in:
parent
bd648bd5a3
commit
95a402d745
|
@ -228,7 +228,6 @@ private:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
win = GetSDLWindow(winID);
|
win = GetSDLWindow(winID);
|
||||||
SDL_SendMouseMotion(win, 0, 0, x, y);
|
|
||||||
|
|
||||||
// Simple relative mode support for mouse.
|
// Simple relative mode support for mouse.
|
||||||
if ((SDL_GetMouse()->relative_mode ||
|
if ((SDL_GetMouse()->relative_mode ||
|
||||||
|
@ -237,10 +236,14 @@ private:
|
||||||
int winWidth, winHeight, winPosX, winPosY;
|
int winWidth, winHeight, winPosX, winPosY;
|
||||||
SDL_GetWindowSize(win, &winWidth, &winHeight);
|
SDL_GetWindowSize(win, &winWidth, &winHeight);
|
||||||
SDL_GetWindowPosition(win, &winPosX, &winPosY);
|
SDL_GetWindowPosition(win, &winPosX, &winPosY);
|
||||||
|
int dx = x - (winWidth / 2);
|
||||||
|
int dy = y - (winHeight / 2);
|
||||||
|
SDL_SendMouseMotion(win, 0, SDL_GetMouse()->relative_mode, dx, dy);
|
||||||
set_mouse_position((winPosX + winWidth / 2), (winPosY + winHeight / 2));
|
set_mouse_position((winPosX + winWidth / 2), (winPosY + winHeight / 2));
|
||||||
if (!be_app->IsCursorHidden())
|
if (!be_app->IsCursorHidden())
|
||||||
be_app->HideCursor();
|
be_app->HideCursor();
|
||||||
} else {
|
} else {
|
||||||
|
SDL_SendMouseMotion(win, 0, 0, x, y);
|
||||||
if (be_app->IsCursorHidden())
|
if (be_app->IsCursorHidden())
|
||||||
be_app->ShowCursor();
|
be_app->ShowCursor();
|
||||||
}
|
}
|
||||||
|
|
|
@ -319,22 +319,17 @@ class SDL_BWin:public BDirectWindow
|
||||||
&& msg->FindInt32("be:transit", &transit) == B_OK) {
|
&& msg->FindInt32("be:transit", &transit) == B_OK) {
|
||||||
_MouseMotionEvent(where, transit);
|
_MouseMotionEvent(where, transit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: Apparently a button press/release event might be dropped
|
|
||||||
if made before before a different button is released. Does
|
|
||||||
B_MOUSE_MOVED have the data needed to check if a mouse button
|
|
||||||
state has changed? */
|
|
||||||
if (msg->FindInt32("buttons", &buttons) == B_OK) {
|
|
||||||
_MouseButtonEvent(buttons);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_MOUSE_DOWN:
|
case B_MOUSE_DOWN:
|
||||||
case B_MOUSE_UP:
|
|
||||||
/* _MouseButtonEvent() detects any and all buttons that may have
|
|
||||||
changed state, as well as that button's new state */
|
|
||||||
if (msg->FindInt32("buttons", &buttons) == B_OK) {
|
if (msg->FindInt32("buttons", &buttons) == B_OK) {
|
||||||
_MouseButtonEvent(buttons);
|
_MouseButtonEvent(buttons, SDL_PRESSED);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_MOUSE_UP:
|
||||||
|
if (msg->FindInt32("buttons", &buttons) == B_OK) {
|
||||||
|
_MouseButtonEvent(buttons, SDL_RELEASED);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -497,26 +492,17 @@ private:
|
||||||
if true: SDL_SetCursor(NULL); */
|
if true: SDL_SetCursor(NULL); */
|
||||||
}
|
}
|
||||||
|
|
||||||
void _MouseButtonEvent(int32 buttons) {
|
void _MouseButtonEvent(int32 buttons, Uint8 state) {
|
||||||
int32 buttonStateChange = buttons ^ _last_buttons;
|
int32 buttonStateChange = buttons ^ _last_buttons;
|
||||||
|
|
||||||
/* Make sure at least one button has changed state */
|
|
||||||
if( !(buttonStateChange) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add any mouse button events */
|
|
||||||
if(buttonStateChange & B_PRIMARY_MOUSE_BUTTON) {
|
if(buttonStateChange & B_PRIMARY_MOUSE_BUTTON) {
|
||||||
_SendMouseButton(SDL_BUTTON_LEFT, buttons &
|
_SendMouseButton(SDL_BUTTON_LEFT, state);
|
||||||
B_PRIMARY_MOUSE_BUTTON);
|
|
||||||
}
|
}
|
||||||
if(buttonStateChange & B_SECONDARY_MOUSE_BUTTON) {
|
if(buttonStateChange & B_SECONDARY_MOUSE_BUTTON) {
|
||||||
_SendMouseButton(SDL_BUTTON_RIGHT, buttons &
|
_SendMouseButton(SDL_BUTTON_RIGHT, state);
|
||||||
B_PRIMARY_MOUSE_BUTTON);
|
|
||||||
}
|
}
|
||||||
if(buttonStateChange & B_TERTIARY_MOUSE_BUTTON) {
|
if(buttonStateChange & B_TERTIARY_MOUSE_BUTTON) {
|
||||||
_SendMouseButton(SDL_BUTTON_MIDDLE, buttons &
|
_SendMouseButton(SDL_BUTTON_MIDDLE, state);
|
||||||
B_PRIMARY_MOUSE_BUTTON);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_last_buttons = buttons;
|
_last_buttons = buttons;
|
||||||
|
|
Loading…
Reference in New Issue