diff --git a/src/sys/ags.h b/src/sys/ags.h index 43785b0..3f4a41b 100644 --- a/src/sys/ags.h +++ b/src/sys/ags.h @@ -137,6 +137,7 @@ public: void load_cursor(int page); void select_cursor(); + void translate_mouse_coords(int* x, int* y); void save_screenshot(const char* path); diff --git a/src/sys/ags_cursor.cpp b/src/sys/ags_cursor.cpp index dced7b3..9f3625a 100644 --- a/src/sys/ags_cursor.cpp +++ b/src/sys/ags_cursor.cpp @@ -7,6 +7,8 @@ #include "ags.h" #include +extern SDL_Window* g_window; + void AGS::load_cursor(int page) { // カーソルCGをロードする @@ -91,3 +93,29 @@ void AGS::select_cursor() } } +void AGS::translate_mouse_coords(int* x, int* y) +{ + // scale mouse x and y + float scalex, scaley; + SDL_RenderGetScale(sdlRenderer, &scalex, &scaley); + *x *= scalex; + *y *= scaley; + + // calculate window borders + int logw, logh; + SDL_RenderGetLogicalSize(sdlRenderer, &logw, &logh); + + float scalew, scaleh; + scalew = logw * scalex; + scaleh = logh * scaley; + + int winw, winh; + SDL_GetWindowSize(g_window, &winw, &winh); + + float border_left = (winw - scalew) / 2; + float border_top = (winh - scaleh) / 2; + + // offset x and y by window borders + *x += border_left; + *y += border_top; +} diff --git a/src/sys/nact_input.cpp b/src/sys/nact_input.cpp index c663299..5a4ce3d 100644 --- a/src/sys/nact_input.cpp +++ b/src/sys/nact_input.cpp @@ -105,6 +105,6 @@ void NACT::get_cursor(int* x, int* y) void NACT::set_cursor(int x, int y) { + ags->translate_mouse_coords(&x, &y); SDL_WarpMouseInWindow(g_window, x, y); } -