Skip to content

Commit

Permalink
Merge pull request #72800 from katemonster33/imgui_input_when_no_wind…
Browse files Browse the repository at this point in the history
…ow_shown

Fixing ImGUi keybindings screen processing keys pressed before it was shown
  • Loading branch information
I-am-Erk authored Apr 4, 2024
2 parents 210e5b1 + 0e01e26 commit 373238f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/cata_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ void cataimgui::client::set_alloced_pair_count( short count )

void cataimgui::client::process_input( void *input )
{
if( !any_window_shown() ) {
return;
}
if( input ) {
input_event *curses_input = static_cast<input_event *>( input );
ImTui::mouse_event new_mouse_event = ImTui::mouse_event();
Expand Down Expand Up @@ -261,7 +264,9 @@ void cataimgui::client::end_frame()

void cataimgui::client::process_input( void *input )
{
ImGui_ImplSDL2_ProcessEvent( static_cast<const SDL_Event *>( input ) );
if( any_window_shown() ) {
ImGui_ImplSDL2_ProcessEvent( static_cast<const SDL_Event *>( input ) );
}
}

#endif
Expand All @@ -276,6 +281,18 @@ bool cataimgui::client::auto_size_frame_active()
return false;
}

bool cataimgui::client::any_window_shown()
{
bool any_window_shown = false;
for( const ImGuiWindow *window : GImGui->Windows ) {
if( window->Active && !window->Hidden ) {
any_window_shown = true;
break;
}
}
return any_window_shown;
}

static ImGuiKey cata_key_to_imgui( int cata_key )
{
switch( cata_key ) {
Expand Down
1 change: 1 addition & 0 deletions src/cata_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class client
const GeometryRenderer_Ptr &sdl_geometry;
#endif
bool auto_size_frame_active();
bool any_window_shown();
};

void point_to_imvec2( point *src, ImVec2 *dest );
Expand Down

0 comments on commit 373238f

Please sign in to comment.