From 3cc52d68eda990b661506c07987aa6208e6f332e Mon Sep 17 00:00:00 2001 From: Bruno Levy Date: Wed, 26 Jul 2023 09:03:20 +0200 Subject: [PATCH] Big cleanup of Android-specific code: - moved all logging and debugging functions to android_utils - splitted a large function in user_callback_android.cpp into three functions (that handle fingers, stylus and mouse respectively) --- src/lib/geogram/basic/android_utils.cpp | 76 +++- src/lib/geogram/basic/android_utils.h | 41 ++- src/lib/geogram_gfx/gui/application.cpp | 9 +- .../geogram_gfx/gui/user_callback_android.cpp | 334 +++++++++++------- .../geogram_gfx/gui/user_callback_android.h | 4 +- .../imgui_ext/imgui_impl_android_ext.cpp | 75 +--- .../imgui_ext/imgui_impl_android_ext.h | 19 - 7 files changed, 325 insertions(+), 233 deletions(-) diff --git a/src/lib/geogram/basic/android_utils.cpp b/src/lib/geogram/basic/android_utils.cpp index 7a253163fe86..409d074b29c2 100644 --- a/src/lib/geogram/basic/android_utils.cpp +++ b/src/lib/geogram/basic/android_utils.cpp @@ -41,6 +41,7 @@ #include #include +#include #include namespace { @@ -411,7 +412,80 @@ namespace GEO { leave_JNI_function(app, env, thread_attached); return result; } - + } +} + +/*******************************************************************/ + +namespace { + using namespace GEO; + + static const char* event_type_to_str(int32_t event_type) { + switch(event_type) { + case AINPUT_EVENT_TYPE_KEY: + return "key"; + case AINPUT_EVENT_TYPE_MOTION: + return "motion"; + default: + return "unknown"; + } + } + + static const char* event_action_to_str(int32_t event_action) { + switch(event_action) { + case AKEY_EVENT_ACTION_DOWN: + return "key/motion_down"; + case AKEY_EVENT_ACTION_UP: + return "key/motion_up"; + case AMOTION_EVENT_ACTION_BUTTON_PRESS: + return "motion_button_press"; + case AMOTION_EVENT_ACTION_BUTTON_RELEASE: + return "motion_button_release"; + case AMOTION_EVENT_ACTION_HOVER_MOVE: + return "motion_hover_move"; + case AMOTION_EVENT_ACTION_MOVE: + return "motion_move"; + case AMOTION_EVENT_ACTION_SCROLL: + return "motion_scroll"; + default: + return "unknown"; + } + } + + static const char* event_tool_type_to_str(int32_t event_tool_type) { + switch(event_tool_type) { + case AMOTION_EVENT_TOOL_TYPE_MOUSE: + return "mouse"; + case AMOTION_EVENT_TOOL_TYPE_STYLUS: + return "stylus"; + case AMOTION_EVENT_TOOL_TYPE_ERASER: + return "eraser"; + case AMOTION_EVENT_TOOL_TYPE_FINGER: + return "finger"; + default: + return "unknown"; + } + } +} + +namespace GEO { + namespace AndroidUtils { + + void debug_show_event(AInputEvent* event) { + std::string msg = std::string("Event=") + " type:" + + std::string(event_type_to_str(AInputEvent_getType(event))); + + if(AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) { + msg += " action:" + std::string( + event_action_to_str(AMotionEvent_getAction(event)) + ) + " tool:" + std::string( + event_tool_type_to_str(AMotionEvent_getToolType(event,0)) + ) + " nb_pointers:" + ::GEO::String::to_string( + int(AMotionEvent_getPointerCount(event)) + ) ; + } + ::GEO::AndroidUtils::debug_log(msg); + } } } diff --git a/src/lib/geogram/basic/android_utils.h b/src/lib/geogram/basic/android_utils.h index 8449acd73860..db7d09fb287d 100644 --- a/src/lib/geogram/basic/android_utils.h +++ b/src/lib/geogram/basic/android_utils.h @@ -42,6 +42,8 @@ #include #include +#include +#include #include /** @@ -50,6 +52,7 @@ */ struct android_app; +struct AInputEvent; namespace GEO { namespace AndroidUtils { @@ -111,9 +114,43 @@ namespace GEO { * temporary files. */ std::string GEOGRAM_API temp_folder(android_app* app); - } -} + /** + * \brief Displays a message in the android log in + * Debug mode, ignored in Release mode. + * \details The message can be displayed using + * 'adb logcat | grep GEOGRAM' + * \param[in] str the message to be displayed + */ + inline void debug_log(const char* str) { + geo_argused(str); +#ifdef GEO_DEBUG + __android_log_print( + ANDROID_LOG_VERBOSE, "GEOGRAM", "DBG: %s", str + ); +#endif + } + /** + * \brief Displays a message in the android log in + * Debug mode, ignored in Release mode. + * \details The message can be displayed using + * 'adb logcat | grep GEOGRAM' + * \param[in] str the message to be displayed + */ + inline void debug_log(const std::string& str) { + debug_log(str.c_str()); + } + /** + * \brief Displays an android event in the android log in + * Debug mode, ignored in release mode. + * \details The message can be displayed using + * 'adb logcat | grep GEOGRAM' + * \param[in] event the event to be displayed + */ + void GEOGRAM_API debug_show_event(AInputEvent* event); + + } +} #endif diff --git a/src/lib/geogram_gfx/gui/application.cpp b/src/lib/geogram_gfx/gui/application.cpp index 1106f3811641..9c3bb26efd34 100644 --- a/src/lib/geogram_gfx/gui/application.cpp +++ b/src/lib/geogram_gfx/gui/application.cpp @@ -85,7 +85,6 @@ # include # include # include -# include #endif @@ -1453,7 +1452,9 @@ namespace GEO { // Check if we are exiting. if (data_->app->destroyRequested != 0) { - android_debug_log("Destroy requested, freeing resources"); + ::GEO::AndroidUtils::debug_log( + "Destroy requested, freeing resources" + ); ImGui_terminate(); GL_terminate(); return; @@ -1464,7 +1465,7 @@ namespace GEO { one_frame(); } } - android_debug_log("End of main loop"); + ::GEO::AndroidUtils::debug_log("End of main loop"); } namespace { @@ -1576,7 +1577,7 @@ namespace GEO { "keyboard", "mouse", "finger", "stylus", "unknown" }; - android_debug_log( + ::GEO::AndroidUtils::debug_log( std::string("mouse CB ") + " (" + String::to_string(x) + "," + String::to_string(y) + ")" + " btn=" + String::to_string(button) + diff --git a/src/lib/geogram_gfx/gui/user_callback_android.cpp b/src/lib/geogram_gfx/gui/user_callback_android.cpp index 933eb9979594..4243e33a81dc 100644 --- a/src/lib/geogram_gfx/gui/user_callback_android.cpp +++ b/src/lib/geogram_gfx/gui/user_callback_android.cpp @@ -37,14 +37,13 @@ * */ +#ifdef __ANDROID__ + #include #include #include - -#ifdef __ANDROID__ - +#include #include "imgui.h" -#include using namespace GEO; @@ -70,6 +69,17 @@ namespace { return EVENT_ACTION_UNKNOWN; } + /** + * \brief Gets from an android event the information in the form taken + * by the unified callback + * \param[in] event the android event + * \parma[out] x , y window coordinates, in 0..width-1, 0..height-1 + * \param[out] button one of 0 (left), 1 (right), 2 (middle) + * \param[out] action one of + * EVENT_ACTION_DOWN, EVENT_ACTION_UP, EVENT_ACTION_DRAG + * \param[out] source one of EVENT_SOURCE_FINGER, EVENT_SOURCE_STYLUS, + * EVENT_SOURCE_MOUSE + */ void decode_android_event( const AInputEvent* event, double& x, double& y, @@ -98,53 +108,41 @@ namespace { break; case AMOTION_EVENT_TOOL_TYPE_MOUSE: source = EVENT_SOURCE_MOUSE; - action = EVENT_ACTION_UNKNOWN; // TODO + action = EVENT_ACTION_UNKNOWN; break; default: - action = EVENT_ACTION_UNKNOWN; // TODO + action = EVENT_ACTION_UNKNOWN; break; } } - + + /** + * \brief Computes the barycenter of two points + * \param[in] p1 , p2 the two points + * \return the barycenter of \p p1 and \p p2 + */ inline ImVec2 barycenter(const ImVec2& p1, const ImVec2& p2) { return ImVec2(0.5f*(p1.x+p1.x), 0.5f*(p1.y+p2.y)); } + /** + * \brief Computes the distance between two points + * \param[in] p1 , p2 the two points + * \return the distance between \p p1 and \p p2 + */ inline float distance(const ImVec2& p1, const ImVec2& p2) { return ::sqrtf((p2.x-p1.x)*(p2.x-p1.x) + (p2.y-p1.y)*(p2.y-p1.y)); } -} -void ImGui_ImplAndroidExt_SetMouseUserCallback( - ImGui_ImplAndroidExt_MouseUserCallback CB -) { - g_mouse_CB = CB; -} - - -int32_t ImGui_ImplAndroidExt_HandleEventUserCallback( - struct android_app* app, AInputEvent* event -) { - - // Initially declared as static global so that key handler - // can 'push' button 1 when the back key event is synthetized - // by a right mouse click (but in fact does not work like that) - // TODO: remove it, not needed in fact. - static int mouse_handler_btn = -1; - - // Right mouse button is a KEY rather than a MOUSE BUTTON, - // hence, to properly handle events, we need to keep track - // of its state, in order to be able to generate DRAG events - // (because the mouse only sees a HOVER event). - static bool right_mouse_btn_pressed = false; - - if(g_mouse_CB == nullptr) { - return 0; - } - if( - AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION && - AMotionEvent_getToolType(event,0) == AMOTION_EVENT_TOOL_TYPE_FINGER + /** + * \brief Event translation for finger events + * \details used by ImGui_ImplAndroidExt_HandleEventUserCallback() + * \param[in] app the android app + * \param[in] event the android event + */ + int32_t HandleEventUserCallback_fingers( + struct android_app* app, AInputEvent* event ) { int nb_fingers = int(AMotionEvent_getPointerCount(event)); int32_t action = AMotionEvent_getAction(event); @@ -264,14 +262,21 @@ int32_t ImGui_ImplAndroidExt_HandleEventUserCallback( int button; int action; int source; + // TODO (clean): remove decode_android_event(), do the job here. decode_android_event(event, x, y, button, action, source); g_mouse_CB(mouse_pos.x, mouse_pos.y, button, action, source); } + return 1; } - if( - AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION && - AMotionEvent_getToolType(event,0) == AMOTION_EVENT_TOOL_TYPE_STYLUS + /** + * \brief Event translation for stylus events + * \details used by ImGui_ImplAndroidExt_HandleEventUserCallback() + * \param[in] app the android app + * \param[in] event the android event + */ + int32_t HandleEventUserCallback_stylus( + struct android_app* app, AInputEvent* event ) { float x = AMotionEvent_getX(event, 0); float y = AMotionEvent_getY(event, 0); @@ -283,118 +288,179 @@ int32_t ImGui_ImplAndroidExt_HandleEventUserCallback( g_mouse_CB( x, y, btn, decode_action(action), EVENT_SOURCE_STYLUS ); + return 1; } - if( - AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION && - AMotionEvent_getToolType(event,0) == AMOTION_EVENT_TOOL_TYPE_MOUSE + /** + * \brief Event translation for mouse events + * \details used by ImGui_ImplAndroidExt_HandleEventUserCallback(). + * Needs to be called for both MOTION and KEY events, because right + * mouse click is a KEY event. + * \param[in] app the android app + * \param[in] event the android event + */ + int32_t HandleEventUserCallback_mouse( + struct android_app* app, AInputEvent* event ) { - float x = AMotionEvent_getX(event, 0); - float y = AMotionEvent_getY(event, 0); + // Initially declared as static global so that key handler + // can 'push' button 1 when the back key event is synthetized + // by a right mouse click (but in fact does not work like that) + // TODO (clean): remove it, not needed in fact. + static int mouse_handler_btn = -1; + + // Right mouse button is a KEY rather than a MOUSE BUTTON, + // hence, to properly handle events, we need to keep track + // of its state, in order to be able to generate DRAG events + // (because the mouse only sees a HOVER event). + static bool right_mouse_btn_pressed = false; + + if( + AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION && + AMotionEvent_getToolType(event,0) == AMOTION_EVENT_TOOL_TYPE_MOUSE + ) { + float x = AMotionEvent_getX(event, 0); + float y = AMotionEvent_getY(event, 0); - int32_t action = AMotionEvent_getAction(event); + int32_t action = AMotionEvent_getAction(event); - if(action == AMOTION_EVENT_ACTION_SCROLL) { - - float hscroll = AMotionEvent_getAxisValue( - event, AMOTION_EVENT_AXIS_HSCROLL, 0 - ); + if(action == AMOTION_EVENT_ACTION_SCROLL) { + + float hscroll = AMotionEvent_getAxisValue( + event, AMOTION_EVENT_AXIS_HSCROLL, 0 + ); - float vscroll = AMotionEvent_getAxisValue( - event, AMOTION_EVENT_AXIS_VSCROLL, 0 - ); + float vscroll = AMotionEvent_getAxisValue( + event, AMOTION_EVENT_AXIS_VSCROLL, 0 + ); - // Synthetize btn 2 push, move, btn 2 release - g_mouse_CB( - x, y, 2, - EVENT_ACTION_DOWN, EVENT_SOURCE_MOUSE - ); - g_mouse_CB( - x + hscroll, y - 10.0f * vscroll, 2, - EVENT_ACTION_DRAG, EVENT_SOURCE_MOUSE - ); - g_mouse_CB( - x + hscroll, y - 10.0f * vscroll, 2, - EVENT_ACTION_UP, EVENT_SOURCE_MOUSE - ); - } if(action == AMOTION_EVENT_ACTION_HOVER_MOVE) { - if(right_mouse_btn_pressed) { + // Synthetize btn 2 push, move, btn 2 release g_mouse_CB( - x, y, 1, - EVENT_ACTION_DRAG, EVENT_SOURCE_MOUSE + x, y, 2, + EVENT_ACTION_DOWN, EVENT_SOURCE_MOUSE ); + g_mouse_CB( + x + hscroll, y - 10.0f * vscroll, 2, + EVENT_ACTION_DRAG, EVENT_SOURCE_MOUSE + ); + g_mouse_CB( + x + hscroll, y - 10.0f * vscroll, 2, + EVENT_ACTION_UP, EVENT_SOURCE_MOUSE + ); + } if(action == AMOTION_EVENT_ACTION_HOVER_MOVE) { + if(right_mouse_btn_pressed) { + g_mouse_CB( + x, y, 1, + EVENT_ACTION_DRAG, EVENT_SOURCE_MOUSE + ); + } + } else { + if( + action == AMOTION_EVENT_ACTION_BUTTON_PRESS || + action == AMOTION_EVENT_ACTION_DOWN + ) { + int32_t buttons = AMotionEvent_getButtonState(event); + if((buttons&AMOTION_EVENT_BUTTON_PRIMARY) != 0) { + mouse_handler_btn = 0; + } else if(((buttons & AMOTION_EVENT_BUTTON_SECONDARY)!=0)) { + mouse_handler_btn = 1; + } else if(((buttons & AMOTION_EVENT_BUTTON_TERTIARY) !=0)) { + mouse_handler_btn = 2; + } + } + if(decode_action(action) != EVENT_ACTION_UNKNOWN) { + g_mouse_CB( + x, y, mouse_handler_btn, + decode_action(action), EVENT_SOURCE_MOUSE + ); + } } - } else { - if( - action == AMOTION_EVENT_ACTION_BUTTON_PRESS || - action == AMOTION_EVENT_ACTION_DOWN - ) { - int32_t buttons = AMotionEvent_getButtonState(event); - if((buttons & AMOTION_EVENT_BUTTON_PRIMARY) != 0) { - mouse_handler_btn = 0; - } else if(((buttons & AMOTION_EVENT_BUTTON_SECONDARY) != 0)) { - mouse_handler_btn = 1; - } else if(((buttons & AMOTION_EVENT_BUTTON_TERTIARY) != 0)) { - mouse_handler_btn = 2; - } - } - if(decode_action(action) != EVENT_ACTION_UNKNOWN) { + } + + // Right mouse button handler (yes, it is a KEY !) + // It is because in Android, right mouse button is supposed + // to behave like the BACK key. + if(AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) { + ImGuiIO& io = ImGui::GetIO(); + int32_t action = AKeyEvent_getAction(event); + int32_t key = AKeyEvent_getKeyCode(event); + + if( + action == AKEY_EVENT_ACTION_UP && + key == AKEYCODE_BACK && + AInputEvent_getSource(event) == AINPUT_SOURCE_MOUSE + ) { + mouse_handler_btn = -1; g_mouse_CB( - x, y, mouse_handler_btn, - decode_action(action), EVENT_SOURCE_MOUSE + io.MousePos.x, io.MousePos.y, 1, + EVENT_ACTION_UP, EVENT_SOURCE_MOUSE ); + right_mouse_btn_pressed = false; } - } + + if(action == AKEY_EVENT_ACTION_DOWN && key == AKEYCODE_BACK) { + if(AInputEvent_getSource(event) != AINPUT_SOURCE_MOUSE) { + ::GEO::AndroidUtils::debug_log("Back softkey pushed"); + // If real back button, quit application + // (normally, returning 0 should do the same, but + // it does seem to work, to be understood...). + if(Application::instance() != nullptr) { + ::GEO::AndroidUtils::debug_log("Exiting application"); + Application::instance()->stop(); + } + } else { + mouse_handler_btn = 1; + // Since right mouse button is a KEY, when it is + // pressed, it repeatedly generate key pressed + // events, so we just capture the first one here. + if(!right_mouse_btn_pressed) { + g_mouse_CB( + io.MousePos.x, io.MousePos.y, 1, + EVENT_ACTION_DOWN, EVENT_SOURCE_MOUSE + ); + right_mouse_btn_pressed = true; + } + } + } + } + return 1; } +} - // Right mouse button handler (yes, it is a KEY !) - // It is because in Android, right mouse button is supposed - // to behave like the BACK key. - if(AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) { - ImGuiIO& io = ImGui::GetIO(); - int32_t action = AKeyEvent_getAction(event); - int32_t key = AKeyEvent_getKeyCode(event); - - if( - action == AKEY_EVENT_ACTION_UP && - key == AKEYCODE_BACK && - AInputEvent_getSource(event) == AINPUT_SOURCE_MOUSE - ) { - mouse_handler_btn = -1; - g_mouse_CB( - io.MousePos.x, io.MousePos.y, 1, - EVENT_ACTION_UP, EVENT_SOURCE_MOUSE - ); - right_mouse_btn_pressed = false; - } +/**************************************************************************/ - if(action == AKEY_EVENT_ACTION_DOWN && key == AKEYCODE_BACK) { - if(AInputEvent_getSource(event) != AINPUT_SOURCE_MOUSE) { - android_debug_log("Back softkey pushed"); - // If real back button, quit application - // (normally, returning 0 should do the same, but - // it does seem to work, to be understood...). - if(Application::instance() != nullptr) { - android_debug_log("Exiting application"); - Application::instance()->stop(); - } - } else { - mouse_handler_btn = 1; - // Since right mouse button is a KEY, when it is - // pressed, it repeatedly generate key pressed - // events, so we just capture the first one here. - if(!right_mouse_btn_pressed) { - g_mouse_CB( - io.MousePos.x, io.MousePos.y, 1, - EVENT_ACTION_DOWN, EVENT_SOURCE_MOUSE - ); - right_mouse_btn_pressed = true; - } - } - } - +int32_t ImGui_ImplAndroidExt_HandleEventUserCallback( + struct android_app* app, AInputEvent* event +) { + + if(g_mouse_CB == nullptr) { + return 0; + } + + int32_t type = AInputEvent_getType(event); + int32_t tool = AMotionEvent_getToolType(event,0); + + if(type==AINPUT_EVENT_TYPE_MOTION && tool==AMOTION_EVENT_TOOL_TYPE_FINGER) { + return HandleEventUserCallback_fingers(app, event); } + + if(type==AINPUT_EVENT_TYPE_MOTION && tool==AMOTION_EVENT_TOOL_TYPE_STYLUS) { + return HandleEventUserCallback_stylus(app, event); + } + + if( + (type==AINPUT_EVENT_TYPE_MOTION&&tool==AMOTION_EVENT_TOOL_TYPE_MOUSE) || + AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY + ) { + return HandleEventUserCallback_mouse(app, event); + } + return 1; } +void ImGui_ImplAndroidExt_SetMouseUserCallback( + ImGui_ImplAndroidExt_MouseUserCallback CB +) { + g_mouse_CB = CB; +} + #endif diff --git a/src/lib/geogram_gfx/gui/user_callback_android.h b/src/lib/geogram_gfx/gui/user_callback_android.h index f6ce8e6ef610..887e594d1e5f 100644 --- a/src/lib/geogram_gfx/gui/user_callback_android.h +++ b/src/lib/geogram_gfx/gui/user_callback_android.h @@ -43,7 +43,9 @@ /** * \file geogram_gfx/gui/user_callback_android.h * \brief functions to handle user input in the rendering area of - * a geoegram application + * a geogram application + * \details translates fingers,stylus,mouse android events into a unified + * callback. */ #ifdef __ANDROID__ diff --git a/src/lib/geogram_gfx/imgui_ext/imgui_impl_android_ext.cpp b/src/lib/geogram_gfx/imgui_ext/imgui_impl_android_ext.cpp index f4179f8290e8..52f8283ac6ae 100644 --- a/src/lib/geogram_gfx/imgui_ext/imgui_impl_android_ext.cpp +++ b/src/lib/geogram_gfx/imgui_ext/imgui_impl_android_ext.cpp @@ -51,75 +51,6 @@ #include #include -// [Bruno] for debugging -namespace { - - - static const char* event_type_to_str(int32_t event_type) { - switch(event_type) { - case AINPUT_EVENT_TYPE_KEY: - return "key"; - case AINPUT_EVENT_TYPE_MOTION: - return "motion"; - default: - return "unknown"; - } - } - - static const char* event_action_to_str(int32_t event_action) { - switch(event_action) { - case AKEY_EVENT_ACTION_DOWN: - return "key/motion_down"; - case AKEY_EVENT_ACTION_UP: - return "key/motion_up"; - case AMOTION_EVENT_ACTION_BUTTON_PRESS: - return "motion_button_press"; - case AMOTION_EVENT_ACTION_BUTTON_RELEASE: - return "motion_button_release"; - case AMOTION_EVENT_ACTION_HOVER_MOVE: - return "motion_hover_move"; - case AMOTION_EVENT_ACTION_MOVE: - return "motion_move"; - case AMOTION_EVENT_ACTION_SCROLL: - return "motion_scroll"; - default: - return "unknown"; - } - } - - static const char* event_tool_type_to_str(int32_t event_tool_type) { - switch(event_tool_type) { - case AMOTION_EVENT_TOOL_TYPE_MOUSE: - return "mouse"; - case AMOTION_EVENT_TOOL_TYPE_STYLUS: - return "stylus"; - case AMOTION_EVENT_TOOL_TYPE_ERASER: - return "eraser"; - case AMOTION_EVENT_TOOL_TYPE_FINGER: - return "finger"; - default: - return "unknown"; - } - } - - void debug_show_event(AInputEvent* event) { - std::string msg = std::string("Event=") + - " type:" + std::string(event_type_to_str(AInputEvent_getType(event))); - - if(AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) { - msg += - " action:" + - std::string(event_action_to_str(AMotionEvent_getAction(event))) + - " tool:" + - std::string(event_tool_type_to_str(AMotionEvent_getToolType(event,0)))+ - " nb_fingers:" + - ::GEO::String::to_string(int(AMotionEvent_getPointerCount(event))) ; - } - android_debug_log(msg); - } - -} - // Android data static double g_Time = 0.0; static android_app* g_app = nullptr; // [Bruno] @@ -242,7 +173,7 @@ static ImGuiKey ImGui_ImplAndroid_KeyCodeToImGuiKey(int32_t key_code) int32_t ImGui_ImplAndroidExt_HandleInputEvent(AInputEvent* input_event) { - debug_show_event(input_event); + ::GEO::AndroidUtils::debug_show_event(input_event); ImGuiIO& io = ImGui::GetIO(); int32_t event_type = AInputEvent_getType(input_event); switch (event_type) @@ -257,7 +188,7 @@ int32_t ImGui_ImplAndroidExt_HandleInputEvent(AInputEvent* input_event) // [Bruno] handle right mouse button if(event_key_code == AKEYCODE_BACK && AInputEvent_getSource(input_event) == AINPUT_SOURCE_MOUSE) { - android_debug_log("right mouse button event"); + ::GEO::AndroidUtils::debug_log("right mouse button event"); return 1; } else @@ -290,7 +221,7 @@ int32_t ImGui_ImplAndroidExt_HandleInputEvent(AInputEvent* input_event) char c = char(unicode); if(isprint(c)) { - android_debug_log("Char input: " + GEO::String::to_string(c)); + ::GEO::AndroidUtils::debug_log("Char input: " + GEO::String::to_string(c)); io.AddInputCharacter(c); } } diff --git a/src/lib/geogram_gfx/imgui_ext/imgui_impl_android_ext.h b/src/lib/geogram_gfx/imgui_ext/imgui_impl_android_ext.h index b5ee420c73ae..5923bc8c909e 100644 --- a/src/lib/geogram_gfx/imgui_ext/imgui_impl_android_ext.h +++ b/src/lib/geogram_gfx/imgui_ext/imgui_impl_android_ext.h @@ -32,24 +32,5 @@ IMGUI_IMPL_API int32_t ImGui_ImplAndroidExt_HandleInputEvent(AInputEvent* input IMGUI_IMPL_API void ImGui_ImplAndroidExt_Shutdown(); IMGUI_IMPL_API void ImGui_ImplAndroidExt_NewFrame(); -// [Bruno] temporary functions for debugging - -#include -#include - -inline void android_debug_log(const char* str) { - (void)str; // silence a warning in release mode -#ifdef GEO_DEBUG - __android_log_print( - ANDROID_LOG_VERBOSE, "GEOGRAM", "DBG: %s", str - ); -#endif -} - -inline void android_debug_log(const std::string& str) { - android_debug_log(str.c_str()); -} - - #endif // #ifndef IMGUI_DISABLE #endif // __ANDROID__