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 7c49af9fd5e9b..9396ea5082e4d 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -11,6 +11,8 @@ #include "output.h" #include "ui_manager.h" +ImGuiKey cata_key_to_imgui( int cata_key ); + #if !(defined(TILES) || defined(WIN32)) #include #include @@ -206,6 +208,43 @@ void cataimgui::client::process_input( void *input ) #endif +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 043560b0400d4..537d944cc20b0 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. @@ -462,9 +458,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 7645cd5be1bb7..7658a16a62dbb 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..74b6dd7f77c96 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; @@ -329,7 +327,7 @@ bool ui_adaptor::has_imgui() } return false; } - +#include "imgui/imgui.h" void ui_adaptor::redraw() { if( !ui_stack.empty() ) { @@ -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 );