Port moved height to android STK
This commit is contained in:
parent
8cc4dd3383
commit
f4233977e5
@ -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);
|
||||
}
|
||||
});
|
||||
|
@ -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; }
|
||||
|
@ -17,11 +17,17 @@ using namespace irr;
|
||||
// Call when android keyboard is opened or close, and save its height for
|
||||
// moving screen
|
||||
std::atomic<int> g_keyboard_height(0);
|
||||
std::atomic<int> 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();
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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; }
|
||||
|
@ -169,8 +169,7 @@ void FontDrawer::draw()
|
||||
const core::dimension2d<u32>& 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
|
||||
|
@ -285,8 +285,7 @@ void draw2DImage(const video::ITexture* texture,
|
||||
const core::dimension2d<u32>& 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<u32>& 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<u32>& 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<s32>& position,
|
||||
const core::dimension2d<u32>& 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());
|
||||
}
|
||||
|
||||
|
@ -92,15 +92,10 @@ void FixedPipelineRenderer::render(float dt, bool is_loading)
|
||||
} // for i<getNumKarts
|
||||
|
||||
// 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);
|
||||
|
||||
// Render the profiler
|
||||
if(UserConfigParams::m_profiler_enabled)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user