From 58a8764552240d0dfff03eb07e0b5836b3db7189 Mon Sep 17 00:00:00 2001 From: Kate M Date: Sat, 9 Mar 2024 13:10:04 -0500 Subject: [PATCH 1/4] Revert "Added preprocessor directives to allow building android without imgui. (#72013)" This reverts commit 19c877c68c5245e3a11769741bfc1bddb0dc534e. --- src/cata_imgui.cpp | 2 -- src/cata_imgui.h | 2 -- src/input_context.cpp | 7 +++---- src/main.cpp | 2 -- src/popup.cpp | 12 ++++++------ src/popup.h | 2 -- src/sdl_font.cpp | 5 +---- src/sdltiles.cpp | 8 -------- src/ui_manager.cpp | 2 -- src/ui_manager.h | 2 -- 10 files changed, 10 insertions(+), 34 deletions(-) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index 460d022a8e982..0ea539c50f673 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -1,4 +1,3 @@ -#if !defined(__ANDROID__) #include "cata_imgui.h" #include @@ -475,4 +474,3 @@ cataimgui::bounds cataimgui::window::get_bounds() { return { -1.f, -1.f, -1.f, -1.f }; } -#endif // #if defined(__ANDROID__) diff --git a/src/cata_imgui.h b/src/cata_imgui.h index 235ecf4949732..4b3b64bd5180d 100644 --- a/src/cata_imgui.h +++ b/src/cata_imgui.h @@ -1,4 +1,3 @@ -#if !defined(__ANDROID__) #pragma once #include #include @@ -107,4 +106,3 @@ void load_colors(); #endif } // namespace cataimgui -#endif // #if defined(__ANDROID) diff --git a/src/input_context.cpp b/src/input_context.cpp index 690b731c842d2..4f1f4b14df3b8 100644 --- a/src/input_context.cpp +++ b/src/input_context.cpp @@ -31,15 +31,14 @@ #include "string_input_popup.h" #include "translations.h" #include "ui_manager.h" +#if !defined(__ANDROID__) +#include "cata_imgui.h" +#include "imgui/imgui.h" enum class kb_menu_status { remove, reset, add, add_global, execute, show }; -#if !defined(__ANDROID__) -#include "cata_imgui.h" -#include "imgui/imgui.h" - class keybindings_ui : public cataimgui::window { // colors of the keybindings diff --git a/src/main.cpp b/src/main.cpp index a7ee587befb5c..00b1170413207 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -168,9 +168,7 @@ void exit_handler( int s ) } else #endif { -#if !defined(__ANDROID__) imclient.reset(); -#endif exit( exit_status ); } } diff --git a/src/popup.cpp b/src/popup.cpp index 45fe92c81df24..ea18b9fbfad03 100644 --- a/src/popup.cpp +++ b/src/popup.cpp @@ -525,6 +525,7 @@ std::shared_ptr query_popup::create_or_get_impl() } return impl; } +#endif query_popup::result query_popup::query_once_imgui() { @@ -620,13 +621,18 @@ query_popup::result query_popup::query_once_imgui() return res; } + query_popup::result query_popup::query() { +#if defined(__ANDROID__) + return query_legacy(); +#else if( get_options().has_option( "USE_IMGUI" ) && get_option( "USE_IMGUI" ) ) { return query_imgui(); } else { return query_legacy(); } +#endif } query_popup::result query_popup::query_imgui() @@ -639,13 +645,7 @@ query_popup::result query_popup::query_imgui() } while( res.wait_input ); return res; } -#else -query_popup::result query_popup::query() -{ - return query_legacy(); -} -#endif query_popup::result query_popup::query_legacy() { diff --git a/src/popup.h b/src/popup.h index ecb4259dd69c9..dfda725911d60 100644 --- a/src/popup.h +++ b/src/popup.h @@ -245,9 +245,7 @@ class query_popup }; std::weak_ptr adaptor; -#if !defined(__ANDROID__) std::weak_ptr p_impl; -#endif // UI caches mutable catacurses::window win; diff --git a/src/sdl_font.cpp b/src/sdl_font.cpp index 24652f80fdb22..c2b8d0b52d91f 100644 --- a/src/sdl_font.cpp +++ b/src/sdl_font.cpp @@ -3,9 +3,7 @@ #include "font_loader.h" #include "output.h" -#if !defined(__ANDROID) #include "imgui/imgui.h" -#endif #include "sdl_utils.h" #if defined(_WIN32) @@ -301,7 +299,7 @@ CachedTTFFont::CachedTTFFont( throw std::runtime_error( TTF_GetError() ); } TTF_SetFontStyle( font.get(), TTF_STYLE_NORMAL ); -#if !defined(__ANDROID__) + ImGuiIO &io = ImGui::GetIO(); if( io.FontDefault == nullptr && typeface.find( "unifont" ) != std::string::npos ) { static const std::array ranges = { @@ -317,7 +315,6 @@ CachedTTFFont::CachedTTFFont( }; io.FontDefault = io.Fonts->AddFontFromFileTTF( typeface.c_str(), fontsize, nullptr, ranges.data() ); } -#endif } SDL_Texture_Ptr CachedTTFFont::create_glyph( const SDL_Renderer_Ptr &renderer, diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index f13a5e3d67114..066a14a34e5cd 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -74,9 +74,7 @@ #include "wcwidth.h" #include "cata_imgui.h" -#if !defined(__ANDROID__) std::unique_ptr imclient; -#endif #if defined(__linux__) # include // getenv()/setenv() @@ -423,11 +421,9 @@ static void WinCreate() geometry = std::make_unique(); } -#if !defined(__ANDROID__) cataimgui::client::sdl_renderer = renderer.get(); cataimgui::client::sdl_window = window.get(); imclient = std::make_unique(); -#endif //io.Fonts->AddFontDefault(); //io.Fonts->Build(); @@ -438,9 +434,7 @@ static void WinDestroy() #if defined(__ANDROID__) touch_joystick.reset(); #endif -#if !defined(__ANDROID__) imclient.reset(); -#endif shutdown_sound(); tilecontext.reset(); gamepad::quit(); @@ -2886,9 +2880,7 @@ static void CheckMessages() bool render_target_reset = false; while( SDL_PollEvent( &ev ) ) { -#if !defined(__ANDROID__) imclient->process_input( &ev ); -#endif switch( ev.type ) { case SDL_WINDOWEVENT: switch( ev.window.event ) { diff --git a/src/ui_manager.cpp b/src/ui_manager.cpp index f8a5297ee664b..efa00c20d6468 100644 --- a/src/ui_manager.cpp +++ b/src/ui_manager.cpp @@ -455,10 +455,8 @@ void ui_adaptor::redraw_invalidated( ) emscripten_sleep( 1 ); #endif -#if !defined(__ANDROID__) imclient->end_frame(); imgui_frame_started = false; -#endif } void ui_adaptor::screen_resized() diff --git a/src/ui_manager.h b/src/ui_manager.h index cbf7d3958d411..48a1d2110c868 100644 --- a/src/ui_manager.h +++ b/src/ui_manager.h @@ -7,14 +7,12 @@ #include "cuboid_rectangle.h" #include "point.h" -#if !defined(__ANDROID__) namespace cataimgui { class client; } // namespace cataimgui extern std::unique_ptr imclient; -#endif namespace catacurses { From c34d18ff115c7059eb65ee32f22287f9aa14fdaf Mon Sep 17 00:00:00 2001 From: Kate M Date: Sat, 9 Mar 2024 17:26:41 -0500 Subject: [PATCH 2/4] Added ImGui support to Android. --- android/app/jni/src/Android.mk | 3 +- android/app/jni/src/third-party/Android.mk | 8 ++-- .../app/jni/src/third-party/imgui/Android.mk | 24 ++++++++++++ src/cata_imgui.cpp | 39 +++++++++++++++++++ src/cata_imgui.h | 2 + src/input_context.cpp | 11 +----- src/input_context.h | 6 --- src/main_menu.cpp | 6 --- src/popup.cpp | 18 --------- src/popup.h | 8 ---- src/sdltiles.cpp | 14 +++++-- src/ui_manager.cpp | 4 -- 12 files changed, 82 insertions(+), 61 deletions(-) create mode 100644 android/app/jni/src/third-party/imgui/Android.mk diff --git a/android/app/jni/src/Android.mk b/android/app/jni/src/Android.mk index 88a08bced6b47..d91ba00e34e27 100644 --- a/android/app/jni/src/Android.mk +++ b/android/app/jni/src/Android.mk @@ -10,7 +10,7 @@ LOCAL_CPP_FEATURES := exceptions rtti CATA_SRCS := $(sort $(wildcard $(LOCAL_PATH)/*.cpp)) LOCAL_SRC_FILES := $(sort $(CATA_SRCS:$(LOCAL_PATH)/%=%)) -LOCAL_STATIC_LIBRARIES := third-party +LOCAL_STATIC_LIBRARIES := third-party imgui LOCAL_SHARED_LIBRARIES := libhidapi SDL2 SDL2_mixer SDL2_image SDL2_ttf mpg123 @@ -28,3 +28,4 @@ endif include $(BUILD_SHARED_LIBRARY) include $(LOCAL_PATH)/../android/app/jni/src/third-party/Android.mk +include $(LOCAL_PATH)/../android/app/jni/src/third-party/imgui/Android.mk diff --git a/android/app/jni/src/third-party/Android.mk b/android/app/jni/src/third-party/Android.mk index a923b8182b81d..0c8d06f0c1a1e 100644 --- a/android/app/jni/src/third-party/Android.mk +++ b/android/app/jni/src/third-party/Android.mk @@ -1,17 +1,15 @@ -LOCAL_PATH := $(call my-dir)/../../../../../src/third-party - include $(CLEAR_VARS) -LOCAL_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/.. +LOCAL_C_INCLUDES := $(LOCAL_PATH)/third-party $(LOCAL_PATH) -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/third-party LOCAL_MODULE := third-party LOCAL_CPP_FEATURES := exceptions rtti # Add your application source files here... -FLATBUFFERS_SRCS := $(sort $(wildcard $(LOCAL_PATH)/flatbuffers/*.cpp)) +FLATBUFFERS_SRCS := $(sort $(wildcard $(LOCAL_PATH)/third-party/flatbuffers/*.cpp)) LOCAL_SRC_FILES := $(sort $(FLATBUFFERS_SRCS:$(LOCAL_PATH)/%=%)) LOCAL_CFLAGS += -DBACKTRACE=1 -DLOCALIZE=1 -Wextra -Wall -fsigned-char diff --git a/android/app/jni/src/third-party/imgui/Android.mk b/android/app/jni/src/third-party/imgui/Android.mk new file mode 100644 index 0000000000000..4aa5e610efcfb --- /dev/null +++ b/android/app/jni/src/third-party/imgui/Android.mk @@ -0,0 +1,24 @@ +include $(CLEAR_VARS) + +LOCAL_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/third-party + +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) + +LOCAL_MODULE := imgui + +LOCAL_CPP_FEATURES := exceptions rtti + +LOCAL_SHARED_LIBRARIES := SDL2 + +# Add your application source files here... +IMGUI_SRCS := $(sort $(wildcard $(LOCAL_PATH)/third-party/imgui/*.cpp)) +LOCAL_SRC_FILES := $(sort $(IMGUI_SRCS:$(LOCAL_PATH)/%=%)) + +LOCAL_CFLAGS += -DBACKTRACE=1 -DLOCALIZE=1 -fsigned-char + +ifeq ($(OS),Windows_NT) + # needed to bypass 8191 character limit on Windows command line + LOCAL_SHORT_COMMANDS = true +endif + +include $(BUILD_STATIC_LIBRARY) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index 0ea539c50f673..4a68bbec9a341 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -11,6 +11,8 @@ #include "output.h" #include "ui_manager.h" +static ImGuiKey cata_key_to_imgui( int cata_key ); + #if !(defined(TILES) || defined(WIN32)) #include #include @@ -205,6 +207,43 @@ void cataimgui::client::process_input( void *input ) #endif +static ImGuiKey cata_key_to_imgui( int cata_key ) +{ + switch( cata_key ) { + case KEY_UP: + return ImGuiKey_UpArrow; + case KEY_DOWN: + return ImGuiKey_DownArrow; + case KEY_LEFT: + return ImGuiKey_LeftArrow; + case KEY_RIGHT: + return ImGuiKey_RightArrow; + case KEY_ENTER: + return ImGuiKey_Enter; + case KEY_ESCAPE: + return ImGuiKey_Escape; + default: + if( cata_key >= 'a' && cata_key <= 'z' ) { + return static_cast( ImGuiKey_A + ( cata_key - 'a' ) ); + } else if( cata_key >= 'A' && cata_key <= 'Z' ) { + return static_cast( ImGuiKey_A + ( cata_key - 'A' ) ); + } else if( cata_key >= '0' && cata_key <= 'Z' ) { + return static_cast( ImGuiKey_A + ( cata_key - '0' ) ); + } + return ImGuiKey_None; + } +} + +void cataimgui::client::process_cata_input( const input_event &event ) +{ + if( event.type == input_event_t::keyboard_code || event.type == input_event_t::keyboard_char ) { + int code = event.get_first_input(); + ImGuiIO &io = ImGui::GetIO(); + io.AddKeyEvent( cata_key_to_imgui( code ), true ); + io.AddKeyEvent( cata_key_to_imgui( code ), false ); + } +} + void cataimgui::point_to_imvec2( point *src, ImVec2 *dest ) { if( src != nullptr && dest != nullptr ) { diff --git a/src/cata_imgui.h b/src/cata_imgui.h index 4b3b64bd5180d..8074be33f8f9f 100644 --- a/src/cata_imgui.h +++ b/src/cata_imgui.h @@ -6,6 +6,7 @@ #include class nc_color; +struct input_event; struct item_info_data; #if defined(WIN32) || defined(TILES) @@ -49,6 +50,7 @@ class client void new_frame(); void end_frame(); void process_input( void *input ); + void process_cata_input( const input_event &event ); #if !(defined(TILES) || defined(WIN32)) void upload_color_pair( int p, int f, int b ); void set_alloced_pair_count( short count ); diff --git a/src/input_context.cpp b/src/input_context.cpp index 4f1f4b14df3b8..0a3be42e0977e 100644 --- a/src/input_context.cpp +++ b/src/input_context.cpp @@ -31,7 +31,6 @@ #include "string_input_popup.h" #include "translations.h" #include "ui_manager.h" -#if !defined(__ANDROID__) #include "cata_imgui.h" #include "imgui/imgui.h" @@ -73,7 +72,6 @@ class keybindings_ui : public cataimgui::window init(); }; }; -#endif static const std::string default_context_id( "default" ); @@ -607,7 +605,6 @@ static const std::map fallback_keys = { { fallback_action::execute, '.' }, }; -#if !defined(__ANDROID__) keybindings_ui::keybindings_ui( bool permit_execute_action, input_context *parent ) : cataimgui::window( "KEYBINDINGS", ImGuiWindowFlags_NoNav ) { @@ -763,7 +760,7 @@ void keybindings_ui::init() { width = TERMX >= 100 ? 100 : 80; } -#endif + bool input_context::resolve_conflicts( const std::vector &events, const std::string &ignore_action ) { @@ -1287,7 +1284,6 @@ action_id input_context::display_menu_legacy( const bool permit_execute_action ) return action_to_execute; } -#if !defined(__ANDROID__) action_id input_context::display_menu_imgui( const bool permit_execute_action ) { @@ -1468,19 +1464,14 @@ action_id input_context::display_menu_imgui( const bool permit_execute_action ) return action_to_execute; } -#endif action_id input_context::display_menu( bool permit_execute_action ) { -#if defined(__ANDROID__) - return display_menu_legacy( permit_execute_action ); -#else if( get_options().has_option( "USE_IMGUI" ) && get_option( "USE_IMGUI" ) ) { return display_menu_imgui( permit_execute_action ); } else { return display_menu_legacy( permit_execute_action ); } -#endif } input_event input_context::get_raw_input() diff --git a/src/input_context.h b/src/input_context.h index 1d374ebd8e88a..b88624b4519c1 100644 --- a/src/input_context.h +++ b/src/input_context.h @@ -20,9 +20,7 @@ enum class kb_menu_status; class hotkey_queue; -#if !defined(__ANDROID__) class keybindings_ui; -#endif namespace catacurses { class window; @@ -40,9 +38,7 @@ class window; */ class input_context { -#if !defined(__ANDROID__) friend class keybindings_ui; -#endif public: #if defined(__ANDROID__) // Whatever's on top is our current input context. @@ -463,9 +459,7 @@ class input_context std::string_view phrase ) const; action_id display_menu_legacy( bool permit_execute_action ); -#if !defined(__ANDROID__) action_id display_menu_imgui( bool permit_execute_action ); -#endif }; class hotkey_queue diff --git a/src/main_menu.cpp b/src/main_menu.cpp index 013f6e26b3d57..4ce10014ce0b0 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -53,7 +53,6 @@ #include "wcwidth.h" #include "worldfactory.h" -#if !defined(__ANDROID__) #include "cata_imgui.h" #include "imgui/imgui.h" @@ -114,7 +113,6 @@ void demo_ui::run() } } } -#endif static const mod_id MOD_INFORMATION_dda( "dda" ); @@ -573,11 +571,9 @@ void main_menu::init_strings() vSettingsSubItems.emplace_back( pgettext( "Main Menu|Settings", "Atopickup" ) ); vSettingsSubItems.emplace_back( pgettext( "Main Menu|Settings", "Saemode" ) ); vSettingsSubItems.emplace_back( pgettext( "Main Menu|Settings", "Colos" ) ); -#if !defined(__ANDROID__) if( get_options().has_option( "USE_IMGUI" ) && get_option( "USE_IMGUI" ) ) { vSettingsSubItems.emplace_back( pgettext( "Main Menu|Settings", "mGui Demo Screen" ) ); } -#endif vSettingsHotkeys.clear(); for( const std::string &item : vSettingsSubItems ) { @@ -923,13 +919,11 @@ 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( "USE_IMGUI" ) ) { demo_ui demo; demo.run(); } -#endif } break; case main_menu_opts::WORLD: diff --git a/src/popup.cpp b/src/popup.cpp index ea18b9fbfad03..31080e65c67b3 100644 --- a/src/popup.cpp +++ b/src/popup.cpp @@ -11,7 +11,6 @@ #include "output.h" #include "ui_manager.h" #include "ui.h" -#if !defined(__ANDROID__) #include "cata_imgui.h" #include "imgui/imgui.h" @@ -140,7 +139,6 @@ void query_popup_impl::on_resized() } } } -#endif query_popup::query_popup() : cur( 0 ), default_text_color( c_white ), anykey( false ), cancel( false ), @@ -277,12 +275,10 @@ void query_popup::invalidate_ui() const } legacy_ui->mark_resize(); } -#if !defined(__ANDROID__) std::shared_ptr imgui_ui = p_impl.lock(); if( imgui_ui ) { imgui_ui->mark_resized(); } -#endif } static constexpr int border_width = 1; @@ -502,18 +498,13 @@ query_popup::result query_popup::query_once_legacy() query_popup::result query_popup::query_once() { -#if defined(__ANDROID__) - return query_once_legacy(); -#else if( get_options().has_option( "USE_IMGUI" ) && get_option( "USE_IMGUI" ) ) { return query_once_imgui(); } else { return query_once_legacy(); } -#endif } -#if !defined(__ANDROID__) std::shared_ptr query_popup::create_or_get_impl() { std::shared_ptr impl = p_impl.lock(); @@ -525,7 +516,6 @@ std::shared_ptr query_popup::create_or_get_impl() } return impl; } -#endif query_popup::result query_popup::query_once_imgui() { @@ -624,15 +614,11 @@ query_popup::result query_popup::query_once_imgui() query_popup::result query_popup::query() { -#if defined(__ANDROID__) - return query_legacy(); -#else if( get_options().has_option( "USE_IMGUI" ) && get_option( "USE_IMGUI" ) ) { return query_imgui(); } else { return query_legacy(); } -#endif } query_popup::result query_popup::query_imgui() @@ -703,13 +689,9 @@ bool query_popup::button::contains( const point &p ) const static_popup::static_popup() { -#if defined(__ANDROID__) - ui = create_or_get_adaptor(); -#else if( get_options().has_option( "USE_IMGUI" ) && get_option( "USE_IMGUI" ) ) { ui_imgui = create_or_get_impl(); } else { ui = create_or_get_adaptor(); } -#endif } diff --git a/src/popup.h b/src/popup.h index dfda725911d60..502a6a4aa7454 100644 --- a/src/popup.h +++ b/src/popup.h @@ -13,9 +13,7 @@ #include "input_enums.h" class ui_adaptor; -#if !defined(__ANDROID__) class query_popup_impl; -#endif /** * UI class for displaying messages or querying player input with popups. @@ -37,9 +35,7 @@ class query_popup_impl; class query_popup { -#if !defined(__ANDROID__) friend class query_popup_impl; -#endif public: /** * Query result returned by `query_once` and `query`. @@ -206,12 +202,10 @@ class query_popup * resizing of the popup. */ std::shared_ptr create_or_get_adaptor(); -#if !defined(__ANDROID__) std::shared_ptr create_or_get_impl(); result query_imgui(); result query_once_imgui(); -#endif result query_legacy(); result query_once_legacy(); @@ -302,9 +296,7 @@ class static_popup : public query_popup private: std::shared_ptr ui; -#if !defined(__ANDROID__) std::shared_ptr ui_imgui; -#endif }; #endif // CATA_SRC_POPUP_H diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 066a14a34e5cd..62acd2f7df7b0 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -2497,6 +2497,9 @@ void handle_finger_input( uint32_t ticks ) } } } + if( last_input.type != input_event_t::error ) { + imclient->process_cata_input( last_input ); + } } bool android_is_hardware_keyboard_available() @@ -2572,6 +2575,7 @@ static void CheckMessages() #if defined(__ANDROID__) if( visible_display_frame_dirty ) { needupdate = true; + ui_manager::redraw_invalidated(); visible_display_frame_dirty = false; } @@ -2612,6 +2616,7 @@ static void CheckMessages() touch_input_context = *new_input_context; needupdate = true; + ui_manager::redraw_invalidated(); } } @@ -2905,6 +2910,7 @@ static void CheckMessages() WindowHeight = ev.window.data2; SDL_Delay( 500 ); SDL_GetWindowSurface( window.get() ); + ui_manager::redraw_invalidated(); refresh_display(); needupdate = true; break; @@ -2998,6 +3004,7 @@ static void CheckMessages() !inp_mngr.get_keyname( lc, input_event_t::keyboard_char ).empty() ) { qsl.remove( last_input ); add_quick_shortcut( qsl, last_input, false, true ); + ui_manager::redraw_invalidated(); refresh_display(); } } else if( lc == '\n' || lc == KEY_ESCAPE ) { @@ -3064,6 +3071,7 @@ static void CheckMessages() touch_input_context.get_category() )]; qsl.remove( last_input ); add_quick_shortcut( qsl, last_input, false, true ); + ui_manager::redraw_invalidated(); refresh_display(); } else if( lc == '\n' || lc == KEY_ESCAPE ) { if( get_option( "ANDROID_AUTO_KEYBOARD" ) ) { @@ -3190,6 +3198,7 @@ static void CheckMessages() update_finger_repeat_delay(); } needupdate = true; // ensure virtual joystick and quick shortcuts redraw as we interact + ui_manager::redraw_invalidated(); finger_curr_x = ev.tfinger.x * WindowWidth; finger_curr_y = ev.tfinger.y * WindowHeight; @@ -3226,6 +3235,7 @@ static void CheckMessages() if( !is_quick_shortcut_touch ) { update_finger_repeat_delay(); } + ui_manager::redraw_invalidated(); needupdate = true; // ensure virtual joystick and quick shortcuts redraw as we interact } else if( ev.tfinger.fingerId == 1 ) { if( !is_quick_shortcut_touch ) { @@ -3410,6 +3420,7 @@ static void CheckMessages() finger_down_time = 0; finger_repeat_time = 0; needupdate = true; // ensure virtual joystick and quick shortcuts are updated properly + ui_manager::redraw_invalidated(); refresh_display(); // as above, but actually redraw it now as well } else if( ev.tfinger.fingerId == 1 ) { if( is_two_finger_touch ) { @@ -3456,9 +3467,6 @@ static void CheckMessages() ui_manager::invalidate( rectangle( point_zero, point( WindowWidth, WindowHeight ) ), false ); ui_manager::redraw_invalidated(); } - if( ui_adaptor::has_imgui() ) { - needupdate = true; - } if( needupdate ) { try_sdl_update(); } diff --git a/src/ui_manager.cpp b/src/ui_manager.cpp index efa00c20d6468..66f9e3623f3d4 100644 --- a/src/ui_manager.cpp +++ b/src/ui_manager.cpp @@ -21,9 +21,7 @@ using ui_stack_t = std::vector>; -#if !defined(__ANDROID__) static bool imgui_frame_started = false; -#endif static bool redraw_in_progress = false; static bool showing_debug_message = false; static bool restart_redrawing = false; @@ -343,13 +341,11 @@ void ui_adaptor::redraw_invalidated( ) if( test_mode || ui_stack.empty() ) { return; } -#if !defined(__ANDROID__) // This boolean is needed when a debug error is thrown inside redraw_invalidated if( !imgui_frame_started ) { imclient->new_frame(); } imgui_frame_started = true; -#endif restore_on_out_of_scope prev_redraw_in_progress( redraw_in_progress ); restore_on_out_of_scope prev_restart_redrawing( restart_redrawing ); From 516f44fab24829383197706b1d4b7d4f2a35bbaa Mon Sep 17 00:00:00 2001 From: Kate M Date: Tue, 12 Mar 2024 17:15:24 -0400 Subject: [PATCH 3/4] Fixing a drawing issue on Android where the screen size does not match the render output, we need to ignore that and just act like the render output is the screen size. --- src/third-party/imgui/imgui_impl_sdl2.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/third-party/imgui/imgui_impl_sdl2.cpp b/src/third-party/imgui/imgui_impl_sdl2.cpp index d28f879b6b9bd..0ab73ec3e82e7 100644 --- a/src/third-party/imgui/imgui_impl_sdl2.cpp +++ b/src/third-party/imgui/imgui_impl_sdl2.cpp @@ -621,9 +621,13 @@ void ImGui_ImplSDL2_NewFrame() SDL_GetRendererOutputSize(bd->Renderer, &display_w, &display_h); else SDL_GL_GetDrawableSize(bd->Window, &display_w, &display_h); +#if defined(__ANDROID__) + io.DisplaySize = ImVec2((float)display_w, (float)display_h); +#else io.DisplaySize = ImVec2((float)w, (float)h); if (w > 0 && h > 0) io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h); +#endif // Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution) // (Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. Happens in VMs and Emscripten, see #6189, #6114, #3644) From 24f174d4cdfea009c3497229bdb238acc77caf36 Mon Sep 17 00:00:00 2001 From: Kate Date: Wed, 13 Mar 2024 11:48:37 -0400 Subject: [PATCH 4/4] Update src/cata_imgui.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jianxiang Wang (王健翔) --- src/cata_imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index 4a68bbec9a341..d16f84ea05d7c 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -227,7 +227,7 @@ static ImGuiKey cata_key_to_imgui( int cata_key ) return static_cast( ImGuiKey_A + ( cata_key - 'a' ) ); } else if( cata_key >= 'A' && cata_key <= 'Z' ) { return static_cast( ImGuiKey_A + ( cata_key - 'A' ) ); - } else if( cata_key >= '0' && cata_key <= 'Z' ) { + } else if( cata_key >= '0' && cata_key <= '9' ) { return static_cast( ImGuiKey_A + ( cata_key - '0' ) ); } return ImGuiKey_None;