Simplify Mouse cursor positions and replace display_hwnd global variable with getCurrentHWND() (Win32)
This commit is contained in:
parent
90187ad798
commit
f89c212848
|
@ -52,16 +52,14 @@
|
||||||
#else
|
#else
|
||||||
#define WINDOW_H_API extern
|
#define WINDOW_H_API extern
|
||||||
|
|
||||||
extern HWND display_hwnd; // Handle to the window
|
|
||||||
// extern HDC display_hdc; // Device context
|
|
||||||
extern bool isFullScreen; // Whether we're fullscreen or not
|
extern bool isFullScreen; // Whether we're fullscreen or not
|
||||||
extern bool isMinimized; // Whether we're minimized or not
|
extern bool isMinimized; // Whether we're minimized or not
|
||||||
extern bool isFocused; // Whether we're focused or not
|
extern bool isFocused; // Whether we're focused or not
|
||||||
extern bool isDirty; // Whether we're dirty or not
|
extern bool isDirty; // Whether we're dirty or not
|
||||||
extern RECT clientSize;
|
|
||||||
// extern HGLRC display_hglrc;
|
|
||||||
#endif /* _PRIVATE_WINDOW_H_ */
|
#endif /* _PRIVATE_WINDOW_H_ */
|
||||||
|
|
||||||
|
WINDOW_H_API HWND getCurrentHWND();
|
||||||
|
|
||||||
WINDOW_H_API HDC getCurrentWindowDC();
|
WINDOW_H_API HDC getCurrentWindowDC();
|
||||||
|
|
||||||
WINDOW_H_API HGLRC getCurrentContext();
|
WINDOW_H_API HGLRC getCurrentContext();
|
||||||
|
|
|
@ -123,7 +123,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert
|
||||||
jboolean copy = JNI_FALSE;
|
jboolean copy = JNI_FALSE;
|
||||||
const char * eMessageText = env->GetStringUTFChars(message, ©);
|
const char * eMessageText = env->GetStringUTFChars(message, ©);
|
||||||
const char * cTitleBarText = env->GetStringUTFChars(title, ©);
|
const char * cTitleBarText = env->GetStringUTFChars(title, ©);
|
||||||
MessageBox(display_hwnd, eMessageText, cTitleBarText, MB_OK | MB_TOPMOST);
|
MessageBox(getCurrentHWND(), eMessageText, cTitleBarText, MB_OK | MB_TOPMOST);
|
||||||
|
|
||||||
printfDebug("*** Alert ***%s\n%s\n", cTitleBarText, eMessageText);
|
printfDebug("*** Alert ***%s\n%s\n", cTitleBarText, eMessageText);
|
||||||
|
|
||||||
|
|
|
@ -318,7 +318,7 @@ static void SetupController() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the cooperative level
|
// set the cooperative level
|
||||||
if(cDIDevice->SetCooperativeLevel(display_hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
|
if(cDIDevice->SetCooperativeLevel(getCurrentHWND(), DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
|
||||||
printfDebug("SetCooperativeLevel failed\n");
|
printfDebug("SetCooperativeLevel failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -81,18 +81,13 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (display_hwnd == NULL) {
|
|
||||||
throwException(env, "No window.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a keyboard device
|
// Create a keyboard device
|
||||||
if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdiKeyboard, NULL) != DI_OK) {
|
if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdiKeyboard, NULL) != DI_OK) {
|
||||||
throwException(env, "Failed to create keyboard.");
|
throwException(env, "Failed to create keyboard.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpdiKeyboard->SetCooperativeLevel(display_hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
|
if (lpdiKeyboard->SetCooperativeLevel(getCurrentHWND(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
|
||||||
throwException(env, "Failed to set keyboard cooperation mode.");
|
throwException(env, "Failed to set keyboard cooperation mode.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,25 +71,29 @@ 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);
|
||||||
|
|
||||||
static void getScreenClientRect(RECT* clientRect, RECT* windowRect)
|
/* Return the RECT of the current client area in the current window
|
||||||
|
* in screen coordinates
|
||||||
|
*/
|
||||||
|
static void getScreenClientRect(RECT* screen_client_rect)
|
||||||
{
|
{
|
||||||
GetClientRect(display_hwnd, clientRect);
|
/* We can't use GetClientRect directly, because it is in
|
||||||
// transform clientRect to screen coordinates
|
* local window coordinates and we can't use GetWindowRect
|
||||||
clientRect->top = -clientSize.top + windowRect->top;
|
* because it returns the screen coordinate RECT of the entire
|
||||||
clientRect->left = -clientSize.left + windowRect->left;
|
* window, inluding decoration. Luckily, the WINDOWINFO structure contains
|
||||||
clientRect->bottom += clientRect->top;
|
* the client rect in screen coordinates.
|
||||||
clientRect->right += clientRect->left;
|
*/
|
||||||
|
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;
|
||||||
GetWindowRect(display_hwnd, &windowRect);
|
getScreenClientRect(&clientRect);
|
||||||
getScreenClientRect(&clientRect, &windowRect);
|
|
||||||
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;
|
||||||
/* SetCursorPos(cursorPos.x, cursorPos.y);
|
|
||||||
GetCursorPos(&cursorPos);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Mouse_nHasWheel(JNIEnv *, jclass) {
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Mouse_nHasWheel(JNIEnv *, jclass) {
|
||||||
|
@ -230,11 +234,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor
|
||||||
if (handle_buffer != NULL) {
|
if (handle_buffer != NULL) {
|
||||||
HCURSOR *cursor_handle = (HCURSOR *)env->GetDirectBufferAddress(handle_buffer);
|
HCURSOR *cursor_handle = (HCURSOR *)env->GetDirectBufferAddress(handle_buffer);
|
||||||
HCURSOR cursor = *cursor_handle;
|
HCURSOR cursor = *cursor_handle;
|
||||||
// HCURSOR cursor = (HCURSOR)cursor_handle;
|
SetClassLong(getCurrentHWND(), GCL_HCURSOR, (LONG)cursor);
|
||||||
SetClassLong(display_hwnd, GCL_HCURSOR, (LONG)cursor);
|
|
||||||
SetCursor(cursor);
|
SetCursor(cursor);
|
||||||
} else {
|
} else {
|
||||||
SetClassLong(display_hwnd, GCL_HCURSOR, (LONG)NULL);
|
SetClassLong(getCurrentHWND(), GCL_HCURSOR, (LONG)NULL);
|
||||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,7 +282,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nGrabMouse
|
||||||
resetCursorPos();
|
resetCursorPos();
|
||||||
}
|
}
|
||||||
mDIDevice->Unacquire();
|
mDIDevice->Unacquire();
|
||||||
if(mDIDevice->SetCooperativeLevel(display_hwnd, mouseMask) != DI_OK) {
|
if(mDIDevice->SetCooperativeLevel(getCurrentHWND(), mouseMask) != DI_OK) {
|
||||||
throwException(env, "Could not set the CooperativeLevel.");
|
throwException(env, "Could not set the CooperativeLevel.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -375,7 +378,7 @@ static void SetupMouse() {
|
||||||
mDIDevice->SetProperty(DIPROP_BUFFERSIZE, &dipropdw.diph);
|
mDIDevice->SetProperty(DIPROP_BUFFERSIZE, &dipropdw.diph);
|
||||||
|
|
||||||
// set the cooperative level
|
// set the cooperative level
|
||||||
if(mDIDevice->SetCooperativeLevel(display_hwnd, mouseMask) != DI_OK) {
|
if(mDIDevice->SetCooperativeLevel(getCurrentHWND(), mouseMask) != DI_OK) {
|
||||||
printfDebug("SetCooperativeLevel failed\n");
|
printfDebug("SetCooperativeLevel failed\n");
|
||||||
mCreate_success = false;
|
mCreate_success = false;
|
||||||
return;
|
return;
|
||||||
|
@ -394,18 +397,18 @@ static int cap(int val, int min, int max) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getGDICursorDelta(int* return_dx, int* return_dy) {
|
static void getGDICursorDelta(int* return_dx, int* return_dy) {
|
||||||
int dx = 0;
|
int dx;
|
||||||
int dy = 0;
|
int dy;
|
||||||
|
|
||||||
POINT newCursorPos;
|
POINT newCursorPos;
|
||||||
GetCursorPos(&newCursorPos);
|
GetCursorPos(&newCursorPos);
|
||||||
RECT clientRect;
|
RECT clientRect;
|
||||||
RECT newWindowRect;
|
RECT newWindowRect;
|
||||||
GetWindowRect(display_hwnd, &newWindowRect);
|
GetWindowRect(getCurrentHWND(), &newWindowRect);
|
||||||
cursorPos.x += newWindowRect.left - windowRect.left;
|
cursorPos.x += newWindowRect.left - windowRect.left;
|
||||||
cursorPos.y += newWindowRect.top - windowRect.top;
|
cursorPos.y += newWindowRect.top - windowRect.top;
|
||||||
windowRect = newWindowRect;
|
windowRect = newWindowRect;
|
||||||
getScreenClientRect(&clientRect, &windowRect);
|
getScreenClientRect(&clientRect);
|
||||||
// Clip the position to the client rect
|
// 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);
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
|
|
||||||
static bool oneShotInitialised = false; // Registers the LWJGL window class
|
static bool oneShotInitialised = false; // Registers the LWJGL window class
|
||||||
|
|
||||||
HWND display_hwnd = NULL; // Handle to the window
|
static HWND display_hwnd = NULL; // Handle to the window
|
||||||
static HDC display_hdc = NULL; // Device context
|
static HDC display_hdc = NULL; // Device context
|
||||||
static HGLRC display_hglrc = NULL; // OpenGL context
|
static HGLRC display_hglrc = NULL; // OpenGL context
|
||||||
static bool isFullScreen = false; // Whether we're fullscreen or not
|
static bool isFullScreen = false; // Whether we're fullscreen or not
|
||||||
|
@ -58,7 +58,6 @@ static bool isFocused = false; // whether we're focused or no
|
||||||
static bool isDirty = false; // Whether we're dirty or not
|
static bool isDirty = false; // Whether we're dirty or not
|
||||||
static bool isUndecorated = false; // Whether we're undecorated or not
|
static bool isUndecorated = false; // Whether we're undecorated or not
|
||||||
extern HINSTANCE dll_handle; // Handle to the LWJGL dll
|
extern HINSTANCE dll_handle; // Handle to the LWJGL dll
|
||||||
RECT clientSize;
|
|
||||||
|
|
||||||
static bool closerequested;
|
static bool closerequested;
|
||||||
static int pixel_format_index;
|
static int pixel_format_index;
|
||||||
|
@ -78,6 +77,10 @@ bool applyPixelFormat(HDC hdc, int iPixelFormat) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HWND getCurrentHWND() {
|
||||||
|
return display_hwnd;
|
||||||
|
}
|
||||||
|
|
||||||
HGLRC getCurrentContext() {
|
HGLRC getCurrentContext() {
|
||||||
return display_hglrc;
|
return display_hglrc;
|
||||||
}
|
}
|
||||||
|
@ -440,6 +443,7 @@ HWND createWindow(int width, int height, bool fullscreen, bool undecorated)
|
||||||
|
|
||||||
// If we're not a fullscreen window, adjust the height to account for the
|
// If we're not a fullscreen window, adjust the height to account for the
|
||||||
// height of the title bar (unless undecorated)
|
// height of the title bar (unless undecorated)
|
||||||
|
RECT clientSize;
|
||||||
clientSize.bottom = height;
|
clientSize.bottom = height;
|
||||||
clientSize.left = 0;
|
clientSize.left = 0;
|
||||||
clientSize.right = width;
|
clientSize.right = width;
|
||||||
|
@ -573,43 +577,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nMakeCurrent
|
||||||
throwException(env, "Could not make display context current");
|
throwException(env, "Could not make display context current");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nReshape
|
|
||||||
(JNIEnv *env, jclass clazz, jint x, jint y, jint width, jint height)
|
|
||||||
{
|
|
||||||
if (isFullScreen) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int exstyle, windowflags;
|
|
||||||
|
|
||||||
if (isUndecorated) {
|
|
||||||
exstyle = WS_EX_APPWINDOW;
|
|
||||||
windowflags = WS_OVERLAPPED;
|
|
||||||
} else {
|
|
||||||
exstyle = WS_EX_APPWINDOW;
|
|
||||||
windowflags = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_MINIMIZEBOX | WS_SYSMENU;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're not a fullscreen window, adjust the height to account for the
|
|
||||||
// height of the title bar:
|
|
||||||
clientSize.bottom = height;
|
|
||||||
clientSize.left = 0;
|
|
||||||
clientSize.right = width;
|
|
||||||
clientSize.top = 0;
|
|
||||||
|
|
||||||
AdjustWindowRectEx(
|
|
||||||
&clientSize, // client-rectangle structure
|
|
||||||
windowflags, // window styles
|
|
||||||
FALSE, // menu-present option
|
|
||||||
exstyle // extended window style
|
|
||||||
);
|
|
||||||
|
|
||||||
SetWindowPos(hwnd, HWND_TOP, x, y, clientSize.right - clientSize.left,
|
|
||||||
clientSize.bottom - clientSize.top, SWP_NOZORDER);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_Display_nGetAvailableDisplayModes(JNIEnv *env, jclass clazz) {
|
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_Display_nGetAvailableDisplayModes(JNIEnv *env, jclass clazz) {
|
||||||
return getAvailableDisplayModes(env);
|
return getAvailableDisplayModes(env);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue