Skip to content

Commit

Permalink
Add the option to open the ImGui demo from the main menu for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroInternalReflection committed Mar 4, 2024
1 parent 8a59431 commit 16632b7
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cata_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ void cataimgui::window::draw()
}
if( ImGui::Begin( id.c_str(), &is_open, window_flags ) ) {
draw_controls();
if( p_impl->window_adaptor->is_on_top ) {
if( p_impl->window_adaptor->is_on_top && !force_to_back ) {
ImGui::BringWindowToDisplayFront( ImGui::GetCurrentWindow() );
}
}
Expand Down
1 change: 1 addition & 0 deletions src/cata_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class window
void mark_resized();

protected:
bool force_to_back = false;
bool is_open;
std::string id;
int window_flags;
Expand Down
75 changes: 75 additions & 0 deletions src/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,69 @@
#include "wcwidth.h"
#include "worldfactory.h"

#if !defined(__ANDROID__)
#include "cata_imgui.h"
#include "imgui/imgui.h"

class demo_ui : public cataimgui::window
{
public:
demo_ui();
void init();
void run();

protected:
void draw_controls() override;
cataimgui::bounds get_bounds() override;
void on_resized() override {
init();
};
};

demo_ui::demo_ui() : cataimgui::window( _( "ImGui Demo Screen" ) )
{
}

cataimgui::bounds demo_ui::get_bounds()
{
return { -1.f, -1.f, float( str_width_to_pixels( TERMX ) ), float( str_height_to_pixels( TERMY ) ) };
}

void demo_ui::draw_controls()
{
ImGui::ShowDemoWindow();
}

void demo_ui::init()
{
// The demo makes it's own screen. Don't get in the way
force_to_back = true;
}

void demo_ui::run()
{
init();

input_context ctxt( "HELP_KEYBINDINGS" );
ctxt.register_action( "QUIT" );
ctxt.register_action( "SELECT" );
ctxt.register_action( "MOUSE_MOVE" );
ctxt.register_action( "ANY_INPUT" );
ctxt.register_action( "HELP_KEYBINDINGS" );
std::string action;

ui_manager::redraw();

while( is_open ) {
ui_manager::redraw();
action = ctxt.handle_input();
if( action == "QUIT" ) {
break;
}
}
}
#endif

static const mod_id MOD_INFORMATION_dda( "dda" );

enum class main_menu_opts : int {
Expand Down Expand Up @@ -510,6 +573,11 @@ void main_menu::init_strings()
vSettingsSubItems.emplace_back( pgettext( "Main Menu|Settings", "A<u|U>topickup" ) );
vSettingsSubItems.emplace_back( pgettext( "Main Menu|Settings", "Sa<f|F>emode" ) );
vSettingsSubItems.emplace_back( pgettext( "Main Menu|Settings", "Colo<r|R>s" ) );
#if !defined(__ANDROID__)
if( get_options().has_option( "USE_IMGUI" ) && get_option<bool>( "USE_IMGUI" ) ) {
vSettingsSubItems.emplace_back( pgettext( "Main Menu|Settings", "<I|i>mGui Demo Screen" ) );
}
#endif

vSettingsHotkeys.clear();
for( const std::string &item : vSettingsSubItems ) {
Expand Down Expand Up @@ -855,6 +923,13 @@ bool main_menu::opening_screen()
get_safemode().show();
} else if( sel2 == 4 ) { /// Colors
all_colors.show_gui();
#if !defined(__ANDROID__)
} else if( sel2 == 5 ) { /// ImGui demo
if( get_options().has_option( "USE_IMGUI" ) && get_option<bool>( "USE_IMGUI" ) ) {
demo_ui demo;
demo.run();
}
#endif
}
break;
case main_menu_opts::WORLD:
Expand Down

0 comments on commit 16632b7

Please sign in to comment.