diff --git a/Platforms/Game/.Android/AndroidCompatibility.cs b/Platforms/Game/.Android/AndroidCompatibility.cs index 02388ff63ea..3affabe2c0f 100644 --- a/Platforms/Game/.Android/AndroidCompatibility.cs +++ b/Platforms/Game/.Android/AndroidCompatibility.cs @@ -62,10 +62,8 @@ private Orientation GetDeviceNaturalOrientation(Activity activity) if (screenOrientation != Android.Content.PM.ScreenOrientation.FullSensor) throw new InvalidOperationException("NaturalOrientation detection failed. Set ScreenOrientation in MainActivity to FullSensor."); - if (((rotation == SurfaceOrientation.Rotation0 || rotation == SurfaceOrientation.Rotation180) && - orientation == Orientation.Landscape) - || ((rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270) && - orientation == Orientation.Portrait)) + if (((rotation == SurfaceOrientation.Rotation0 || rotation == SurfaceOrientation.Rotation180) && orientation == Orientation.Landscape) + || ((rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270) && orientation == Orientation.Portrait)) { return Orientation.Landscape; } @@ -88,14 +86,18 @@ internal DisplayOrientation GetAbsoluteOrientation(int degrees) // Surprisingly 90 degree is landscape right, except on Kindle devices switch (degrees) { - case 90: - return FlipLandscape ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight; - case 270: - return FlipLandscape ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft; case 0: return DisplayOrientation.Portrait; case 180: return DisplayOrientation.PortraitDown; + case 90: + if (FlipLandscape) + return DisplayOrientation.LandscapeLeft; + return DisplayOrientation.LandscapeRight; + case 270: + if (FlipLandscape) + return DisplayOrientation.LandscapeRight; + return DisplayOrientation.LandscapeLeft; default: return DisplayOrientation.Unknown; @@ -109,38 +111,61 @@ internal DisplayOrientation GetAbsoluteOrientation(int degrees) [CLSCompliant(false)] public DisplayOrientation GetAbsoluteOrientation(Activity activity) { - SurfaceOrientation orientation = activity.WindowManager.DefaultDisplay.Rotation; + Orientation orientation = activity.Resources.Configuration.Orientation; + SurfaceOrientation rotation = activity.WindowManager.DefaultDisplay.Rotation; + switch (orientation) { - case SurfaceOrientation.Rotation90: + case Orientation.Portrait: { - if (NaturalOrientation == Orientation.Landscape) - return DisplayOrientation.PortraitDown; - else - return (FlipLandscape) ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft; + switch (rotation) + { + case SurfaceOrientation.Rotation0: + default: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation != Orientation.Landscape); + return DisplayOrientation.Portrait; + case SurfaceOrientation.Rotation180: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation != Orientation.Landscape); + return DisplayOrientation.PortraitDown; + case SurfaceOrientation.Rotation90: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation == Orientation.Landscape); + return DisplayOrientation.PortraitDown; + case SurfaceOrientation.Rotation270: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation == Orientation.Landscape); + return DisplayOrientation.Portrait; + } } - case SurfaceOrientation.Rotation180: - { - if (NaturalOrientation == Orientation.Landscape) - return (FlipLandscape) ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight; - else - return DisplayOrientation.PortraitDown; - } - case SurfaceOrientation.Rotation270: - { - if (NaturalOrientation == Orientation.Landscape) - return DisplayOrientation.Portrait; - else - return (FlipLandscape) ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight; - } - case SurfaceOrientation.Rotation0: + break; + + case Android.Content.Res.Orientation.Landscape: default: { - if (NaturalOrientation == Orientation.Landscape) - return (FlipLandscape) ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft; - else - return DisplayOrientation.Portrait; + switch (rotation) + { + case SurfaceOrientation.Rotation0: + default: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation == Orientation.Landscape); + if (AndroidCompatibility.Current.FlipLandscape) + return DisplayOrientation.LandscapeRight; + return DisplayOrientation.LandscapeLeft; + case SurfaceOrientation.Rotation180: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation == Orientation.Landscape); + if (AndroidCompatibility.Current.FlipLandscape) + return DisplayOrientation.LandscapeLeft; + return DisplayOrientation.LandscapeRight; + case SurfaceOrientation.Rotation90: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation != Orientation.Landscape); + if (AndroidCompatibility.Current.FlipLandscape) + return DisplayOrientation.LandscapeRight; + return DisplayOrientation.LandscapeLeft; + case SurfaceOrientation.Rotation270: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation != Orientation.Landscape); + if (AndroidCompatibility.Current.FlipLandscape) + return DisplayOrientation.LandscapeLeft; + return DisplayOrientation.LandscapeRight; + } } + break; } } } diff --git a/Platforms/Game/.Android/ConcreteGraphicsDeviceManager.cs b/Platforms/Game/.Android/ConcreteGraphicsDeviceManager.cs index 6bf5514cba6..152124a7fdc 100644 --- a/Platforms/Game/.Android/ConcreteGraphicsDeviceManager.cs +++ b/Platforms/Game/.Android/ConcreteGraphicsDeviceManager.cs @@ -120,25 +120,7 @@ public override void CreateDevice() Android.App.Activity activity = AndroidGameWindow.Activity; DisplayOrientation currentOrientation = AndroidCompatibility.Current.GetAbsoluteOrientation(activity); - switch (activity.Resources.Configuration.Orientation) - { - case Android.Content.Res.Orientation.Portrait: - { - DisplayOrientation orientation = (currentOrientation == DisplayOrientation.PortraitDown) - ? DisplayOrientation.PortraitDown - : DisplayOrientation.Portrait; - gameWindow.SetOrientation(orientation, false); - } - break; - default: - { - DisplayOrientation orientation = (currentOrientation == DisplayOrientation.LandscapeRight) - ? DisplayOrientation.LandscapeRight - : DisplayOrientation.LandscapeLeft; - gameWindow.SetOrientation(orientation, false); - } - break; - } + gameWindow.SetOrientation(currentOrientation, false); // ResetClientBounds { diff --git a/Platforms/Game/.CardboardLegacy/AndroidCompatibility.cs b/Platforms/Game/.CardboardLegacy/AndroidCompatibility.cs index 148c75e3708..4ba4f9cc706 100644 --- a/Platforms/Game/.CardboardLegacy/AndroidCompatibility.cs +++ b/Platforms/Game/.CardboardLegacy/AndroidCompatibility.cs @@ -62,10 +62,8 @@ private Orientation GetDeviceNaturalOrientation(Activity activity) if (screenOrientation != Android.Content.PM.ScreenOrientation.Landscape) throw new InvalidOperationException("NaturalOrientation detection failed. Set ScreenOrientation in MainActivity to Landscape."); - if (((rotation == SurfaceOrientation.Rotation0 || rotation == SurfaceOrientation.Rotation180) && - orientation == Orientation.Landscape) - || ((rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270) && - orientation == Orientation.Portrait)) + if (((rotation == SurfaceOrientation.Rotation0 || rotation == SurfaceOrientation.Rotation180) && orientation == Orientation.Landscape) + || ((rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270) && orientation == Orientation.Portrait)) { return Orientation.Landscape; } @@ -88,14 +86,18 @@ internal DisplayOrientation GetAbsoluteOrientation(int degrees) // Surprisingly 90 degree is landscape right, except on Kindle devices switch (degrees) { - case 90: - return FlipLandscape ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight; - case 270: - return FlipLandscape ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft; case 0: return DisplayOrientation.Portrait; case 180: return DisplayOrientation.PortraitDown; + case 90: + if (FlipLandscape) + return DisplayOrientation.LandscapeLeft; + return DisplayOrientation.LandscapeRight; + case 270: + if (FlipLandscape) + return DisplayOrientation.LandscapeRight; + return DisplayOrientation.LandscapeLeft; default: return DisplayOrientation.Unknown; @@ -109,38 +111,61 @@ internal DisplayOrientation GetAbsoluteOrientation(int degrees) [CLSCompliant(false)] public DisplayOrientation GetAbsoluteOrientation(Activity activity) { - SurfaceOrientation orientation = activity.WindowManager.DefaultDisplay.Rotation; + Orientation orientation = activity.Resources.Configuration.Orientation; + SurfaceOrientation rotation = activity.WindowManager.DefaultDisplay.Rotation; + switch (orientation) { - case SurfaceOrientation.Rotation90: + case Orientation.Portrait: { - if (NaturalOrientation == Orientation.Landscape) - return DisplayOrientation.PortraitDown; - else - return (FlipLandscape) ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft; + switch (rotation) + { + case SurfaceOrientation.Rotation0: + default: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation != Orientation.Landscape); + return DisplayOrientation.Portrait; + case SurfaceOrientation.Rotation180: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation != Orientation.Landscape); + return DisplayOrientation.PortraitDown; + case SurfaceOrientation.Rotation90: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation == Orientation.Landscape); + return DisplayOrientation.PortraitDown; + case SurfaceOrientation.Rotation270: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation == Orientation.Landscape); + return DisplayOrientation.Portrait; + } } - case SurfaceOrientation.Rotation180: - { - if (NaturalOrientation == Orientation.Landscape) - return (FlipLandscape) ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight; - else - return DisplayOrientation.PortraitDown; - } - case SurfaceOrientation.Rotation270: - { - if (NaturalOrientation == Orientation.Landscape) - return DisplayOrientation.Portrait; - else - return (FlipLandscape) ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight; - } - case SurfaceOrientation.Rotation0: + break; + + case Android.Content.Res.Orientation.Landscape: default: { - if (NaturalOrientation == Orientation.Landscape) - return (FlipLandscape) ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft; - else - return DisplayOrientation.Portrait; + switch (rotation) + { + case SurfaceOrientation.Rotation0: + default: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation == Orientation.Landscape); + if (AndroidCompatibility.Current.FlipLandscape) + return DisplayOrientation.LandscapeRight; + return DisplayOrientation.LandscapeLeft; + case SurfaceOrientation.Rotation180: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation == Orientation.Landscape); + if (AndroidCompatibility.Current.FlipLandscape) + return DisplayOrientation.LandscapeLeft; + return DisplayOrientation.LandscapeRight; + case SurfaceOrientation.Rotation90: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation != Orientation.Landscape); + if (AndroidCompatibility.Current.FlipLandscape) + return DisplayOrientation.LandscapeRight; + return DisplayOrientation.LandscapeLeft; + case SurfaceOrientation.Rotation270: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation != Orientation.Landscape); + if (AndroidCompatibility.Current.FlipLandscape) + return DisplayOrientation.LandscapeLeft; + return DisplayOrientation.LandscapeRight; + } } + break; } } } diff --git a/Platforms/Game/.CardboardLegacy/ConcreteGraphicsDeviceManager.cs b/Platforms/Game/.CardboardLegacy/ConcreteGraphicsDeviceManager.cs index a8485f16c5a..38059301e6c 100644 --- a/Platforms/Game/.CardboardLegacy/ConcreteGraphicsDeviceManager.cs +++ b/Platforms/Game/.CardboardLegacy/ConcreteGraphicsDeviceManager.cs @@ -120,25 +120,7 @@ public override void CreateDevice() Android.App.Activity activity = AndroidGameWindow.Activity; DisplayOrientation currentOrientation = AndroidCompatibility.Current.GetAbsoluteOrientation(activity); - switch (activity.Resources.Configuration.Orientation) - { - case Android.Content.Res.Orientation.Portrait: - { - DisplayOrientation orientation = (currentOrientation == DisplayOrientation.PortraitDown) - ? DisplayOrientation.PortraitDown - : DisplayOrientation.Portrait; - gameWindow.SetOrientation(orientation, false); - } - break; - default: - { - DisplayOrientation orientation = (currentOrientation == DisplayOrientation.LandscapeRight) - ? DisplayOrientation.LandscapeRight - : DisplayOrientation.LandscapeLeft; - gameWindow.SetOrientation(orientation, false); - } - break; - } + gameWindow.SetOrientation(currentOrientation, false); // ResetClientBounds { diff --git a/Platforms/Game/.Oculus/AndroidCompatibility.cs b/Platforms/Game/.Oculus/AndroidCompatibility.cs index 3e316fde2ef..3237c8d02cb 100644 --- a/Platforms/Game/.Oculus/AndroidCompatibility.cs +++ b/Platforms/Game/.Oculus/AndroidCompatibility.cs @@ -62,10 +62,8 @@ private Orientation GetDeviceNaturalOrientation(Activity activity) if (screenOrientation != Android.Content.PM.ScreenOrientation.Landscape) throw new InvalidOperationException("Invalid orientation. Set ScreenOrientation in MainActivity to Landscape."); - if (((rotation == SurfaceOrientation.Rotation0 || rotation == SurfaceOrientation.Rotation180) && - orientation == Orientation.Landscape) - || ((rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270) && - orientation == Orientation.Portrait)) + if (((rotation == SurfaceOrientation.Rotation0 || rotation == SurfaceOrientation.Rotation180) && orientation == Orientation.Landscape) + || ((rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270) && orientation == Orientation.Portrait)) { return Orientation.Landscape; } @@ -88,14 +86,18 @@ internal DisplayOrientation GetAbsoluteOrientation(int degrees) // Surprisingly 90 degree is landscape right, except on Kindle devices switch (degrees) { - case 90: - return FlipLandscape ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight; - case 270: - return FlipLandscape ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft; case 0: return DisplayOrientation.Portrait; case 180: return DisplayOrientation.PortraitDown; + case 90: + if (FlipLandscape) + return DisplayOrientation.LandscapeLeft; + return DisplayOrientation.LandscapeRight; + case 270: + if (FlipLandscape) + return DisplayOrientation.LandscapeRight; + return DisplayOrientation.LandscapeLeft; default: return DisplayOrientation.Unknown; @@ -109,38 +111,61 @@ internal DisplayOrientation GetAbsoluteOrientation(int degrees) [CLSCompliant(false)] public DisplayOrientation GetAbsoluteOrientation(Activity activity) { - SurfaceOrientation orientation = activity.WindowManager.DefaultDisplay.Rotation; + Orientation orientation = activity.Resources.Configuration.Orientation; + SurfaceOrientation rotation = activity.WindowManager.DefaultDisplay.Rotation; + switch (orientation) { - case SurfaceOrientation.Rotation90: + case Orientation.Portrait: { - if (NaturalOrientation == Orientation.Landscape) - return DisplayOrientation.PortraitDown; - else - return (FlipLandscape) ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft; + switch (rotation) + { + case SurfaceOrientation.Rotation0: + default: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation != Orientation.Landscape); + return DisplayOrientation.Portrait; + case SurfaceOrientation.Rotation180: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation != Orientation.Landscape); + return DisplayOrientation.PortraitDown; + case SurfaceOrientation.Rotation90: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation == Orientation.Landscape); + return DisplayOrientation.PortraitDown; + case SurfaceOrientation.Rotation270: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation == Orientation.Landscape); + return DisplayOrientation.Portrait; + } } - case SurfaceOrientation.Rotation180: - { - if (NaturalOrientation == Orientation.Landscape) - return (FlipLandscape) ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight; - else - return DisplayOrientation.PortraitDown; - } - case SurfaceOrientation.Rotation270: - { - if (NaturalOrientation == Orientation.Landscape) - return DisplayOrientation.Portrait; - else - return (FlipLandscape) ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight; - } - case SurfaceOrientation.Rotation0: + break; + + case Android.Content.Res.Orientation.Landscape: default: { - if (NaturalOrientation == Orientation.Landscape) - return (FlipLandscape) ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft; - else - return DisplayOrientation.Portrait; + switch (rotation) + { + case SurfaceOrientation.Rotation0: + default: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation == Orientation.Landscape); + if (AndroidCompatibility.Current.FlipLandscape) + return DisplayOrientation.LandscapeRight; + return DisplayOrientation.LandscapeLeft; + case SurfaceOrientation.Rotation180: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation == Orientation.Landscape); + if (AndroidCompatibility.Current.FlipLandscape) + return DisplayOrientation.LandscapeLeft; + return DisplayOrientation.LandscapeRight; + case SurfaceOrientation.Rotation90: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation != Orientation.Landscape); + if (AndroidCompatibility.Current.FlipLandscape) + return DisplayOrientation.LandscapeRight; + return DisplayOrientation.LandscapeLeft; + case SurfaceOrientation.Rotation270: + System.Diagnostics.Debug.Assert(AndroidCompatibility.Current.NaturalOrientation != Orientation.Landscape); + if (AndroidCompatibility.Current.FlipLandscape) + return DisplayOrientation.LandscapeLeft; + return DisplayOrientation.LandscapeRight; + } } + break; } } }