From 75f14740ad330fafdfec31f03fe062ea859b5d45 Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 4 May 2021 09:03:38 +0800 Subject: [PATCH] Add a way to print message to stk gui from java --- .../src/main/java/SuperTuxKartActivity.java | 2 ++ .../source/Irrlicht/CIrrDeviceAndroid.cpp | 23 +++++++++++++++++++ src/guiengine/message_queue.hpp | 2 -- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/SuperTuxKartActivity.java b/android/src/main/java/SuperTuxKartActivity.java index 3edcbeac8..5687de82c 100644 --- a/android/src/main/java/SuperTuxKartActivity.java +++ b/android/src/main/java/SuperTuxKartActivity.java @@ -71,6 +71,8 @@ public class SuperTuxKartActivity extends SDLActivity private float m_left_padding; private float m_right_padding; // ------------------------------------------------------------------------ + public native static void debugMsg(String msg); + // ------------------------------------------------------------------------ private native static void handlePadding(boolean val); // ------------------------------------------------------------------------ private native static void saveKeyboardHeight(int height); diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp index 237811888..66bc5197c 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp @@ -9,8 +9,10 @@ #include #include #include +#include #include #include "../../../../src/utils/utf8/unchecked.h" +#include "../../../../src/guiengine/message_queue.hpp" using namespace irr; @@ -34,6 +36,27 @@ extern "C" int Android_disablePadding() return g_disable_padding.load(); } +#define MAKE_DEBUG_MSG_CALLBACK(x) JNIEXPORT void JNICALL Java_ ## x##_SuperTuxKartActivity_debugMsg(JNIEnv* env, jclass cls, jstring msg) +#define ANDROID_DEBUG_MSG_CALLBACK(PKG_NAME) MAKE_DEBUG_MSG_CALLBACK(PKG_NAME) + +extern "C" +ANDROID_DEBUG_MSG_CALLBACK(ANDROID_PACKAGE_CALLBACK_NAME) +{ + if (msg == NULL) + return; + const uint16_t* utf16_text = + (const uint16_t*)env->GetStringChars(msg, NULL); + if (utf16_text == NULL) + return; + const size_t str_len = env->GetStringLength(msg); + std::u32string tmp; + utf8::unchecked::utf16to32( + utf16_text, utf16_text + str_len, std::back_inserter(tmp)); + env->ReleaseStringChars(msg, utf16_text); + core::stringw message = (wchar_t*)tmp.c_str(); + MessageQueue::add(MessageQueue::MT_GENERIC, message); +} + #define MAKE_ANDROID_SAVE_KBD_HEIGHT_CALLBACK(x) JNIEXPORT void JNICALL Java_ ## x##_SuperTuxKartActivity_saveKeyboardHeight(JNIEnv* env, jclass cls, jint height) #define ANDROID_SAVE_KBD_HEIGHT_CALLBACK(PKG_NAME) MAKE_ANDROID_SAVE_KBD_HEIGHT_CALLBACK(PKG_NAME) diff --git a/src/guiengine/message_queue.hpp b/src/guiengine/message_queue.hpp index d0f60059c..f7cbdb455 100644 --- a/src/guiengine/message_queue.hpp +++ b/src/guiengine/message_queue.hpp @@ -19,8 +19,6 @@ #ifndef HEADER_MESSAGE_QUEUE_HPP #define HEADER_MESSAGE_QUEUE_HPP -#include "guiengine/widgets/label_widget.hpp" - #include "irrString.h" #include