From f4233977e5c9ac575028e89ff70eafb65db48b0d Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 12 Jul 2020 08:34:59 +0800 Subject: [PATCH] Port moved height to android STK --- .../src/main/java/SuperTuxKartActivity.java | 3 +++ lib/irrlicht/include/IrrlichtDevice.h | 4 ---- .../source/Irrlicht/CIrrDeviceAndroid.cpp | 15 +++++++++++++++ lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp | 18 +++++++++++++++++- lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.h | 2 ++ lib/irrlicht/source/Irrlicht/CIrrDeviceStub.h | 2 -- src/font/font_drawer.cpp | 3 +-- src/graphics/2dutils.cpp | 12 ++++-------- src/graphics/fixed_pipeline_renderer.cpp | 5 ----- src/graphics/irr_driver.cpp | 9 --------- src/graphics/shader_based_renderer.cpp | 5 ----- src/guiengine/message_queue.cpp | 16 ++-------------- 12 files changed, 44 insertions(+), 50 deletions(-) diff --git a/android/src/main/java/SuperTuxKartActivity.java b/android/src/main/java/SuperTuxKartActivity.java index 5176a4e62..f4aaabc0b 100644 --- a/android/src/main/java/SuperTuxKartActivity.java +++ b/android/src/main/java/SuperTuxKartActivity.java @@ -36,6 +36,8 @@ public class SuperTuxKartActivity extends SDLActivity // ------------------------------------------------------------------------ private native void saveKeyboardHeight(int height); // ------------------------------------------------------------------------ + private native void saveMovedHeight(int height); + // ------------------------------------------------------------------------ private native static void addDNSSrvRecords(String name, int weight); // ------------------------------------------------------------------------ private void hideKeyboardNative(final boolean clear_text) @@ -106,6 +108,7 @@ public class SuperTuxKartActivity extends SDLActivity int margin = screen_height - m_bottom_y; if (keyboard_height > margin) moved_height = -keyboard_height + margin; + saveMovedHeight(-moved_height); SDLActivity.moveView(moved_height); } }); diff --git a/lib/irrlicht/include/IrrlichtDevice.h b/lib/irrlicht/include/IrrlichtDevice.h index ea242db1f..f18f65111 100644 --- a/lib/irrlicht/include/IrrlichtDevice.h +++ b/lib/irrlicht/include/IrrlichtDevice.h @@ -42,8 +42,6 @@ namespace irr */ class IrrlichtDevice : public virtual IReferenceCounted { - protected: - typedef s32 (*HeightFunc)(const IrrlichtDevice*); public: //! Runs the device. @@ -299,8 +297,6 @@ namespace irr virtual u32 getScreenHeight() const = 0; virtual u32 getOnScreenKeyboardHeight() const = 0; virtual s32 getMovedHeight() const = 0; - virtual void toggleOnScreenKeyboard(bool show, s32 type = 0) = 0; - virtual void registerGetMovedHeightFunction(HeightFunc) = 0; virtual bool activateAccelerometer(float updateInterval) { return false; } virtual bool deactivateAccelerometer() { return false; } diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp index e22f3db26..5fcb2b20d 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp @@ -17,11 +17,17 @@ using namespace irr; // Call when android keyboard is opened or close, and save its height for // moving screen std::atomic g_keyboard_height(0); +std::atomic g_moved_height(0); extern "C" int Android_getKeyboardHeight() { return g_keyboard_height.load(); } +extern "C" int Android_getMovedHeight() +{ + return g_moved_height.load(); +} + #define MAKE_ANDROID_SAVE_KBD_HEIGHT_CALLBACK(x) JNIEXPORT void JNICALL Java_ ## x##_SuperTuxKartActivity_saveKeyboardHeight(JNIEnv* env, jobject this_obj, jint height) #define ANDROID_SAVE_KBD_HEIGHT_CALLBACK(PKG_NAME) MAKE_ANDROID_SAVE_KBD_HEIGHT_CALLBACK(PKG_NAME) @@ -31,6 +37,15 @@ ANDROID_SAVE_KBD_HEIGHT_CALLBACK(ANDROID_PACKAGE_CALLBACK_NAME) g_keyboard_height.store((int)height); } +#define MAKE_ANDROID_SAVE_MOVED_HEIGHT_CALLBACK(x) JNIEXPORT void JNICALL Java_ ## x##_SuperTuxKartActivity_saveMovedHeight(JNIEnv* env, jobject this_obj, jint height) +#define ANDROID_SAVE_MOVED_HEIGHT_CALLBACK(PKG_NAME) MAKE_ANDROID_SAVE_MOVED_HEIGHT_CALLBACK(PKG_NAME) + +extern "C" +ANDROID_SAVE_MOVED_HEIGHT_CALLBACK(ANDROID_PACKAGE_CALLBACK_NAME) +{ + g_moved_height.store((int)height); +} + bool Android_isHardwareKeyboardConnected() { JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv(); diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp index d339ffa86..bbdce18c4 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp @@ -1247,10 +1247,26 @@ bool CIrrDeviceSDL::hasOnScreenKeyboard() const } +extern "C" int Android_getMovedHeight(); +s32 CIrrDeviceSDL::getMovedHeight() const +{ +#if defined(IOS_STK) + return SDL_GetMovedHeightByScreenKeyboard() * NativeScale; +#elif defined(ANDROID) + return Android_getMovedHeight(); +#else + return 0; +#endif +} + + +extern "C" int Android_getKeyboardHeight(); u32 CIrrDeviceSDL::getOnScreenKeyboardHeight() const { -#ifdef MOBILE_STK +#if defined(IOS_STK) return SDL_GetScreenKeyboardHeight() * NativeScale; +#elif defined(ANDROID) + return Android_getKeyboardHeight(); #else return 0; #endif diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.h index 258284cbf..231b6317f 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.h @@ -139,6 +139,8 @@ namespace irr virtual u32 getOnScreenKeyboardHeight() const; + virtual s32 getMovedHeight() const; + virtual bool activateAccelerometer(float updateInterval); virtual bool deactivateAccelerometer(); virtual bool isAccelerometerActive(); diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceStub.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceStub.h index 4c7d8be6f..ace03e3c9 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceStub.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceStub.h @@ -123,8 +123,6 @@ namespace irr virtual u32 getScreenHeight() const { return 0; } virtual u32 getOnScreenKeyboardHeight() const { return 0; } virtual s32 getMovedHeight() const { return 0; } - virtual void toggleOnScreenKeyboard(bool show, s32 type = 0) {} - virtual void registerGetMovedHeightFunction(HeightFunc) {} //! Returns true if system has touch device virtual bool supportsTouchDevice() const { return false; } diff --git a/src/font/font_drawer.cpp b/src/font/font_drawer.cpp index 5ea260d02..ba87a84aa 100644 --- a/src/font/font_drawer.cpp +++ b/src/font/font_drawer.cpp @@ -169,8 +169,7 @@ void FontDrawer::draw() const core::dimension2d& render_target_size = irr_driver->getActualScreenSize(); glScissor(g_clip->UpperLeftCorner.X, - (s32)render_target_size.Height - g_clip->LowerRightCorner.Y + - irr_driver->getDevice()->getMovedHeight(), + (s32)render_target_size.Height - g_clip->LowerRightCorner.Y, g_clip->getWidth(), g_clip->getHeight()); } else diff --git a/src/graphics/2dutils.cpp b/src/graphics/2dutils.cpp index 8b78fad0e..298467e71 100644 --- a/src/graphics/2dutils.cpp +++ b/src/graphics/2dutils.cpp @@ -285,8 +285,7 @@ void draw2DImage(const video::ITexture* texture, const core::dimension2d& render_target_size = irr_driver->getActualScreenSize(); glScissor(clip_rect->UpperLeftCorner.X, - (s32)render_target_size.Height - clip_rect->LowerRightCorner.Y + - irr_driver->getDevice()->getMovedHeight(), + (s32)render_target_size.Height - clip_rect->LowerRightCorner.Y, clip_rect->getWidth(), clip_rect->getHeight()); } @@ -397,8 +396,7 @@ void draw2DImage(const video::ITexture* texture, const core::dimension2d& render_target_size = irr_driver->getActualScreenSize(); glScissor(clip_rect->UpperLeftCorner.X, - (s32)render_target_size.Height - clip_rect->LowerRightCorner.Y + - irr_driver->getDevice()->getMovedHeight(), + (s32)render_target_size.Height - clip_rect->LowerRightCorner.Y, clip_rect->getWidth(), clip_rect->getHeight()); } if (colors) @@ -449,8 +447,7 @@ void draw2DImageCustomAlpha(const irr::video::ITexture* texture, const core::dimension2d& render_target_size = irr_driver->getActualScreenSize(); glScissor(clipRect->UpperLeftCorner.X, - (s32)render_target_size.Height - clipRect->LowerRightCorner.Y + - irr_driver->getDevice()->getMovedHeight(), + (s32)render_target_size.Height - clipRect->LowerRightCorner.Y, clipRect->getWidth(), clipRect->getHeight()); } @@ -562,8 +559,7 @@ void GL32_draw2DRectangle(video::SColor color, const core::rect& position, const core::dimension2d& render_target_size = irr_driver->getActualScreenSize(); glScissor(clip->UpperLeftCorner.X, - (s32)render_target_size.Height - clip->LowerRightCorner.Y + - irr_driver->getDevice()->getMovedHeight(), + (s32)render_target_size.Height - clip->LowerRightCorner.Y, clip->getWidth(), clip->getHeight()); } diff --git a/src/graphics/fixed_pipeline_renderer.cpp b/src/graphics/fixed_pipeline_renderer.cpp index 8f4330007..261c6a8cf 100644 --- a/src/graphics/fixed_pipeline_renderer.cpp +++ b/src/graphics/fixed_pipeline_renderer.cpp @@ -92,15 +92,10 @@ void FixedPipelineRenderer::render(float dt, bool is_loading) } // for igetDevice()->getMovedHeight(), - irr_driver->getActualScreenSize().Width, - irr_driver->getActualScreenSize().Height); GUIEngine::render(dt, is_loading); if (irr_driver->getRenderNetworkDebug() && !is_loading) irr_driver->renderNetworkDebug(); - glViewport(0, 0, irr_driver->getActualScreenSize().Width, - irr_driver->getActualScreenSize().Height); // Render the profiler if(UserConfigParams::m_profiler_enabled) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 0d49c0641..567d5c01a 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -2032,7 +2032,6 @@ void IrrDriver::update(float dt, bool is_loading) #endif World *world = World::getWorld(); - int moved_height = irr_driver->getDevice()->getMovedHeight(); if (world) { #ifndef SERVER_ONLY @@ -2041,11 +2040,7 @@ void IrrDriver::update(float dt, bool is_loading) GUIEngine::Screen* current_screen = GUIEngine::getCurrentScreen(); if (current_screen != NULL && current_screen->needs3D()) { - glViewport(0, moved_height, irr_driver->getActualScreenSize().Width, - irr_driver->getActualScreenSize().Height); GUIEngine::render(dt, is_loading); - glViewport(0, 0, irr_driver->getActualScreenSize().Width, - irr_driver->getActualScreenSize().Height); } if (!is_loading && Physics::get()) @@ -2064,15 +2059,11 @@ void IrrDriver::update(float dt, bool is_loading) m_video_driver->beginScene(/*backBuffer clear*/ true, /*zBuffer*/ true, video::SColor(255,100,101,140)); - glViewport(0, moved_height, irr_driver->getActualScreenSize().Width, - irr_driver->getActualScreenSize().Height); GUIEngine::render(dt, is_loading); if (m_render_nw_debug && !is_loading) { renderNetworkDebug(); } - glViewport(0, 0, irr_driver->getActualScreenSize().Width, - irr_driver->getActualScreenSize().Height); m_video_driver->endScene(); #endif } diff --git a/src/graphics/shader_based_renderer.cpp b/src/graphics/shader_based_renderer.cpp index 095da2974..67e703709 100644 --- a/src/graphics/shader_based_renderer.cpp +++ b/src/graphics/shader_based_renderer.cpp @@ -802,15 +802,10 @@ void ShaderBasedRenderer::render(float dt, bool is_loading) ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_GUI)); PROFILER_PUSH_CPU_MARKER("GUIEngine", 0x75, 0x75, 0x75); // Either render the gui, or the global elements of the race gui. - glViewport(0, irr_driver->getDevice()->getMovedHeight(), - irr_driver->getActualScreenSize().Width, - irr_driver->getActualScreenSize().Height); GUIEngine::render(dt, is_loading); if (irr_driver->getRenderNetworkDebug() && !is_loading) irr_driver->renderNetworkDebug(); - glViewport(0, 0, irr_driver->getActualScreenSize().Width, - irr_driver->getActualScreenSize().Height); PROFILER_POP_CPU_MARKER(); } diff --git a/src/guiengine/message_queue.cpp b/src/guiengine/message_queue.cpp index 17cd8e568..6f32011e0 100644 --- a/src/guiengine/message_queue.cpp +++ b/src/guiengine/message_queue.cpp @@ -217,13 +217,7 @@ public: int pos_transform = 0; if (m_container == g_container.get()) pos_transform = s_msg_raise; - int moved_height = 0; -#ifdef ANDROID - moved_height = irr_driver->getDevice()->getMovedHeight(); -#elif defined(IOS_STK) - moved_height = SDL_GetMovedHeightByScreenKeyboard() * - irr_driver->getDevice()->getNativeScale(); -#endif + int moved_height = irr_driver->getDevice()->getMovedHeight(); core::position2di raise = core::position2di(0, irr_driver->getDevice()->getOnScreenKeyboardHeight() - moved_height + pos_transform); @@ -329,13 +323,7 @@ public: { Message::draw(dt); m_display_timer = 9999999.9f; - int moved_height = 0; -#ifdef ANDROID - moved_height = irr_driver->getDevice()->getMovedHeight(); -#elif defined(IOS_STK) - moved_height = SDL_GetMovedHeightByScreenKeyboard() * - irr_driver->getDevice()->getNativeScale(); -#endif + int moved_height = irr_driver->getDevice()->getMovedHeight(); core::position2di raise = core::position2di(0, irr_driver->getDevice()->getOnScreenKeyboardHeight() - moved_height);