Skip to content

Commit

Permalink
Refactor hide cursor code in its own function
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 6, 2024
1 parent 949f471 commit 08c9166
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions platforms/desktop-shared/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 08c9166

Please sign in to comment.