Simplify cursor position in Mouse even more - get rid of hairy window rect code
This commit is contained in:
parent
f89c212848
commit
0aea2bccd0
|
@ -58,7 +58,6 @@ static bool mCreate_success; // bool used to determine successfull creat
|
||||||
static bool mFirstTimeInitialization = true; // boolean to determine first time initialization
|
static bool mFirstTimeInitialization = true; // boolean to determine first time initialization
|
||||||
|
|
||||||
static POINT cursorPos;
|
static POINT cursorPos;
|
||||||
static RECT windowRect;
|
|
||||||
static bool mouse_grabbed;
|
static bool mouse_grabbed;
|
||||||
static int mouseMask = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
|
static int mouseMask = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
|
||||||
|
|
||||||
|
@ -71,27 +70,10 @@ void SetupMouse();
|
||||||
void InitializeMouseFields();
|
void InitializeMouseFields();
|
||||||
void UpdateMouseFields(JNIEnv *env, jclass clsMouse, jobject coord_buffer_obj, jobject button_buffer_obj);
|
void UpdateMouseFields(JNIEnv *env, jclass clsMouse, jobject coord_buffer_obj, jobject button_buffer_obj);
|
||||||
|
|
||||||
/* Return the RECT of the current client area in the current window
|
|
||||||
* in screen coordinates
|
|
||||||
*/
|
|
||||||
static void getScreenClientRect(RECT* screen_client_rect)
|
|
||||||
{
|
|
||||||
/* We can't use GetClientRect directly, because it is in
|
|
||||||
* local window coordinates and we can't use GetWindowRect
|
|
||||||
* because it returns the screen coordinate RECT of the entire
|
|
||||||
* window, inluding decoration. Luckily, the WINDOWINFO structure contains
|
|
||||||
* the client rect in screen coordinates.
|
|
||||||
*/
|
|
||||||
WINDOWINFO window_info;
|
|
||||||
window_info.cbSize = sizeof(WINDOWINFO);
|
|
||||||
GetWindowInfo(getCurrentHWND(), &window_info);
|
|
||||||
*screen_client_rect = window_info.rcClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void resetCursorPos(void) {
|
static void resetCursorPos(void) {
|
||||||
/* Reset cursor position to middle of the window */
|
/* Reset cursor position to middle of the window */
|
||||||
RECT clientRect;
|
RECT clientRect;
|
||||||
getScreenClientRect(&clientRect);
|
GetClientRect(getCurrentHWND(), &clientRect);
|
||||||
cursorPos.x = (clientRect.left + clientRect.right)/2;
|
cursorPos.x = (clientRect.left + clientRect.right)/2;
|
||||||
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
|
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
|
||||||
}
|
}
|
||||||
|
@ -401,17 +383,13 @@ static void getGDICursorDelta(int* return_dx, int* return_dy) {
|
||||||
int dy;
|
int dy;
|
||||||
|
|
||||||
POINT newCursorPos;
|
POINT newCursorPos;
|
||||||
GetCursorPos(&newCursorPos);
|
|
||||||
RECT clientRect;
|
RECT clientRect;
|
||||||
RECT newWindowRect;
|
GetCursorPos(&newCursorPos);
|
||||||
GetWindowRect(getCurrentHWND(), &newWindowRect);
|
ScreenToClient(getCurrentHWND(), &newCursorPos);
|
||||||
cursorPos.x += newWindowRect.left - windowRect.left;
|
GetClientRect(getCurrentHWND(), &clientRect);
|
||||||
cursorPos.y += newWindowRect.top - windowRect.top;
|
|
||||||
windowRect = newWindowRect;
|
|
||||||
getScreenClientRect(&clientRect);
|
|
||||||
// Clip the position to the client rect
|
|
||||||
newCursorPos.x = cap(newCursorPos.x, clientRect.left, clientRect.right - 1);
|
newCursorPos.x = cap(newCursorPos.x, clientRect.left, clientRect.right - 1);
|
||||||
newCursorPos.y = cap(newCursorPos.y, clientRect.top, clientRect.bottom - 1);
|
newCursorPos.y = cap(newCursorPos.y, clientRect.top, clientRect.bottom - 1);
|
||||||
|
// Clip the position to the client rect
|
||||||
dx = newCursorPos.x - cursorPos.x;
|
dx = newCursorPos.x - cursorPos.x;
|
||||||
dy = newCursorPos.y - cursorPos.y;
|
dy = newCursorPos.y - cursorPos.y;
|
||||||
cursorPos.x += dx;
|
cursorPos.x += dx;
|
||||||
|
|
Loading…
Reference in New Issue