diff --git a/src/Libs/imgui/backends/imgui_impl_sdl2.cpp b/src/Libs/imgui/backends/imgui_impl_sdl2.cpp index a18c013..c3332b4 100644 --- a/src/Libs/imgui/backends/imgui_impl_sdl2.cpp +++ b/src/Libs/imgui/backends/imgui_impl_sdl2.cpp @@ -125,6 +125,14 @@ struct ImGui_ImplSDL2_Data ImGui_ImplSDL2_Data() { memset((void*)this, 0, sizeof(*this)); } }; +static ImVec2 RenderScale(SDL_Renderer* Renderer) { + ImVec2 res; + res.x = 1.0f; + res.y = 1.0f; + SDL_RenderGetScale(Renderer, &res.x, &res.y); + return res; +} + // Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. // FIXME: multi-context support is not well tested and probably dysfunctional in this backend. @@ -568,7 +576,8 @@ static void ImGui_ImplSDL2_UpdateMouseData() int window_x, window_y, mouse_x_global, mouse_y_global; SDL_GetGlobalMouseState(&mouse_x_global, &mouse_y_global); SDL_GetWindowPosition(bd->Window, &window_x, &window_y); - io.AddMousePosEvent((float)(mouse_x_global - window_x), (float)(mouse_y_global - window_y)); + ImVec2 scale = RenderScale(bd->Renderer); + io.AddMousePosEvent((float)(mouse_x_global - window_x)/scale.x, (float)(mouse_y_global - window_y)/scale.y); } } } diff --git a/src/saland.cpp b/src/saland.cpp index 179de0b..b4567b7 100644 --- a/src/saland.cpp +++ b/src/saland.cpp @@ -221,11 +221,11 @@ void RunGameState(sago::GameStateInterface& state ) { ImGui::Render(); ImGuiIO& io = ImGui::GetIO(); io.IniFilename = NULL; - float x, y; - SDL_RenderGetScale(globalData.screen, &x, &y); - SDL_RenderSetScale(globalData.screen, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y); + //float x, y; + //SDL_RenderGetScale(globalData.screen, &x, &y); + //SDL_RenderSetScale(globalData.screen, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y); ImGui_ImplSDLRenderer2_RenderDrawData( ImGui::GetDrawData(), globalData.screen ); - SDL_RenderSetScale(globalData.screen, x, y); + //SDL_RenderSetScale(globalData.screen, x, y); //While using Dear ImGui we do not draw the mouse ourself. This is gone: globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), globalData.mousex, globalData.mousey); SDL_RenderPresent(globalData.screen); @@ -243,7 +243,7 @@ void RunGameState(sago::GameStateInterface& state ) { if (event.type == SDL_WINDOWEVENT) { if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { std::cout << event.window.data1 << ", " << event.window.data2 << "\n"; - SDL_GetRendererOutputSize(globalData.screen, &globalData.xsize, &globalData.ysize); + //SDL_GetRendererOutputSize(globalData.screen, &globalData.xsize, &globalData.ysize); } } @@ -354,7 +354,7 @@ void ResetFullscreen() { dataHolder.invalidateAll(globalData.screen); globalData.spriteHolder.reset(new sago::SagoSpriteHolder( dataHolder ) ); SDL_ShowCursor(SDL_ENABLE); - SDL_GetRendererOutputSize(globalData.screen, &globalData.xsize, &globalData.ysize); + //SDL_GetRendererOutputSize(globalData.screen, &globalData.xsize, &globalData.ysize); } void toggleFullscreen() { @@ -410,7 +410,8 @@ public: void runGame() { - int width = 1280, height = 800; + globalData.xsize = 1280; + globalData.ysize = 800; SDL_Init(SDL_INIT_VIDEO); IMG_Init(IMG_INIT_PNG); TTF_Init(); @@ -432,11 +433,12 @@ void runGame() { } SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2"); SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_SCALING, "1"); - win = SDL_CreateWindow("Saland Adventures", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_RESIZABLE); + win = SDL_CreateWindow("Saland Adventures", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, globalData.xsize, globalData.ysize, SDL_WINDOW_RESIZABLE); globalData.screen = SDL_CreateRenderer(win, -1, rendererFlags); - SDL_RenderSetLogicalSize(globalData.screen, width, height); - InitImGui(win, globalData.screen, width, height); + SDL_RenderSetLogicalSize(globalData.screen, globalData.xsize, globalData.ysize); + InitImGui(win, globalData.screen, globalData.xsize, globalData.ysize); + globalData.ysize = globalData.ysize; sago::SagoDataHolder holder(globalData.screen); globalData.spriteHolder.reset(new sago::SagoSpriteHolder(holder));