[Scummvm-git-logs] scummvm master -> 1b3c783b9eebbb3ee784a56db73b0a635328a4c3
larsamannen
noreply at scummvm.org
Sat Jul 8 16:49:59 UTC 2023
This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
885ee122c7 IOS7: Factorize code to get the interface orientation
147d41b360 IOS7: Add screen orientation settings to backend menu tab
34d7cd3769 IOS7: Implement setting of requested screen orientation
1b3c783b9e IOS7: Update current orientation before animation completes
Commit: 885ee122c7b77cdc30812af1e15c71093d160831
https://github.com/scummvm/scummvm/commit/885ee122c7b77cdc30812af1e15c71093d160831
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2023-07-08T18:49:54+02:00
Commit Message:
IOS7: Factorize code to get the interface orientation
Changed paths:
backends/platform/ios7/ios7_app_delegate.h
backends/platform/ios7/ios7_app_delegate.mm
backends/platform/ios7/ios7_scummvm_view_controller.h
backends/platform/ios7/ios7_scummvm_view_controller.mm
backends/platform/ios7/ios7_video.mm
diff --git a/backends/platform/ios7/ios7_app_delegate.h b/backends/platform/ios7/ios7_app_delegate.h
index 4e317adb43d..ec84e505516 100644
--- a/backends/platform/ios7/ios7_app_delegate.h
+++ b/backends/platform/ios7/ios7_app_delegate.h
@@ -32,6 +32,10 @@
+ (iOS7AppDelegate *)iOS7AppDelegate;
+ (iPhoneView *)iPhoneView;
+#if TARGET_OS_IOS
++ (UIInterfaceOrientation)currentOrientation;
+#endif
+
@end
#endif
diff --git a/backends/platform/ios7/ios7_app_delegate.mm b/backends/platform/ios7/ios7_app_delegate.mm
index 45f9207cb2c..1223281b4b0 100644
--- a/backends/platform/ios7/ios7_app_delegate.mm
+++ b/backends/platform/ios7/ios7_app_delegate.mm
@@ -85,19 +85,10 @@
- (void)applicationDidBecomeActive:(UIApplication *)application {
[_view applicationResume];
+#if TARGET_OS_IOS
// Make sure we have the correct orientation in case the orientation was changed while
// the app was inactive.
-#if TARGET_OS_IOS
- UIInterfaceOrientation interfaceOrientation = UIInterfaceOrientationUnknown;
- if (@available(iOS 13.0, *)) {
- interfaceOrientation = [[[_view window] windowScene] interfaceOrientation];
- } else {
- interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
- }
- if (interfaceOrientation != UIInterfaceOrientationUnknown) {
- [_view interfaceOrientationChanged:interfaceOrientation];
- [_controller setCurrentOrientation: interfaceOrientation];
- }
+ [_controller updateCurrentOrientation];
#endif
}
@@ -151,4 +142,11 @@
return appDelegate->_view;
}
+#if TARGET_OS_IOS
++ (UIInterfaceOrientation)currentOrientation {
+ iOS7AppDelegate *appDelegate = [self iOS7AppDelegate];
+ return [appDelegate->_controller currentOrientation];
+}
+#endif
+
@end
diff --git a/backends/platform/ios7/ios7_scummvm_view_controller.h b/backends/platform/ios7/ios7_scummvm_view_controller.h
index 9b6cf004d56..53676448d27 100644
--- a/backends/platform/ios7/ios7_scummvm_view_controller.h
+++ b/backends/platform/ios7/ios7_scummvm_view_controller.h
@@ -32,6 +32,10 @@
}
#if TARGET_OS_IOS
+- (UIInterfaceOrientation)interfaceOrientation;
+
+- (UIInterfaceOrientation)currentOrientation;
+-(void) updateCurrentOrientation;
-(void) setCurrentOrientation:(UIInterfaceOrientation)orientation;
#endif
diff --git a/backends/platform/ios7/ios7_scummvm_view_controller.mm b/backends/platform/ios7/ios7_scummvm_view_controller.mm
index 4b9e3b389d2..883154591ef 100644
--- a/backends/platform/ios7/ios7_scummvm_view_controller.mm
+++ b/backends/platform/ios7/ios7_scummvm_view_controller.mm
@@ -47,6 +47,24 @@
}
#if TARGET_OS_IOS
+- (UIInterfaceOrientation)interfaceOrientation {
+ if (@available(iOS 13.0, *)) {
+ return [[[[self view] window] windowScene] interfaceOrientation];
+ } else {
+ return [[UIApplication sharedApplication] statusBarOrientation];
+ }
+}
+
+- (UIInterfaceOrientation)currentOrientation {
+ return currentOrientation;
+}
+
+-(void) updateCurrentOrientation {
+ UIInterfaceOrientation interfaceOrientation = [self interfaceOrientation];
+ if (interfaceOrientation != UIInterfaceOrientationUnknown)
+ [self setCurrentOrientation: interfaceOrientation];
+}
+
-(void) setCurrentOrientation:(UIInterfaceOrientation)orientation {
if (orientation != currentOrientation) {
currentOrientation = orientation;
@@ -57,12 +75,7 @@
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
- UIInterfaceOrientation orientation = UIInterfaceOrientationUnknown;
- if (@available(iOS 13.0, *)) {
- orientation = [[[[self view] window] windowScene] interfaceOrientation];
- } else {
- orientation = [[UIApplication sharedApplication] statusBarOrientation];
- }
+ UIInterfaceOrientation orientation = [self interfaceOrientation];
if (orientation != UIInterfaceOrientationUnknown && orientation != currentOrientation) {
currentOrientation = orientation;
[[iOS7AppDelegate iPhoneView] interfaceOrientationChanged:orientation];
@@ -73,12 +86,7 @@
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
- UIInterfaceOrientation orientationAfter = UIInterfaceOrientationUnknown;
- if (@available(iOS 13.0, *)) {
- orientationAfter = [[[[self view] window] windowScene] interfaceOrientation];
- } else {
- orientationAfter = [[UIApplication sharedApplication] statusBarOrientation];
- }
+ UIInterfaceOrientation orientationAfter = [self interfaceOrientation];
if (orientationAfter != UIInterfaceOrientationUnknown && orientationAfter != currentOrientation) {
currentOrientation = orientationAfter;
[[iOS7AppDelegate iPhoneView] interfaceOrientationChanged:currentOrientation];
diff --git a/backends/platform/ios7/ios7_video.mm b/backends/platform/ios7/ios7_video.mm
index e1b9db7ca78..fca2d8c8ad0 100644
--- a/backends/platform/ios7/ios7_video.mm
+++ b/backends/platform/ios7/ios7_video.mm
@@ -349,12 +349,7 @@ bool iOS7_fetchEvent(InternalEvent *event) {
CGRect newFrame = self.frame;
#if TARGET_OS_IOS
UIEdgeInsets inset = [[[UIApplication sharedApplication] keyWindow] safeAreaInsets];
- UIInterfaceOrientation orientation = UIInterfaceOrientationUnknown;
- if (@available(iOS 13.0, *)) {
- orientation = [[[self window] windowScene] interfaceOrientation];
- } else {
- orientation = [[UIApplication sharedApplication] statusBarOrientation];
- }
+ UIInterfaceOrientation orientation = [iOS7AppDelegate currentOrientation];
// The code below adjust the screen size according to what Apple calls
// the "safe area". It also cover the cases when the software keyboard
Commit: 147d41b3600d2c55f59759c4e39d7094aaeb477c
https://github.com/scummvm/scummvm/commit/147d41b3600d2c55f59759c4e39d7094aaeb477c
Author: Lars Sundström (l.sundstrom at gmail.com)
Date: 2023-07-08T18:49:54+02:00
Commit Message:
IOS7: Add screen orientation settings to backend menu tab
Add options to let the user configure the screen orientation when
in games and in launcher. The option can be set per game as well
to allow for some games to start in landscape mode while others
in landscape mode.
This commit implements the options in the backend menu tab. The
code is very much similar as the one implemented in the Android
backend.
Changed paths:
backends/platform/ios7/ios7_common.h
backends/platform/ios7/ios7_options.mm
backends/platform/ios7/ios7_osys_main.h
diff --git a/backends/platform/ios7/ios7_common.h b/backends/platform/ios7/ios7_common.h
index 8f1ba8380ec..95fdec1e4bd 100644
--- a/backends/platform/ios7/ios7_common.h
+++ b/backends/platform/ios7/ios7_common.h
@@ -55,6 +55,7 @@ enum InputEvent {
};
enum ScreenOrientation {
+ kScreenOrientationAuto,
kScreenOrientationPortrait,
kScreenOrientationFlippedPortrait,
kScreenOrientationLandscape,
diff --git a/backends/platform/ios7/ios7_options.mm b/backends/platform/ios7/ios7_options.mm
index 15a40648e1f..68f1059099f 100644
--- a/backends/platform/ios7/ios7_options.mm
+++ b/backends/platform/ios7/ios7_options.mm
@@ -26,6 +26,7 @@
#include "gui/message.h"
#include "gui/ThemeEval.h"
#include "gui/widget.h"
+#include "gui/widgets/popup.h"
#include "common/translation.h"
#include "backends/platform/ios7/ios7_osys_main.h"
@@ -51,12 +52,22 @@ private:
// OptionsContainerWidget API
void defineLayout(GUI::ThemeEval &layouts, const Common::String &layoutName, const Common::String &overlayedLayout) const override;
void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) override;
+#if TARGET_OS_IOS
+ uint32 loadOrientation(const Common::String &setting, bool acceptDefault, uint32 defaultValue);
+ void saveOrientation(const Common::String &setting, uint32 orientation);
+#endif
GUI::CheckboxWidget *_onscreenCheckbox;
GUI::CheckboxWidget *_touchpadCheckbox;
GUI::CheckboxWidget *_clickAndDragCheckbox;
GUI::CheckboxWidget *_keyboardFnBarCheckbox;
-
+#if TARGET_OS_IOS
+ GUI::StaticTextWidget *_orientationDesc;
+ GUI::StaticTextWidget *_orientationMenusDesc;
+ GUI::PopUpWidget *_orientationMenusPopUp;
+ GUI::StaticTextWidget *_orientationGamesDesc;
+ GUI::PopUpWidget *_orientationGamesPopUp;
+#endif
bool _enabled;
};
@@ -70,6 +81,31 @@ IOS7OptionsWidget::IOS7OptionsWidget(GuiObject *boss, const Common::String &name
_clickAndDragCheckbox = new GUI::CheckboxWidget(widgetsBoss(), "IOS7OptionsDialog.ClickAndDragMode", _("Mouse-click-and-drag mode"));
_keyboardFnBarCheckbox = new GUI::CheckboxWidget(widgetsBoss(), "IOS7OptionsDialog.KeyboardFunctionBar", _("Show keyboard function bar"));
+#if TARGET_OS_IOS
+ _orientationDesc = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.OrientationText", _("Select the orientation:"));
+ if (inAppDomain) {
+ _orientationMenusDesc = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.OMenusText", _("In menus"));
+ _orientationMenusPopUp = new GUI::PopUpWidget(widgetsBoss(), "IOS7OptionsDialog.OMenus");
+ _orientationMenusPopUp->appendEntry(_("Automatic"), kScreenOrientationAuto);
+ _orientationMenusPopUp->appendEntry(_("Portrait"), kScreenOrientationPortrait);
+ _orientationMenusPopUp->appendEntry(_("Landscape"), kScreenOrientationLandscape);
+ } else {
+ _orientationMenusDesc = nullptr;
+ _orientationMenusPopUp = nullptr;
+ }
+
+ _orientationGamesDesc = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.OGamesText", _("In games"));
+ _orientationGamesPopUp = new GUI::PopUpWidget(widgetsBoss(), "IOS7OptionsDialog.OGames");
+
+ if (!inAppDomain) {
+ _orientationGamesPopUp->appendEntry(_("<default>"), kScreenOrientationAuto);
+ }
+
+ _orientationGamesPopUp->appendEntry(_("Automatic"), kScreenOrientationAuto);
+ _orientationGamesPopUp->appendEntry(_("Portrait"), kScreenOrientationPortrait);
+ _orientationGamesPopUp->appendEntry(_("Landscape"), kScreenOrientationLandscape);
+#endif
+
new GUI::ButtonWidget(widgetsBoss(), "IOS7OptionsDialog.ControlsHelp", _("Controls Help"), Common::U32String(), kHelpCmd);
// setEnabled is normally only called from the EditGameDialog, but some options (OnScreenControl)
@@ -93,6 +129,21 @@ void IOS7OptionsWidget::defineLayout(GUI::ThemeEval &layouts, const Common::Stri
.addPadding(0, 0, 0, 0)
.addWidget("ControlsHelp", "WideButton");
+#if TARGET_OS_IOS
+ layouts.addWidget("OrientationText", "", -1, layouts.getVar("Globals.Line.Height"));
+ if (inAppDomain) {
+ layouts.addLayout(GUI::ThemeLayout::kLayoutHorizontal)
+ .addPadding(0, 0, 0, 0)
+ .addWidget("OMenusText", "OptionsLabel")
+ .addWidget("OMenus", "PopUp")
+ .closeLayout();
+ }
+ layouts.addLayout(GUI::ThemeLayout::kLayoutHorizontal)
+ .addPadding(0, 0, 0, 0)
+ .addWidget("OGamesText", "OptionsLabel")
+ .addWidget("OGames", "PopUp")
+ .closeLayout();
+#endif
layouts.closeLayout()
.closeDialog();
}
@@ -138,36 +189,107 @@ void IOS7OptionsWidget::handleCommand(GUI::CommandSender *sender, uint32 cmd, ui
}
}
+#if TARGET_OS_IOS
+uint32 IOS7OptionsWidget::loadOrientation(const Common::String &setting, bool acceptDefault, uint32 defaultValue) {
+ if (!acceptDefault || ConfMan.hasKey(setting, _domain)) {
+ Common::String orientation = ConfMan.get(setting, _domain);
+ if (orientation == "auto") {
+ return kScreenOrientationAuto;
+ } else if (orientation == "portrait") {
+ return kScreenOrientationPortrait;
+ } else if (orientation == "landscape") {
+ return kScreenOrientationLandscape;
+ } else {
+ return defaultValue;
+ }
+ } else {
+ return kScreenOrientationAuto;
+ }
+}
+
+void IOS7OptionsWidget::saveOrientation(const Common::String &setting, uint32 orientation) {
+ switch (orientation) {
+ case kScreenOrientationAuto:
+ ConfMan.set(setting, "auto", _domain);
+ break;
+ case kScreenOrientationPortrait:
+ ConfMan.set(setting, "portrait", _domain);
+ break;
+ case kScreenOrientationLandscape:
+ ConfMan.set(setting, "landscape", _domain);
+ break;
+ default:
+ // default
+ ConfMan.removeKey(setting, _domain);
+ break;
+ }
+}
+#endif
+
void IOS7OptionsWidget::load() {
+ const bool inAppDomain = _domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain);
+
_onscreenCheckbox->setState(ConfMan.getBool("onscreen_control", _domain));
_touchpadCheckbox->setState(ConfMan.getBool("touchpad_mode", _domain));
_clickAndDragCheckbox->setState(ConfMan.getBool("clickanddrag_mode", _domain));
_keyboardFnBarCheckbox->setState(ConfMan.getBool("keyboard_fn_bar", _domain));
+
+#if TARGET_OS_IOS
+ if (inAppDomain) {
+ _orientationMenusPopUp->setSelectedTag(loadOrientation("orientation_menus", !inAppDomain, kScreenOrientationAuto));
+ }
+ _orientationGamesPopUp->setSelectedTag(loadOrientation("orientation_games", !inAppDomain, kScreenOrientationAuto));
+#endif
}
bool IOS7OptionsWidget::save() {
+ const bool inAppDomain = _domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain);
+
if (_enabled) {
ConfMan.setBool("onscreen_control", _onscreenCheckbox->getState(), _domain);
ConfMan.setBool("touchpad_mode", _touchpadCheckbox->getState(), _domain);
ConfMan.setBool("clickanddrag_mode", _clickAndDragCheckbox->getState(), _domain);
ConfMan.setBool("keyboard_fn_bar", _keyboardFnBarCheckbox->getState(), _domain);
+
+#if TARGET_OS_IOS
+ if (inAppDomain) {
+ saveOrientation("orientation_menus", _orientationMenusPopUp->getSelectedTag());
+ }
+ saveOrientation("orientation_games", _orientationGamesPopUp->getSelectedTag());
+#endif
} else {
ConfMan.removeKey("onscreen_control", _domain);
ConfMan.removeKey("touchpad_mode", _domain);
ConfMan.removeKey("clickanddrag_mode", _domain);
ConfMan.removeKey("keyboard_fn_bar", _domain);
+
+#if TARGET_OS_IOS
+ if (inAppDomain) {
+ ConfMan.removeKey("orientation_menus", _domain);
+ }
+ ConfMan.removeKey("orientation_games", _domain);
+#endif
}
return true;
}
bool IOS7OptionsWidget::hasKeys() {
- return ConfMan.hasKey("onscreen_control", _domain) ||
- ConfMan.hasKey("touchpad_mode", _domain) ||
- ConfMan.hasKey("clickanddrag_mode", _domain);
+ bool hasKeys = ConfMan.hasKey("onscreen_control", _domain) ||
+ ConfMan.hasKey("touchpad_mode", _domain) ||
+ ConfMan.hasKey("clickanddrag_mode", _domain);
+
+#if TARGET_OS_IOS
+ hasKeys = hasKeys || (_domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain) && ConfMan.hasKey("orientation_menus", _domain)) ||
+ ConfMan.hasKey("orientation_games", _domain);
+#endif
+
+ return hasKeys;
+
}
void IOS7OptionsWidget::setEnabled(bool e) {
+ const bool inAppDomain = _domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain);
_enabled = e;
#if TARGET_OS_IOS && defined (__IPHONE_15_0)
@@ -187,6 +309,15 @@ void IOS7OptionsWidget::setEnabled(bool e) {
#endif
_clickAndDragCheckbox->setEnabled(e);
_keyboardFnBarCheckbox->setEnabled(e);
+
+#if TARGET_OS_IOS
+ if (inAppDomain) {
+ _orientationMenusDesc->setEnabled(e);
+ _orientationMenusPopUp->setEnabled(e);
+ }
+ _orientationGamesDesc->setEnabled(e);
+ _orientationGamesPopUp->setEnabled(e);
+#endif
}
GUI::OptionsContainerWidget *OSystem_iOS7::buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const {
@@ -198,6 +329,11 @@ void OSystem_iOS7::registerDefaultSettings(const Common::String &target) const {
ConfMan.registerDefault("touchpad_mode", !iOS7_isBigDevice());
ConfMan.registerDefault("clickanddrag_mode", false);
ConfMan.registerDefault("keyboard_fn_bar", true);
+
+#if TARGET_OS_IOS
+ ConfMan.registerDefault("orientation_menus", "auto");
+ ConfMan.registerDefault("orientation_games", "auto");
+#endif
}
void OSystem_iOS7::applyBackendSettings() {
@@ -205,3 +341,28 @@ void OSystem_iOS7::applyBackendSettings() {
_touchpadModeEnabled = ConfMan.getBool("touchpad_mode");
_mouseClickAndDragEnabled = ConfMan.getBool("clickanddrag_mode");
}
+
+#if TARGET_OS_IOS
+void OSystem_iOS7::applyOrientationSettings() {
+ const Common::String activeDomain = ConfMan.getActiveDomainName();
+ const bool inAppDomain = activeDomain.empty() ||
+ activeDomain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain);
+
+ Common::String setting;
+
+ if (inAppDomain) {
+ setting = "orientation_menus";
+ } else {
+ setting = "orientation_games";
+ }
+
+ Common::String orientation = ConfMan.get(setting);
+ if (orientation == "portrait") {
+ // TODO: Call function to trigger orientation
+ } else if (orientation == "landscape") {
+ // TODO: Call function to trigger orientation
+ } else {
+ // TODO: Call function to trigger orientation
+ }
+ }
+#endif
diff --git a/backends/platform/ios7/ios7_osys_main.h b/backends/platform/ios7/ios7_osys_main.h
index 34da661f311..d36a8e71fda 100644
--- a/backends/platform/ios7/ios7_osys_main.h
+++ b/backends/platform/ios7/ios7_osys_main.h
@@ -101,6 +101,10 @@ public:
bool touchpadModeEnabled() const;
+#if TARGET_OS_IOS
+ void applyOrientationSettings();
+#endif
+
uint createOpenGLContext();
void destroyOpenGLContext();
void refreshScreen() const;
Commit: 34d7cd3769aa7f92f9cd0c60362c35579de2619c
https://github.com/scummvm/scummvm/commit/34d7cd3769aa7f92f9cd0c60362c35579de2619c
Author: Lars Sundström (l.sundstrom at gmail.com)
Date: 2023-07-08T18:49:54+02:00
Commit Message:
IOS7: Implement setting of requested screen orientation
Implement function to trigger the device to set the screen
orientation according to the configration in the backend
options tab.
The implementation to trigger the setting is different for
devices running iOS prior version 16 and version 16+.
The screen orientation update is triggered when user has
applied the setting in the backen options tab, when the GUI
launcher is loaded and when starting a game.
The orientation is only changed if going from any portrait
mode to any landscape mode and the opposite.
Based on the setting, an UIInterfaceOrientationMask property
is set to hold the allowed interface orientations. If the
setting is "Portrait" the property will be set to
UIInterfaceOrientationMaskPortrait, allowing to only change
the orientation to normal or upside down portrait modes.
If the setting is "Landscape" the UIInterfaceOrientationMask
will be set to UIInterfaceOrientationMaskLandscape allowing
the device to rotate the screen orientation only to either
right or left landscape mode. If set to "Auto" all orientations
will be allowed.
When the device orientation changes, the system calls the
instance property method supportedInterfaceOrientations on the
root view controller or the topmost modal view controller that
fills the window. If the view controller supports the new
orientation, the system rotates the window and the view
controller. The system only calls this method if the view
controller's shouldAutorotate method returns YES, which is the
default value.
The event handler is refactored to receive the internal screen
orientation value instead of the enum value of the UIKit enum
UIInterfaceOrientation. The convertion from UIInterfaceOrientation
to ScreenOrientation is done in iPhoneView class instead when
sending the new orientation value to the event handler.
This also makes the convertion aligned with the screen orientation
settings in the function setSupportedScreenOrientation.
Changed paths:
backends/platform/ios7/ios7_options.mm
backends/platform/ios7/ios7_osys_events.cpp
backends/platform/ios7/ios7_osys_main.cpp
backends/platform/ios7/ios7_osys_main.h
backends/platform/ios7/ios7_osys_video.mm
backends/platform/ios7/ios7_scummvm_view_controller.mm
backends/platform/ios7/ios7_video.h
backends/platform/ios7/ios7_video.mm
diff --git a/backends/platform/ios7/ios7_options.mm b/backends/platform/ios7/ios7_options.mm
index 68f1059099f..03093c85c88 100644
--- a/backends/platform/ios7/ios7_options.mm
+++ b/backends/platform/ios7/ios7_options.mm
@@ -340,6 +340,10 @@ void OSystem_iOS7::applyBackendSettings() {
virtualController(ConfMan.getBool("onscreen_control"));
_touchpadModeEnabled = ConfMan.getBool("touchpad_mode");
_mouseClickAndDragEnabled = ConfMan.getBool("clickanddrag_mode");
+
+#if TARGET_OS_IOS
+ applyOrientationSettings();
+#endif
}
#if TARGET_OS_IOS
@@ -358,11 +362,11 @@ void OSystem_iOS7::applyOrientationSettings() {
Common::String orientation = ConfMan.get(setting);
if (orientation == "portrait") {
- // TODO: Call function to trigger orientation
+ setSupportedScreenOrientation(kScreenOrientationPortrait);
} else if (orientation == "landscape") {
- // TODO: Call function to trigger orientation
+ setSupportedScreenOrientation(kScreenOrientationLandscape);
} else {
- // TODO: Call function to trigger orientation
+ setSupportedScreenOrientation(kScreenOrientationAuto);
}
}
#endif
diff --git a/backends/platform/ios7/ios7_osys_events.cpp b/backends/platform/ios7/ios7_osys_events.cpp
index 6fafc200f94..444b7537107 100644
--- a/backends/platform/ios7/ios7_osys_events.cpp
+++ b/backends/platform/ios7/ios7_osys_events.cpp
@@ -364,23 +364,7 @@ void OSystem_iOS7::handleEvent_mouseEvent(Common::Event &event, int relX, int re
void OSystem_iOS7::handleEvent_orientationChanged(int orientation) {
//printf("Orientation: %i\n", orientation);
- ScreenOrientation newOrientation;
- switch (orientation) {
- case 1:
- newOrientation = kScreenOrientationPortrait;
- break;
- case 2:
- newOrientation = kScreenOrientationFlippedPortrait;
- break;
- case 3:
- newOrientation = kScreenOrientationLandscape;
- break;
- case 4:
- newOrientation = kScreenOrientationFlippedLandscape;
- break;
- default:
- return;
- }
+ ScreenOrientation newOrientation = (ScreenOrientation)orientation;
if (_screenOrientation != newOrientation) {
_screenOrientation = newOrientation;
diff --git a/backends/platform/ios7/ios7_osys_main.cpp b/backends/platform/ios7/ios7_osys_main.cpp
index d4163e2e5e9..1ecc6cb235a 100644
--- a/backends/platform/ios7/ios7_osys_main.cpp
+++ b/backends/platform/ios7/ios7_osys_main.cpp
@@ -90,7 +90,7 @@ public:
OSystem_iOS7::OSystem_iOS7() :
_mixer(NULL), _lastMouseTap(0), _queuedEventTime(0),
_secondaryTapped(false), _lastSecondaryTap(0),
- _screenOrientation(kScreenOrientationFlippedLandscape),
+ _screenOrientation(kScreenOrientationAuto),
_timeSuspended(0) {
_queuedInputEvent.type = Common::EVENT_INVALID;
_touchpadModeEnabled = ConfMan.getBool("touchpad_mode");
diff --git a/backends/platform/ios7/ios7_osys_main.h b/backends/platform/ios7/ios7_osys_main.h
index d36a8e71fda..e51026984f3 100644
--- a/backends/platform/ios7/ios7_osys_main.h
+++ b/backends/platform/ios7/ios7_osys_main.h
@@ -103,6 +103,7 @@ public:
#if TARGET_OS_IOS
void applyOrientationSettings();
+ void setSupportedScreenOrientation(ScreenOrientation screenOrientation);
#endif
uint createOpenGLContext();
diff --git a/backends/platform/ios7/ios7_osys_video.mm b/backends/platform/ios7/ios7_osys_video.mm
index 41f49aca099..2db4bbc090b 100644
--- a/backends/platform/ios7/ios7_osys_video.mm
+++ b/backends/platform/ios7/ios7_osys_video.mm
@@ -95,6 +95,8 @@ void OSystem_iOS7::engineInit() {
[[iOS7AppDelegate iPhoneView] setIsInGame:YES];
#if TARGET_OS_IOS
+ applyOrientationSettings();
+
// Automatically open the keyboard when starting a game and in portrait mode.
// This is preferred for text input games and there's a lot of screen space to
// utilize for the keyboard anyway.
@@ -116,6 +118,8 @@ void OSystem_iOS7::engineDone() {
[[iOS7AppDelegate iPhoneView] setIsInGame:NO];
#if TARGET_OS_IOS
+ applyOrientationSettings();
+
// Hide keyboard when going back to launcher
execute_on_main_thread(^ {
[[iOS7AppDelegate iPhoneView] hideKeyboard];
@@ -160,6 +164,70 @@ void OSystem_iOS7::setShowKeyboard(bool show) {
}
}
+#if TARGET_OS_IOS
+void OSystem_iOS7::setSupportedScreenOrientation(ScreenOrientation screenOrientation) {
+ bool shouldUpdateScreenOrientation = false;
+
+ switch (screenOrientation) {
+ case kScreenOrientationPortrait:
+ case kScreenOrientationFlippedPortrait:
+ [[iOS7AppDelegate iPhoneView] setSupportedScreenOrientations:UIInterfaceOrientationMaskPortrait];
+ if (_screenOrientation != kScreenOrientationPortrait &&
+ _screenOrientation != kScreenOrientationFlippedPortrait) {
+ shouldUpdateScreenOrientation = true;
+ }
+ break;
+ case kScreenOrientationLandscape:
+ case kScreenOrientationFlippedLandscape:
+ [[iOS7AppDelegate iPhoneView] setSupportedScreenOrientations:UIInterfaceOrientationMaskLandscape];
+ if (_screenOrientation != kScreenOrientationLandscape &&
+ _screenOrientation != kScreenOrientationFlippedLandscape) {
+ shouldUpdateScreenOrientation = true;
+ }
+ break;
+ case kScreenOrientationAuto:
+ default:
+ [[iOS7AppDelegate iPhoneView] setSupportedScreenOrientations:UIInterfaceOrientationMaskAll];
+ break;
+ }
+
+#ifdef __IPHONE_16_0
+ if (@available(iOS 16.0, *)) {
+ execute_on_main_thread(^ {
+ [UIViewParentController([iOS7AppDelegate iPhoneView]) setNeedsUpdateOfSupportedInterfaceOrientations];
+ });
+ // We don't end up here if orientation is set to auto.
+ // Also, we won't know for sure if it will select right or left for landscape
+ // orientation, or normal or upside down (most probably normal) for portrait.
+ // The _screenOrientation will be set accordingly when handling the orientationChanged
+ // event so just set it to what we're given for now.
+ _screenOrientation = screenOrientation;
+ } else
+#endif
+ if (shouldUpdateScreenOrientation) {
+ switch (screenOrientation) {
+ case kScreenOrientationPortrait:
+ case kScreenOrientationFlippedPortrait:
+ execute_on_main_thread(^ {
+ [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
+ });
+ _screenOrientation = kScreenOrientationPortrait;
+ break;
+ case kScreenOrientationLandscape:
+ case kScreenOrientationFlippedLandscape:
+ execute_on_main_thread(^ {
+ [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeRight) forKey:@"orientation"];
+ });
+ _screenOrientation = kScreenOrientationLandscape;
+ break;
+ case kScreenOrientationAuto:
+ default:
+ break;
+ }
+ }
+}
+#endif
+
bool OSystem_iOS7::isKeyboardShown() const {
__block bool isShown = false;
execute_on_main_thread(^{
diff --git a/backends/platform/ios7/ios7_scummvm_view_controller.mm b/backends/platform/ios7/ios7_scummvm_view_controller.mm
index 883154591ef..28b560cadcb 100644
--- a/backends/platform/ios7/ios7_scummvm_view_controller.mm
+++ b/backends/platform/ios7/ios7_scummvm_view_controller.mm
@@ -59,6 +59,10 @@
return currentOrientation;
}
+- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
+ return [[iOS7AppDelegate iPhoneView] supportedScreenOrientations];
+}
+
-(void) updateCurrentOrientation {
UIInterfaceOrientation interfaceOrientation = [self interfaceOrientation];
if (interfaceOrientation != UIInterfaceOrientationUnknown)
diff --git a/backends/platform/ios7/ios7_video.h b/backends/platform/ios7/ios7_video.h
index 807460fb954..40e4f2a0600 100644
--- a/backends/platform/ios7/ios7_video.h
+++ b/backends/platform/ios7/ios7_video.h
@@ -62,6 +62,7 @@ uint getSizeNextPOT(uint size);
}
@property (nonatomic, assign) BOOL isInGame;
+ at property (nonatomic, assign) UIInterfaceOrientationMask supportedScreenOrientations;
- (id)initWithFrame:(struct CGRect)frame;
diff --git a/backends/platform/ios7/ios7_video.mm b/backends/platform/ios7/ios7_video.mm
index fca2d8c8ad0..5ff35258db3 100644
--- a/backends/platform/ios7/ios7_video.mm
+++ b/backends/platform/ios7/ios7_video.mm
@@ -456,7 +456,18 @@ bool iOS7_fetchEvent(InternalEvent *event) {
#if TARGET_OS_IOS
- (void)interfaceOrientationChanged:(UIInterfaceOrientation)orientation {
- [self addEvent:InternalEvent(kInputOrientationChanged, orientation, 0)];
+ ScreenOrientation screenOrientation;
+ if (orientation == UIInterfaceOrientationPortrait) {
+ screenOrientation = kScreenOrientationPortrait;
+ } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
+ screenOrientation = kScreenOrientationFlippedPortrait;
+ } else if (orientation == UIInterfaceOrientationLandscapeRight) {
+ screenOrientation = kScreenOrientationLandscape;
+ } else { // UIInterfaceOrientationLandscapeLeft
+ screenOrientation = kScreenOrientationFlippedLandscape;
+ }
+
+ [self addEvent:InternalEvent(kInputOrientationChanged, screenOrientation, 0)];
if (UIInterfaceOrientationIsLandscape(orientation)) {
[self hideKeyboard];
} else {
Commit: 1b3c783b9eebbb3ee784a56db73b0a635328a4c3
https://github.com/scummvm/scummvm/commit/1b3c783b9eebbb3ee784a56db73b0a635328a4c3
Author: Lars Sundström (l.sundstrom at gmail.com)
Date: 2023-07-08T18:49:54+02:00
Commit Message:
IOS7: Update current orientation before animation completes
The overided viewWillTransitionToSize instance method did update the
current orientation when animation to the new orientation completed.
However, that made the handling of safe areas on devices having such,
e.g. iPhones with the sensor bar on top, racy. The correct orientation
was set after the adjustViewFrameForSafeArea function was called.
Set the new orientation before the animation completes.
Changed paths:
backends/platform/ios7/ios7_scummvm_view_controller.mm
diff --git a/backends/platform/ios7/ios7_scummvm_view_controller.mm b/backends/platform/ios7/ios7_scummvm_view_controller.mm
index 28b560cadcb..8acaa4c98ca 100644
--- a/backends/platform/ios7/ios7_scummvm_view_controller.mm
+++ b/backends/platform/ios7/ios7_scummvm_view_controller.mm
@@ -88,14 +88,11 @@
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
-
- [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
- UIInterfaceOrientation orientationAfter = [self interfaceOrientation];
- if (orientationAfter != UIInterfaceOrientationUnknown && orientationAfter != currentOrientation) {
- currentOrientation = orientationAfter;
- [[iOS7AppDelegate iPhoneView] interfaceOrientationChanged:currentOrientation];
- }
- }];
+ UIInterfaceOrientation orientationAfter = [self interfaceOrientation];
+ if (orientationAfter != UIInterfaceOrientationUnknown && orientationAfter != currentOrientation) {
+ currentOrientation = orientationAfter;
+ [[iOS7AppDelegate iPhoneView] interfaceOrientationChanged:currentOrientation];
+ }
}
#endif
More information about the Scummvm-git-logs
mailing list