SDL: Fixup touchscreen code

This commit is contained in:
wheremyfoodat 2024-07-26 12:05:33 +03:00
parent 1413cdaebf
commit 11e7eb7fd6
3 changed files with 9 additions and 7 deletions

View file

@ -502,7 +502,7 @@ if(NOT BUILD_HYDRA_CORE AND NOT BUILD_LIBRETRO_CORE)
) )
else() else()
set(FRONTEND_SOURCE_FILES src/panda_sdl/main.cpp src/panda_sdl/frontend_sdl.cpp src/panda_sdl/mappings.cpp) set(FRONTEND_SOURCE_FILES src/panda_sdl/main.cpp src/panda_sdl/frontend_sdl.cpp src/panda_sdl/mappings.cpp)
set(FRONTEND_HEADER_FILES "") set(FRONTEND_HEADER_FILES "include/panda_sdl/frontend_sdl.hpp")
endif() endif()
target_link_libraries(Alber PRIVATE AlberCore) target_link_libraries(Alber PRIVATE AlberCore)

View file

@ -23,6 +23,8 @@ class FrontendSDL {
SDL_GameController* gameController = nullptr; SDL_GameController* gameController = nullptr;
InputMappings keyboardMappings; InputMappings keyboardMappings;
u32 windowWidth = 400;
u32 windowHeight = 480;
int gameControllerID; int gameControllerID;
bool programRunning = true; bool programRunning = true;

View file

@ -162,9 +162,9 @@ void FrontendSDL::run() {
if (emu.romType == ROMType::None) break; if (emu.romType == ROMType::None) break;
if (event.button.button == SDL_BUTTON_LEFT) { if (event.button.button == SDL_BUTTON_LEFT) {
// Get current window dimensions if (windowWidth == 0 || windowHeight == 0) [[unlikely]] {
int windowWidth, windowHeight; break;
SDL_GetWindowSize(window, &windowWidth, &windowHeight); }
// Go from window positions to [0, 400) for x and [0, 480) for y // Go from window positions to [0, 400) for x and [0, 480) for y
const s32 x = (s32)std::round(event.button.x * 400.f / windowWidth); const s32 x = (s32)std::round(event.button.x * 400.f / windowWidth);
@ -298,9 +298,9 @@ void FrontendSDL::run() {
case SDL_WINDOWEVENT: { case SDL_WINDOWEVENT: {
auto type = event.window.event; auto type = event.window.event;
if (type == SDL_WINDOWEVENT_RESIZED) { if (type == SDL_WINDOWEVENT_RESIZED) {
const u32 width = event.window.data1; windowWidth = event.window.data1;
const u32 height = event.window.data2; windowHeight = event.window.data2;
emu.setOutputSize(width, height); emu.setOutputSize(windowWidth, windowHeight);
} }
} }
} }