diff --git a/aurora/lib/aurora.cpp b/aurora/lib/aurora.cpp index 80422a4ce..69fbe3962 100644 --- a/aurora/lib/aurora.cpp +++ b/aurora/lib/aurora.cpp @@ -352,14 +352,12 @@ WindowSize get_window_size() noexcept { int width, height, fb_w, fb_h; SDL_GetWindowSize(g_window, &width, &height); SDL_GL_GetDrawableSize(g_window, &fb_w, &fb_h); - float scale = fb_w / width; - + float scale = static_cast(fb_w) / static_cast(width); #ifndef __APPLE__ if (SDL_GetDisplayDPI(SDL_GetWindowDisplayIndex(g_window), nullptr, &scale, nullptr) == 0) { scale /= 96.f; } #endif - return { .width = static_cast(width), .height = static_cast(height), diff --git a/aurora/lib/imgui.cpp b/aurora/lib/imgui.cpp index 4fe8ac4b7..3174992bb 100644 --- a/aurora/lib/imgui.cpp +++ b/aurora/lib/imgui.cpp @@ -25,8 +25,10 @@ void create_context() noexcept { void initialize(SDL_Window* window) noexcept { ImGui_ImplSDL2_Init(window, nullptr); +#ifdef __APPLE__ // Disable MouseCanUseGlobalState for scaling purposes ImGui_ImplSDL2_GetBackendData()->MouseCanUseGlobalState = false; +#endif ImGui_ImplWGPU_Init(g_device.Get(), 1, static_cast(gpu::g_graphicsConfig.colorFormat)); } @@ -37,21 +39,16 @@ void shutdown() noexcept { } void process_event(const SDL_Event& event) noexcept { - auto newEvent = event; - if (newEvent.type == SDL_MOUSEMOTION) { - auto& io = ImGui::GetIO(); - float mouseX = newEvent.motion.x; - float mouseY = newEvent.motion.y; #ifdef __APPLE__ - mouseX *= g_scale; - mouseY *= g_scale; -#endif + if (event.type == SDL_MOUSEMOTION) { + auto& io = ImGui::GetIO(); // Scale up mouse coordinates - io.AddMousePosEvent(mouseX, mouseY); - + io.AddMousePosEvent(static_cast(event.motion.x) * g_scale, + static_cast(event.motion.y) * g_scale); return; } - ImGui_ImplSDL2_ProcessEvent(&newEvent); +#endif + ImGui_ImplSDL2_ProcessEvent(&event); } void new_frame(const WindowSize& size) noexcept {