diff options
author | Marcel Admiraal <madmiraal@users.noreply.github.com> | 2022-04-26 11:40:57 +0200 |
---|---|---|
committer | Marcel Admiraal <madmiraal@users.noreply.github.com> | 2022-05-02 09:31:32 +0200 |
commit | 97e87a2daf27ff250e748cb25a29f1c91879c709 (patch) | |
tree | 2d033d6216df1a1d8a2df50cd44a0389ed35ed30 /platform/iphone | |
parent | bc7ccc909bb81334124fb24a771e148991fb0b3a (diff) |
Fix screen_get_usable_rect returning display safe area
Diffstat (limited to 'platform/iphone')
-rw-r--r-- | platform/iphone/display_server_iphone.h | 2 | ||||
-rw-r--r-- | platform/iphone/display_server_iphone.mm | 33 |
2 files changed, 19 insertions, 16 deletions
diff --git a/platform/iphone/display_server_iphone.h b/platform/iphone/display_server_iphone.h index 6ae190b81a..7af222e3f8 100644 --- a/platform/iphone/display_server_iphone.h +++ b/platform/iphone/display_server_iphone.h @@ -134,6 +134,8 @@ public: virtual void tts_resume() override; virtual void tts_stop() override; + virtual Rect2i get_display_safe_area() const override; + virtual int get_screen_count() const override; virtual Point2i screen_get_position(int p_screen = SCREEN_OF_MAIN_WINDOW) const override; virtual Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const override; diff --git a/platform/iphone/display_server_iphone.mm b/platform/iphone/display_server_iphone.mm index ec58ab195a..573ee9b7a8 100644 --- a/platform/iphone/display_server_iphone.mm +++ b/platform/iphone/display_server_iphone.mm @@ -360,6 +360,22 @@ void DisplayServerIPhone::tts_stop() { [tts stopSpeaking]; } +Rect2i DisplayServerIPhone::get_display_safe_area() const { + if (@available(iOS 11, *)) { + UIEdgeInsets insets = UIEdgeInsetsZero; + UIView *view = AppDelegate.viewController.godotView; + if ([view respondsToSelector:@selector(safeAreaInsets)]) { + insets = [view safeAreaInsets]; + } + float scale = screen_get_scale(); + Size2i insets_position = Size2i(insets.left, insets.top) * scale; + Size2i insets_size = Size2i(insets.left + insets.right, insets.top + insets.bottom) * scale; + return Rect2i(screen_get_position() + insets_position, screen_get_size() - insets_size); + } else { + return Rect2i(screen_get_position(), screen_get_size()); + } +} + int DisplayServerIPhone::get_screen_count() const { return 1; } @@ -379,22 +395,7 @@ Size2i DisplayServerIPhone::screen_get_size(int p_screen) const { } Rect2i DisplayServerIPhone::screen_get_usable_rect(int p_screen) const { - if (@available(iOS 11, *)) { - UIEdgeInsets insets = UIEdgeInsetsZero; - UIView *view = AppDelegate.viewController.godotView; - - if ([view respondsToSelector:@selector(safeAreaInsets)]) { - insets = [view safeAreaInsets]; - } - - float scale = screen_get_scale(p_screen); - Size2i insets_position = Size2i(insets.left, insets.top) * scale; - Size2i insets_size = Size2i(insets.left + insets.right, insets.top + insets.bottom) * scale; - - return Rect2i(screen_get_position(p_screen) + insets_position, screen_get_size(p_screen) - insets_size); - } else { - return Rect2i(screen_get_position(p_screen), screen_get_size(p_screen)); - } + return Rect2i(screen_get_position(p_screen), screen_get_size(p_screen)); } int DisplayServerIPhone::screen_get_dpi(int p_screen) const { |