From a0e1e55afa1f1cdfc9da8fbd0258a84463787ccd Mon Sep 17 00:00:00 2001 From: Daniel Brooks Date: Mon, 22 Jan 2024 04:36:16 -0500 Subject: [PATCH] ImGui widgets record their dimensions, invalidate lower uis The invalidation logic is already there, we just have to set the `dimensions` so that it knows what we drew over. --- src/cata_imgui.cpp | 23 +++++++++++++++++++++++ src/cata_imgui.h | 6 ++++++ src/third-party/imgui/imconfig.h | 1 + 3 files changed, 30 insertions(+) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index 139a5796e2c11..10b454c7677a2 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -198,6 +198,22 @@ void cataimgui::client::process_input( void *input ) #endif +void cataimgui::point_to_imvec2( point *src, ImVec2 *dest ) +{ + if( src != nullptr && dest != nullptr ) { + dest->x = src->x; + dest->y = src->y; + } +} + +void cataimgui::imvec2_to_point( ImVec2 *src, point *dest ) +{ + if( src != nullptr && dest != nullptr ) { + dest->x = src->x; + dest->y = src->y; + } +} + void cataimgui::window::draw_colored_text( std::string const &text, const nc_color &color, float wrap_width, bool *is_selected, bool *is_focused, bool *is_hovered ) { @@ -303,6 +319,13 @@ class cataimgui::window_impl window_adaptor->is_imgui = true; window_adaptor->on_redraw( [this]( ui_adaptor & ) { win_base->draw(); + point catapos; + point catasize; + ImVec2 impos = ImGui::GetWindowPos(); + ImVec2 imsize = ImGui::GetWindowSize(); + imvec2_to_point( &impos, &catapos ); + imvec2_to_point( &imsize, &catasize ); + window_adaptor->position( catapos, catasize ); } ); window_adaptor->on_screen_resize( [this]( ui_adaptor & ) { is_resized = true; diff --git a/src/cata_imgui.h b/src/cata_imgui.h index 71b81b1e7cb7a..0068a53709a90 100644 --- a/src/cata_imgui.h +++ b/src/cata_imgui.h @@ -13,6 +13,9 @@ struct SDL_Renderer; struct SDL_Window; #endif +struct point; +class ImVec2; + namespace cataimgui { struct bounds { @@ -55,6 +58,9 @@ class client #endif }; +void point_to_imvec2( point *src, ImVec2 *dest ); +void imvec2_to_point( ImVec2 *src, point *dest ); + class window { std::unique_ptr p_impl; diff --git a/src/third-party/imgui/imconfig.h b/src/third-party/imgui/imconfig.h index 876cf32f72105..06fd1b7b80631 100644 --- a/src/third-party/imgui/imconfig.h +++ b/src/third-party/imgui/imconfig.h @@ -90,6 +90,7 @@ constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ operator MyVec4() const { return MyVec4(x,y,z,w); } */ + //---- ...Or use Dear ImGui's own very basic math operators. //#define IMGUI_DEFINE_MATH_OPERATORS