From 08c91661002c0b2f8fc6a92d52801e439d61d861 Mon Sep 17 00:00:00 2001 From: Ignacio Sanchez Gines <863613+drhelius@users.noreply.github.com> Date: Sat, 6 Jan 2024 19:55:46 +0100 Subject: [PATCH] Refactor hide cursor code in its own function --- platforms/desktop-shared/application.cpp | 31 ++++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/platforms/desktop-shared/application.cpp b/platforms/desktop-shared/application.cpp index 26faf4cb..52722ae9 100644 --- a/platforms/desktop-shared/application.cpp +++ b/platforms/desktop-shared/application.cpp @@ -40,6 +40,7 @@ static void sdl_destroy(void); static void sdl_events(void); static void sdl_events_emu(const SDL_Event* event); static void sdl_shortcuts_gui(const SDL_Event* event); +static void handle_mouse_cursor(void); static void run_emulator(void); static void render(void); static void frame_throttle(void); @@ -101,6 +102,7 @@ void application_mainloop(void) { frame_time_start = SDL_GetPerformanceCounter(); sdl_events(); + handle_mouse_cursor(); run_emulator(); render(); frame_time_end = SDL_GetPerformanceCounter(); @@ -230,19 +232,6 @@ static void sdl_events(void) sdl_shortcuts_gui(&event); } } - - bool hide_cursor = false; - - if (gui_main_window_hovered && !config_debug.debug) - hide_cursor = true; - - if (!config_emulator.show_menu && !config_debug.debug) - hide_cursor = true; - - if (hide_cursor) - ImGui::SetMouseCursor(ImGuiMouseCursor_None); - else - ImGui::SetMouseCursor(ImGuiMouseCursor_Arrow); } static void sdl_events_emu(const SDL_Event* event) @@ -477,6 +466,22 @@ static void sdl_shortcuts_gui(const SDL_Event* event) } } +static void handle_mouse_cursor(void) +{ + bool hide_cursor = false; + + if (gui_main_window_hovered && !config_debug.debug) + hide_cursor = true; + + if (!config_emulator.show_menu && !config_debug.debug) + hide_cursor = true; + + if (hide_cursor) + ImGui::SetMouseCursor(ImGuiMouseCursor_None); + else + ImGui::SetMouseCursor(ImGuiMouseCursor_Arrow); +} + static void run_emulator(void) { static char prevtitle[256];