rawinput: proper conversion of abs coordinates

Issue #138
get rid of libPvr_GetRenderTarget() -> getNativeHwnd()
This commit is contained in:
flyinghead 2021-05-04 12:03:09 +02:00
parent 54cfc6e09b
commit 71fb024061
7 changed files with 33 additions and 34 deletions

View File

@ -2,15 +2,13 @@
#include "audiostream.h"
#include <initguid.h>
#include <dsound.h>
#ifdef USE_SDL
#include "sdl/sdl.h"
#endif
#include <vector>
#include <algorithm>
#include <atomic>
#include <thread>
#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));

View File

@ -424,6 +424,18 @@ static void get_window_state()
}
#ifdef _WIN32
#include <windows.h>
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 <windows.h>
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__)

View File

@ -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 <windows.h>
HWND sdl_get_native_hwnd();
#endif

View File

@ -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);

View File

@ -25,6 +25,8 @@
#define CALLBACK
#endif
HWND getNativeHwnd();
namespace rawinput {
static std::map<HANDLE, std::shared_ptr<RawMouse>> 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);

View File

@ -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)
{

View File

@ -12,10 +12,12 @@ void os_DebugBreak()
#endif
}
void* libPvr_GetRenderTarget()
#ifdef _WIN32
HWND getNativeHwnd()
{
return nullptr;
return (HWND)NULL;
}
#endif
void os_SetupInput()
{