aurora: Small cleanup to scaling logic

This commit is contained in:
Luke Street 2022-02-26 16:28:58 -05:00
parent 457f63d311
commit d6f8ca44de
2 changed files with 9 additions and 14 deletions

View File

@ -352,14 +352,12 @@ WindowSize get_window_size() noexcept {
int width, height, fb_w, fb_h; int width, height, fb_w, fb_h;
SDL_GetWindowSize(g_window, &width, &height); SDL_GetWindowSize(g_window, &width, &height);
SDL_GL_GetDrawableSize(g_window, &fb_w, &fb_h); SDL_GL_GetDrawableSize(g_window, &fb_w, &fb_h);
float scale = fb_w / width; float scale = static_cast<float>(fb_w) / static_cast<float>(width);
#ifndef __APPLE__ #ifndef __APPLE__
if (SDL_GetDisplayDPI(SDL_GetWindowDisplayIndex(g_window), nullptr, &scale, nullptr) == 0) { if (SDL_GetDisplayDPI(SDL_GetWindowDisplayIndex(g_window), nullptr, &scale, nullptr) == 0) {
scale /= 96.f; scale /= 96.f;
} }
#endif #endif
return { return {
.width = static_cast<uint32_t>(width), .width = static_cast<uint32_t>(width),
.height = static_cast<uint32_t>(height), .height = static_cast<uint32_t>(height),

View File

@ -25,8 +25,10 @@ void create_context() noexcept {
void initialize(SDL_Window* window) noexcept { void initialize(SDL_Window* window) noexcept {
ImGui_ImplSDL2_Init(window, nullptr); ImGui_ImplSDL2_Init(window, nullptr);
#ifdef __APPLE__
// Disable MouseCanUseGlobalState for scaling purposes // Disable MouseCanUseGlobalState for scaling purposes
ImGui_ImplSDL2_GetBackendData()->MouseCanUseGlobalState = false; ImGui_ImplSDL2_GetBackendData()->MouseCanUseGlobalState = false;
#endif
ImGui_ImplWGPU_Init(g_device.Get(), 1, static_cast<WGPUTextureFormat>(gpu::g_graphicsConfig.colorFormat)); ImGui_ImplWGPU_Init(g_device.Get(), 1, static_cast<WGPUTextureFormat>(gpu::g_graphicsConfig.colorFormat));
} }
@ -37,21 +39,16 @@ void shutdown() noexcept {
} }
void process_event(const SDL_Event& event) 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__ #ifdef __APPLE__
mouseX *= g_scale; if (event.type == SDL_MOUSEMOTION) {
mouseY *= g_scale; auto& io = ImGui::GetIO();
#endif
// Scale up mouse coordinates // Scale up mouse coordinates
io.AddMousePosEvent(mouseX, mouseY); io.AddMousePosEvent(static_cast<float>(event.motion.x) * g_scale,
static_cast<float>(event.motion.y) * g_scale);
return; return;
} }
ImGui_ImplSDL2_ProcessEvent(&newEvent); #endif
ImGui_ImplSDL2_ProcessEvent(&event);
} }
void new_frame(const WindowSize& size) noexcept { void new_frame(const WindowSize& size) noexcept {