Add code to handle screen padding in new iPhone

This commit is contained in:
Benau 2019-12-20 13:10:58 +08:00
parent 84f91d58db
commit be77b5f294
3 changed files with 64 additions and 3 deletions

View File

@ -314,6 +314,10 @@ namespace irr
virtual bool deactivateDeviceMotion() { return false; } virtual bool deactivateDeviceMotion() { return false; }
virtual bool isDeviceMotionActive() { return false; } virtual bool isDeviceMotionActive() { return false; }
virtual bool isDeviceMotionAvailable() { 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. //! Check if a driver type is supported by the engine.
/** Even if true is returned the driver may not be available /** Even if true is returned the driver may not be available
for a configuration requested when creating the device. */ for a configuration requested when creating the device. */

View File

@ -113,7 +113,30 @@ namespace irr
m_touch_id_map.clear(); m_touch_id_map.clear();
} }
void setUpsideDown(bool val) { m_upside_down = val; } 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(); 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: private:
void createWindow(); void createWindow();
void createViewAndDriver(); void createViewAndDriver();
@ -124,6 +147,11 @@ namespace irr
std::map<void*, size_t> m_touch_id_map; std::map<void*, size_t> m_touch_id_map;
bool m_upside_down; bool m_upside_down;
float m_top_padding;
float m_bottom_padding;
float m_left_padding;
float m_right_padding;
float m_native_scale;
}; };
} }

View File

@ -36,9 +36,20 @@ namespace irr
@interface HideStatusBarView : UIViewController @interface HideStatusBarView : UIViewController
-(BOOL)prefersStatusBarHidden; -(BOOL)prefersStatusBarHidden;
-(BOOL)prefersHomeIndicatorAutoHidden; -(BOOL)prefersHomeIndicatorAutoHidden;
-(void)viewDidAppear:(BOOL)animated;
@end @end
@implementation HideStatusBarView {} @implementation HideStatusBarView
{
irr::CIrrDeviceiOS* Device;
}
- (id)init: (irr::CIrrDeviceiOS*)device
{
self = [super init];
Device = device;
return self;
}
-(BOOL)prefersStatusBarHidden -(BOOL)prefersStatusBarHidden
{ {
@ -50,6 +61,18 @@ namespace irr
return YES; 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 @end
/* CIrrDelegateiOS */ /* CIrrDelegateiOS */
@ -427,6 +450,11 @@ namespace irr
CIrrDeviceiOS::CIrrDeviceiOS(const SIrrlichtCreationParameters& params) CIrrDeviceiOS::CIrrDeviceiOS(const SIrrlichtCreationParameters& params)
: CIrrDeviceStub(params), DataStorage(0), Close(false), m_upside_down(false) : 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 #ifdef _DEBUG
setDebugName("CIrrDeviceiOS"); setDebugName("CIrrDeviceiOS");
#endif #endif
@ -819,7 +847,7 @@ namespace irr
{ {
SIrrDeviceiOSDataStorage* dataStorage = static_cast<SIrrDeviceiOSDataStorage*>(DataStorage); SIrrDeviceiOSDataStorage* dataStorage = static_cast<SIrrDeviceiOSDataStorage*>(DataStorage);
dataStorage->Window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 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.rootViewController = dataStorage->ViewController;
[dataStorage->Window makeKeyAndVisible]; [dataStorage->Window makeKeyAndVisible];
} }
@ -846,7 +874,8 @@ namespace irr
CIrrViewiOS* view = [[CIrrViewiOS alloc] initWithFrame:[[UIScreen mainScreen] bounds] CIrrViewiOS* view = [[CIrrViewiOS alloc] initWithFrame:[[UIScreen mainScreen] bounds]
forDevice:this forContext:dataStorage->m_eagl_context]; forDevice:this forContext:dataStorage->m_eagl_context];
dataStorage->View = view; 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 // This will initialize the default framebuffer, which bind its valus to GL_FRAMEBUFFER_BINDING
beginScene(); beginScene();
GLint default_fb = 0; GLint default_fb = 0;