From be77b5f294e962cf323319b23771ee99bd017f7f Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 20 Dec 2019 13:10:58 +0800 Subject: [PATCH] Add code to handle screen padding in new iPhone --- lib/irrlicht/include/IrrlichtDevice.h | 4 +++ lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.h | 28 +++++++++++++++ lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm | 35 +++++++++++++++++-- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/lib/irrlicht/include/IrrlichtDevice.h b/lib/irrlicht/include/IrrlichtDevice.h index 9b21626a8..8082b5b08 100644 --- a/lib/irrlicht/include/IrrlichtDevice.h +++ b/lib/irrlicht/include/IrrlichtDevice.h @@ -314,6 +314,10 @@ namespace irr virtual bool deactivateDeviceMotion() { return false; } virtual bool isDeviceMotionActive() { return false; } virtual bool isDeviceMotionAvailable() { return false; } + virtual s32 getTopPadding() { return 0; } + virtual s32 getBottomPadding() { return 0; } + virtual s32 getLeftPadding() { return 0; } + virtual s32 getRightPadding() { return 0; } //! Check if a driver type is supported by the engine. /** Even if true is returned the driver may not be available for a configuration requested when creating the device. */ diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.h index a304f41da..21f1fef8c 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.h @@ -113,7 +113,30 @@ namespace irr m_touch_id_map.clear(); } void setUpsideDown(bool val) { m_upside_down = val; } + void setPaddings(float top, float bottom, float left, float right) + { + m_top_padding = top; + m_bottom_padding = bottom; + m_left_padding = left; + m_right_padding = right; + } static std::string getSystemLanguageCode(); + virtual s32 getTopPadding() + { + return m_top_padding * m_native_scale; + } + virtual s32 getBottomPadding() + { + return m_bottom_padding * m_native_scale; + } + virtual s32 getLeftPadding() + { + return m_left_padding * m_native_scale; + } + virtual s32 getRightPadding() + { + return m_right_padding * m_native_scale; + } private: void createWindow(); void createViewAndDriver(); @@ -124,6 +147,11 @@ namespace irr std::map m_touch_id_map; bool m_upside_down; + float m_top_padding; + float m_bottom_padding; + float m_left_padding; + float m_right_padding; + float m_native_scale; }; } diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm b/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm index bf644c573..b25ee576f 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm @@ -36,9 +36,20 @@ namespace irr @interface HideStatusBarView : UIViewController -(BOOL)prefersStatusBarHidden; -(BOOL)prefersHomeIndicatorAutoHidden; +-(void)viewDidAppear:(BOOL)animated; @end -@implementation HideStatusBarView {} +@implementation HideStatusBarView +{ + irr::CIrrDeviceiOS* Device; +} + +- (id)init: (irr::CIrrDeviceiOS*)device +{ + self = [super init]; + Device = device; + return self; +} -(BOOL)prefersStatusBarHidden { @@ -50,6 +61,18 @@ namespace irr return YES; } +-(void)viewDidAppear:(BOOL)animated +{ + [super viewDidAppear : animated]; + if (@available(iOS 11.0, *)) + { + Device->setPaddings(self.view.safeAreaInsets.top, + self.view.safeAreaInsets.bottom, + self.view.safeAreaInsets.left, + self.view.safeAreaInsets.right); + } +} + @end /* CIrrDelegateiOS */ @@ -427,6 +450,11 @@ namespace irr CIrrDeviceiOS::CIrrDeviceiOS(const SIrrlichtCreationParameters& params) : CIrrDeviceStub(params), DataStorage(0), Close(false), m_upside_down(false) { + m_top_padding = 0.0f; + m_bottom_padding = 0.0f; + m_left_padding = 0.0f; + m_right_padding = 0.0f; + m_native_scale = 1.0f; #ifdef _DEBUG setDebugName("CIrrDeviceiOS"); #endif @@ -819,7 +847,7 @@ namespace irr { SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); dataStorage->Window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - dataStorage->ViewController = [[HideStatusBarView alloc] init]; + dataStorage->ViewController = [[HideStatusBarView alloc] init: this]; dataStorage->Window.rootViewController = dataStorage->ViewController; [dataStorage->Window makeKeyAndVisible]; } @@ -846,7 +874,8 @@ namespace irr CIrrViewiOS* view = [[CIrrViewiOS alloc] initWithFrame:[[UIScreen mainScreen] bounds] forDevice:this forContext:dataStorage->m_eagl_context]; dataStorage->View = view; - view.contentScaleFactor = dataStorage->Window.screen.nativeScale; + m_native_scale = dataStorage->Window.screen.nativeScale; + view.contentScaleFactor = m_native_scale; // This will initialize the default framebuffer, which bind its valus to GL_FRAMEBUFFER_BINDING beginScene(); GLint default_fb = 0;