From 71fb024061fdcbfc272c25052727f0f8dd4c16ef Mon Sep 17 00:00:00 2001 From: flyinghead Date: Tue, 4 May 2021 12:03:09 +0200 Subject: [PATCH] rawinput: proper conversion of abs coordinates Issue #138 get rid of libPvr_GetRenderTarget() -> getNativeHwnd() --- core/oslib/audiobackend_directsound.cpp | 10 ++-------- core/sdl/sdl.cpp | 26 ++++++++++++------------- core/sdl/sdl.h | 5 ----- core/types.h | 2 -- core/windows/rawinput.cpp | 12 +++++++++++- core/windows/winmain.cpp | 6 +++--- tests/src/test_stubs.cpp | 6 ++++-- 7 files changed, 33 insertions(+), 34 deletions(-) diff --git a/core/oslib/audiobackend_directsound.cpp b/core/oslib/audiobackend_directsound.cpp index 4a2cb5ee0..f7e5993dd 100644 --- a/core/oslib/audiobackend_directsound.cpp +++ b/core/oslib/audiobackend_directsound.cpp @@ -2,15 +2,13 @@ #include "audiostream.h" #include #include -#ifdef USE_SDL -#include "sdl/sdl.h" -#endif #include #include #include #include #include "stdclass.h" +HWND getNativeHwnd(); #define verifyc(x) verify(!FAILED(x)) static IDirectSound8* dsound; @@ -126,12 +124,8 @@ static void audioThreadMain() static void directsound_init() { verifyc(DirectSoundCreate8(NULL, &dsound, NULL)); + verifyc(dsound->SetCooperativeLevel(getNativeHwnd(), DSSCL_PRIORITY)); -#ifdef USE_SDL - verifyc(dsound->SetCooperativeLevel(sdl_get_native_hwnd(), DSSCL_PRIORITY)); -#else - verifyc(dsound->SetCooperativeLevel((HWND)libPvr_GetRenderTarget(), DSSCL_PRIORITY)); -#endif // Set up WAV format structure. WAVEFORMATEX wfx; memset(&wfx, 0, sizeof(WAVEFORMATEX)); diff --git a/core/sdl/sdl.cpp b/core/sdl/sdl.cpp index ed2b6cce4..3e1a5edb5 100644 --- a/core/sdl/sdl.cpp +++ b/core/sdl/sdl.cpp @@ -424,6 +424,18 @@ static void get_window_state() } +#ifdef _WIN32 +#include + +HWND getNativeHwnd() +{ + SDL_SysWMinfo wmInfo; + SDL_VERSION(&wmInfo.version); + SDL_GetWindowWMInfo(window, &wmInfo); + return wmInfo.info.win.window; +} +#endif + bool sdl_recreate_window(u32 flags) { #ifdef _WIN32 @@ -501,7 +513,7 @@ bool sdl_recreate_window(u32 flags) #endif theGLContext.SetWindow(window); #ifdef _WIN32 - theDXContext.setNativeWindow(sdl_get_native_hwnd()); + theDXContext.setNativeWindow(getNativeHwnd()); #endif return true; @@ -530,17 +542,5 @@ void sdl_window_destroy() SDL_DestroyWindow(window); } -#ifdef _WIN32 -#include - -HWND sdl_get_native_hwnd() -{ - SDL_SysWMinfo wmInfo; - SDL_VERSION(&wmInfo.version); - SDL_GetWindowWMInfo(window, &wmInfo); - return wmInfo.info.win.window; -} -#endif - #endif // !defined(__APPLE__) diff --git a/core/sdl/sdl.h b/core/sdl/sdl.h index 0f1572f7a..852b34bcd 100644 --- a/core/sdl/sdl.h +++ b/core/sdl/sdl.h @@ -8,8 +8,3 @@ void sdl_window_create(); void sdl_window_set_text(const char* text); void sdl_window_destroy(); bool sdl_recreate_window(u32 flags); - -#ifdef _WIN32 -#include -HWND sdl_get_native_hwnd(); -#endif diff --git a/core/types.h b/core/types.h index dbb86ec33..f5834e011 100644 --- a/core/types.h +++ b/core/types.h @@ -376,8 +376,6 @@ s32 libPvr_Init(); void libPvr_Reset(bool hard); void libPvr_Term(); -void* libPvr_GetRenderTarget(); - // 0x00600000 - 0x006007FF [NAOMI] (modem area for dreamcast) u32 libExtDevice_ReadMem_A0_006(u32 addr,u32 size); void libExtDevice_WriteMem_A0_006(u32 addr,u32 data,u32 size); diff --git a/core/windows/rawinput.cpp b/core/windows/rawinput.cpp index 603a270ff..c22af98f6 100644 --- a/core/windows/rawinput.cpp +++ b/core/windows/rawinput.cpp @@ -25,6 +25,8 @@ #define CALLBACK #endif +HWND getNativeHwnd(); + namespace rawinput { static std::map> mice; @@ -237,7 +239,15 @@ void RawMouse::buttonInput(u32 buttonId, u16 flags, u16 downFlag, u16 upFlag) { void RawMouse::updateState(RAWMOUSE* state) { if (state->usFlags & MOUSE_MOVE_ABSOLUTE) - SetMousePosition(state->lLastX, state->lLastY, screen_width, screen_height, maple_port()); + { + bool isVirtualDesktop = (state->usFlags & MOUSE_VIRTUAL_DESKTOP) == MOUSE_VIRTUAL_DESKTOP; + int width = GetSystemMetrics(isVirtualDesktop ? SM_CXVIRTUALSCREEN : SM_CXSCREEN); + int height = GetSystemMetrics(isVirtualDesktop ? SM_CYVIRTUALSCREEN : SM_CYSCREEN); + + POINT pt { long(state->lLastX / 65535.0f * width), long(state->lLastY / 65535.0f * height) }; + ScreenToClient(getNativeHwnd(), &pt); + SetMousePosition(pt.x, pt.y, screen_width, screen_height, maple_port()); + } else if (state->lLastX != 0 || state->lLastY != 0) SetRelativeMousePosition(state->lLastX, state->lLastY, maple_port()); buttonInput(0, state->usButtonFlags, RI_MOUSE_LEFT_BUTTON_DOWN, RI_MOUSE_LEFT_BUTTON_UP); diff --git a/core/windows/winmain.cpp b/core/windows/winmain.cpp index a60e24ee2..e992b08b1 100644 --- a/core/windows/winmain.cpp +++ b/core/windows/winmain.cpp @@ -610,12 +610,12 @@ static void toggleFullscreen() } } -#endif -void* libPvr_GetRenderTarget() +HWND getNativeHwnd() { - return (void*)hWnd; + return hWnd; } +#endif void os_SetWindowText(const char* text) { diff --git a/tests/src/test_stubs.cpp b/tests/src/test_stubs.cpp index c37c9e313..8a35d1a0d 100644 --- a/tests/src/test_stubs.cpp +++ b/tests/src/test_stubs.cpp @@ -12,10 +12,12 @@ void os_DebugBreak() #endif } -void* libPvr_GetRenderTarget() +#ifdef _WIN32 +HWND getNativeHwnd() { - return nullptr; + return (HWND)NULL; } +#endif void os_SetupInput() {