Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1336 from Nezz/orientation

DisplayOrientation revision
  • Loading branch information...
commit 1ad52c30975f8b0780a9f44d7b2fa52941d1d68e 2 parents 1ea236c + ca1e660
@tomspilman tomspilman authored
View
14 MonoGame.Framework/Android/AndroidGameWindow.cs
@@ -269,7 +269,7 @@ internal DisplayOrientation GetEffectiveSupportedOrientations()
}
else
{
- return DisplayOrientation.Portrait | DisplayOrientation.PortraitUpsideDown;
+ return DisplayOrientation.Portrait | DisplayOrientation.PortraitDown;
}
}
else
@@ -294,8 +294,8 @@ internal void SetOrientation(DisplayOrientation newOrientation, bool applyGraphi
newOrientation = DisplayOrientation.LandscapeRight;
else if ((supported & DisplayOrientation.Portrait) != 0)
newOrientation = DisplayOrientation.Portrait;
- else if ((supported & DisplayOrientation.PortraitUpsideDown) != 0)
- newOrientation = DisplayOrientation.PortraitUpsideDown;
+ else if ((supported & DisplayOrientation.PortraitDown) != 0)
+ newOrientation = DisplayOrientation.PortraitDown;
}
DisplayOrientation oldOrientation = CurrentOrientation;
@@ -386,7 +386,7 @@ private set
{
DisplayOrientation supported = GetEffectiveSupportedOrientations();
ScreenOrientation requestedOrientation = ScreenOrientation.Unspecified;
- bool wasPortrait = _currentOrientation == DisplayOrientation.Portrait || _currentOrientation == DisplayOrientation.PortraitUpsideDown;
+ bool wasPortrait = _currentOrientation == DisplayOrientation.Portrait || _currentOrientation == DisplayOrientation.PortraitDown;
bool requestPortrait = false;
bool didOrientationChange = false;
@@ -413,7 +413,7 @@ private set
requestedOrientation = (ScreenOrientation)ScreenOrientationAll.Portrait;
requestPortrait = true;
break;
- case DisplayOrientation.PortraitUpsideDown:
+ case DisplayOrientation.PortraitDown:
requestedOrientation = (ScreenOrientation)ScreenOrientationAll.ReversePortrait;
requestPortrait = true;
break;
@@ -432,8 +432,8 @@ private set
requestPortrait = false;
}
// Check if the requested orientation is either of the portrain orientations and any portrait orientation is supported.
- else if ((value == DisplayOrientation.Portrait || value == DisplayOrientation.PortraitUpsideDown) &&
- ((supported & (DisplayOrientation.Portrait | DisplayOrientation.PortraitUpsideDown)) != 0))
+ else if ((value == DisplayOrientation.Portrait || value == DisplayOrientation.PortraitDown) &&
+ ((supported & (DisplayOrientation.Portrait | DisplayOrientation.PortraitDown)) != 0))
{
didOrientationChange = true;
_currentOrientation = DisplayOrientation.Portrait;
View
2  MonoGame.Framework/Android/OrientationListener.cs
@@ -55,7 +55,7 @@ public override void OnOrientationChanged(int orientation)
break;
case 0: disporientation = DisplayOrientation.Portrait;
break;
- case 180: disporientation = DisplayOrientation.PortraitUpsideDown;
+ case 180: disporientation = DisplayOrientation.PortraitDown;
break;
default:
disporientation = DisplayOrientation.LandscapeLeft;
View
29 MonoGame.Framework/DisplayOrientation.cs
@@ -42,24 +42,15 @@ 1. Definitions
namespace Microsoft.Xna.Framework
{
- [Flags]
- public enum DisplayOrientation
- {
- /// <summary>
- /// In Xna, this value is Default = 0. The effect of setting
- /// GraphicsDeviceManager.SupportedOrientations = Default is the same as setting
- /// GraphicsDeviceManager.SupportedOrientations = LandscapeLeft | LandscapeRight.
- /// </summary>
- Default = 1,
- LandscapeLeft = 2,
- LandscapeRight = 4,
- Portrait = 8,
- // iPhone specific Orientations
- FaceDown = 16,
- FaceUp = 32,
- // Android can also use this orientation
- PortraitUpsideDown = 64,
- Unknown = 128,
- }
+ [Flags]
+ public enum DisplayOrientation
+ {
+ Default = 0,
+ LandscapeLeft = 1,
+ LandscapeRight = 2,
+ Portrait = 4,
+ PortraitDown = 8,
+ Unknown = 16
+ }
}
View
4 MonoGame.Framework/MacOS/GameWindow.cs
@@ -284,7 +284,7 @@ private void FillTouchCollection(NSSet touches)
break;
}
- case DisplayOrientation.PortraitUpsideDown :
+ case DisplayOrientation.PortraitDown :
{
translatedPosition = new Vector2( ClientBounds.Width - position.X, ClientBounds.Height - position.Y );
break;
@@ -316,7 +316,7 @@ private void FillTouchCollection(NSSet touches)
break;
}
- case DisplayOrientation.PortraitUpsideDown :
+ case DisplayOrientation.PortraitDown :
{
translatedPosition = new Vector2( ClientBounds.Width - position.X, ClientBounds.Height - position.Y );
break;
View
75 MonoGame.Framework/Windows8/MetroGameWindow.cs
@@ -46,13 +46,12 @@ 1. Definitions
using System.Runtime.InteropServices;
using Windows.UI.Core;
+using Windows.UI.ViewManagement;
+using Windows.UI.Xaml;
using Windows.Graphics.Display;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
-using Windows.UI.ViewManagement;
-using Windows.UI.Xaml;
-
namespace Microsoft.Xna.Framework
{
@@ -61,7 +60,6 @@ public partial class MetroGameWindow : GameWindow
private DisplayOrientation _supportedOrientations;
private DisplayOrientation _orientation;
private CoreWindow _coreWindow;
- protected Game game;
private Rectangle _clientBounds;
private ApplicationViewState _currentViewState;
private InputEvents _windowEvents;
@@ -107,28 +105,19 @@ protected internal override void SetSupportedOrientations(DisplayOrientation ori
return;
_supportedOrientations = orientations;
- var supported = DisplayOrientations.None;
-
+
+ DisplayOrientations supported;
if (orientations == DisplayOrientation.Default)
{
// Make the decision based on the preferred backbuffer dimensions.
var manager = Game.graphicsDeviceManager;
if (manager.PreferredBackBufferWidth > manager.PreferredBackBufferHeight)
- supported = DisplayOrientations.Landscape | DisplayOrientations.LandscapeFlipped;
+ supported = FromOrientation(DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight);
else
- supported = DisplayOrientations.Portrait | DisplayOrientations.PortraitFlipped;
+ supported = FromOrientation(DisplayOrientation.Portrait | DisplayOrientation.PortraitDown);
}
else
- {
- if ((orientations & DisplayOrientation.LandscapeLeft) != 0)
- supported |= DisplayOrientations.Landscape;
- if ((orientations & DisplayOrientation.LandscapeRight) != 0)
- supported |= DisplayOrientations.LandscapeFlipped;
- if ((orientations & DisplayOrientation.Portrait) != 0)
- supported |= DisplayOrientations.Portrait;
- if ((orientations & DisplayOrientation.PortraitUpsideDown) != 0)
- supported |= DisplayOrientations.PortraitFlipped;
- }
+ supported = FromOrientation(orientations);
DisplayProperties.AutoRotationPreferences = supported;
}
@@ -232,36 +221,32 @@ private void Window_SizeChanged(CoreWindow sender, WindowSizeChangedEventArgs ar
manager.ApplyChanges();
}
- private static DisplayOrientation ToOrientation(DisplayOrientations orientation)
+ private static DisplayOrientation ToOrientation(DisplayOrientations orientations)
{
- var result = (DisplayOrientation)0;
+ var result = DisplayOrientation.Default;
+ if ((orientations & DisplayOrientations.Landscape) != 0)
+ result |= DisplayOrientation.LandscapeLeft;
+ if ((orientations & DisplayOrientations.LandscapeFlipped) != 0)
+ result |= DisplayOrientation.LandscapeRight;
+ if ((orientations & DisplayOrientations.Portrait) != 0)
+ result |= DisplayOrientation.Portrait;
+ if ((orientations & DisplayOrientations.PortraitFlipped) != 0)
+ result |= DisplayOrientation.PortraitDown;
- if (DisplayProperties.NativeOrientation == orientation)
- result |= DisplayOrientation.Default;
-
- switch (orientation)
- {
- default:
- case DisplayOrientations.None:
- result |= DisplayOrientation.Default;
- break;
-
- case DisplayOrientations.Landscape:
- result |= DisplayOrientation.LandscapeLeft;
- break;
-
- case DisplayOrientations.LandscapeFlipped:
- result |= DisplayOrientation.LandscapeRight;
- break;
-
- case DisplayOrientations.Portrait:
- result |= DisplayOrientation.Portrait;
- break;
+ return result;
+ }
- case DisplayOrientations.PortraitFlipped:
- result |= DisplayOrientation.PortraitUpsideDown;
- break;
- }
+ private static DisplayOrientations FromOrientation(DisplayOrientation orientation)
+ {
+ var result = DisplayOrientations.None;
+ if ((orientation & DisplayOrientation.LandscapeLeft) != 0)
+ result |= DisplayOrientations.Landscape;
+ if ((orientation & DisplayOrientation.LandscapeRight) != 0)
+ result |= DisplayOrientations.LandscapeFlipped;
+ if ((orientation & DisplayOrientation.Portrait) != 0)
+ result |= DisplayOrientations.Portrait;
+ if ((orientation & DisplayOrientation.PortraitDown) != 0)
+ result |= DisplayOrientations.PortraitFlipped;
return result;
}
View
2  MonoGame.Framework/WindowsPhone/WPGamePlatform.cs
@@ -81,7 +81,7 @@ public WindowsPhoneGamePlatform(Game game)
: base(game)
{
// Setup the game window.
- Window = new WindowsPhoneGameWindow();
+ Window = new WindowsPhoneGameWindow(game);
// Setup the launch parameters.
// - Parameters can optionally start with a forward slash.
View
106 MonoGame.Framework/WindowsPhone/WPGameWindow.cs
@@ -37,26 +37,31 @@ 1. Definitions
*/
using System;
+using System.Windows;
using System.Runtime.InteropServices;
-using Microsoft.Xna.Framework;
+
using Windows.UI.Core;
using Windows.Graphics.Display;
+
+using Microsoft.Phone.Controls;
+using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
-using System.Windows;
using Microsoft.Xna.Framework.Input.Touch;
-
namespace MonoGame.Framework.WindowsPhone
{
public class WindowsPhoneGameWindow : GameWindow
{
+ private DisplayOrientation _supportedOrientations;
private DisplayOrientation _orientation;
private Rectangle _clientBounds;
+ private Game _game;
#region Internal Properties
static internal double Width;
static internal double Height;
+ static internal PhoneApplicationPage Page;
internal bool IsExiting { get; set; }
@@ -87,46 +92,17 @@ public override DisplayOrientation CurrentOrientation
protected internal override void SetSupportedOrientations(DisplayOrientation orientations)
{
- /*
- // We don't want to trigger orientation changes
- // when no preference is being changed.
- if (_supportedOrientations == orientations)
- return;
-
- _supportedOrientations = orientations;
- var supported = DisplayOrientations.None;
-
- if (orientations == DisplayOrientation.Default)
- {
- // Make the decision based on the preferred backbuffer dimensions.
- var manager = _game.graphicsDeviceManager;
- if (manager.PreferredBackBufferWidth > manager.PreferredBackBufferHeight)
- supported = DisplayOrientations.Landscape | DisplayOrientations.LandscapeFlipped;
- else
- supported = DisplayOrientations.Portrait | DisplayOrientations.PortraitFlipped;
- }
- else
- {
- if ((orientations & DisplayOrientation.LandscapeLeft) != 0)
- supported |= DisplayOrientations.Landscape;
- if ((orientations & DisplayOrientation.LandscapeRight) != 0)
- supported |= DisplayOrientations.LandscapeFlipped;
- if ((orientations & DisplayOrientation.Portrait) != 0)
- supported |= DisplayOrientations.Portrait;
- if ((orientations & DisplayOrientation.PortraitUpsideDown) != 0)
- supported |= DisplayOrientations.PortraitFlipped;
- }
-
- //DisplayProperties.AutoRotationPreferences = supported;
- */
+ _supportedOrientations = orientations == DisplayOrientation.Default ? DisplayOrientation.Portrait : orientations;
}
#endregion
- public WindowsPhoneGameWindow()
+ public WindowsPhoneGameWindow(Game game)
{
- //_orientation = ToOrientation(DisplayProperties.CurrentOrientation);
- //DisplayProperties.OrientationChanged += DisplayProperties_OrientationChanged;
+ _game = game;
+
+ _orientation = ToOrientation(Page.Orientation);
+ Page.OrientationChanged += Page_OrientationChanged;
//inputElement.SizeChanged += Window_SizeChanged;
@@ -201,54 +177,38 @@ private void Window_SizeChanged(CoreWindow sender, WindowSizeChangedEventArgs ar
}
*/
- private static DisplayOrientation ToOrientation(DisplayOrientations orientation)
+ private static DisplayOrientation ToOrientation(PageOrientation orientations)
{
- var result = (DisplayOrientation)0;
-
- if (DisplayProperties.NativeOrientation == orientation)
- result |= DisplayOrientation.Default;
-
- switch (orientation)
- {
- default:
- case DisplayOrientations.None:
- result |= DisplayOrientation.Default;
- break;
-
- case DisplayOrientations.Landscape:
- result |= DisplayOrientation.LandscapeLeft;
- break;
-
- case DisplayOrientations.LandscapeFlipped:
- result |= DisplayOrientation.LandscapeRight;
- break;
-
- case DisplayOrientations.Portrait:
- result |= DisplayOrientation.Portrait;
- break;
-
- case DisplayOrientations.PortraitFlipped:
- result |= DisplayOrientation.PortraitUpsideDown;
- break;
- }
+ var result = DisplayOrientation.Default;
+ if ((orientations & (PageOrientation)0x0004) != 0)
+ result |= DisplayOrientation.Portrait;
+ if ((orientations & (PageOrientation)0x0008) != 0)
+ result |= DisplayOrientation.PortraitDown;
+ if ((orientations & (PageOrientation)0x0010) != 0)
+ result |= DisplayOrientation.LandscapeLeft;
+ if ((orientations & (PageOrientation)0x0020) != 0)
+ result |= DisplayOrientation.LandscapeRight;
return result;
}
- /*
- private void DisplayProperties_OrientationChanged(object sender)
+ private void Page_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
+ DisplayOrientation orientation = ToOrientation(e.Orientation);
+ // Don't change our orientation if it isn't supported
+ if ((orientation & _supportedOrientations) == 0)
+ return;
+
// Set the new orientation.
- _orientation = ToOrientation(DisplayProperties.CurrentOrientation);
+ _orientation = orientation;
// Call the user callback.
OnOrientationChanged();
// If we have a valid client bounds then update the graphics device.
- if (_clientBounds.Width > 0 && _clientBounds.Height > 0)
- _game.graphicsDeviceManager.ApplyChanges();
+ //if (_clientBounds.Width > 0 && _clientBounds.Height > 0)
+ // _game.graphicsDeviceManager.ApplyChanges();
}
- */
protected override void SetTitle(string title)
{
View
21 MonoGame.Framework/WindowsPhone/XamlGame.cs
@@ -1,12 +1,15 @@
using System;
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Input.Touch;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
using SharpDX;
using SharpDX.Direct3D11;
+using Microsoft.Phone.Controls;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Input.Touch;
+using Windows.Graphics.Display;
using Windows.Phone.Input.Interop;
using Windows.UI.Core;
-using System.Windows.Controls;
-using Windows.Graphics.Display;
using Vector2 = Microsoft.Xna.Framework.Vector2;
namespace MonoGame.Framework.WindowsPhone
@@ -121,16 +124,20 @@ public override void PrepareResources(DateTime presentTargetTime, ref DrawingSiz
/// <param name="launchParameters">The command line arguments from launch.</param>
/// <param name="drawingSurface">The XAML drawing surface to which we render the scene and recieve input events.</param>
/// <returns></returns>
- static public T Create(string launchParameters, DrawingSurfaceBackgroundGrid drawingSurface)
+ static public T Create(string launchParameters, PhoneApplicationPage page)
{
if (launchParameters == null)
throw new NullReferenceException("The launch parameters cannot be null!");
- if (drawingSurface == null)
- throw new NullReferenceException("The drawing surface cannot be null!");
+ if (page == null)
+ throw new NullReferenceException("The page parameter cannot be null!");
+ if (!(page.Content is DrawingSurfaceBackgroundGrid))
+ throw new NullReferenceException("The drawing surface could not be found!");
+ DrawingSurfaceBackgroundGrid drawingSurface = (DrawingSurfaceBackgroundGrid)page.Content;
WindowsPhoneGamePlatform.LaunchParameters = launchParameters;
WindowsPhoneGameWindow.Width = drawingSurface.ActualWidth;
WindowsPhoneGameWindow.Height = drawingSurface.ActualHeight;
+ WindowsPhoneGameWindow.Page = page;
// Construct the game.
var game = new T();
View
22 MonoGame.Framework/iOS/OrientationConverter.cs
@@ -77,15 +77,15 @@ public static DisplayOrientation UIDeviceOrientationToDisplayOrientation(UIDevic
{
switch (orientation)
{
- case UIDeviceOrientation.FaceDown: return DisplayOrientation.FaceDown;
- case UIDeviceOrientation.FaceUp: return DisplayOrientation.FaceUp;
+ case UIDeviceOrientation.FaceDown: return DisplayOrientation.Unknown;
+ case UIDeviceOrientation.FaceUp: return DisplayOrientation.Unknown;
default:
// NOTE: in XNA, Orientation Left is a 90 degree rotation counterclockwise, while on iOS
// it is a 90 degree rotation CLOCKWISE. They are BACKWARDS!
case UIDeviceOrientation.LandscapeLeft: return DisplayOrientation.LandscapeRight;
case UIDeviceOrientation.LandscapeRight: return DisplayOrientation.LandscapeLeft;
case UIDeviceOrientation.Portrait: return DisplayOrientation.Portrait;
- case UIDeviceOrientation.PortraitUpsideDown: return DisplayOrientation.PortraitUpsideDown;
+ case UIDeviceOrientation.PortraitUpsideDown: return DisplayOrientation.PortraitDown;
}
}
@@ -99,7 +99,7 @@ public static DisplayOrientation ToDisplayOrientation(UIInterfaceOrientation ori
case UIInterfaceOrientation.LandscapeLeft: return DisplayOrientation.LandscapeRight;
case UIInterfaceOrientation.LandscapeRight: return DisplayOrientation.LandscapeLeft;
case UIInterfaceOrientation.Portrait: return DisplayOrientation.Portrait;
- case UIInterfaceOrientation.PortraitUpsideDown: return DisplayOrientation.PortraitUpsideDown;
+ case UIInterfaceOrientation.PortraitUpsideDown: return DisplayOrientation.PortraitDown;
}
}
@@ -107,18 +107,18 @@ public static UIInterfaceOrientationMask ToUIInterfaceOrientationMask (DisplayOr
{
switch (Normalize(orientation))
{
- case((DisplayOrientation)1):
- case((DisplayOrientation)6):
+ case((DisplayOrientation)0):
+ case((DisplayOrientation)3):
return UIInterfaceOrientationMask.Landscape;
- case((DisplayOrientation)2):
+ case((DisplayOrientation)1):
return UIInterfaceOrientationMask.LandscapeLeft;
- case((DisplayOrientation)4):
+ case((DisplayOrientation)2):
return UIInterfaceOrientationMask.LandscapeRight;
- case((DisplayOrientation)16):
+ case((DisplayOrientation)4):
return UIInterfaceOrientationMask.Portrait;
- case((DisplayOrientation)32):
+ case((DisplayOrientation)8):
return UIInterfaceOrientationMask.PortraitUpsideDown;
- case((DisplayOrientation)14):
+ case((DisplayOrientation)7):
return UIInterfaceOrientationMask.AllButUpsideDown;
default:
return UIInterfaceOrientationMask.All;
View
2  ProjectTemplates/VisualStudio2012/WindowsPhone/GamePage.xaml.cs
@@ -22,7 +22,7 @@ public GamePage()
{
InitializeComponent();
- _game = XamlGame<Game1>.Create("", XnaSurface);
+ _game = XamlGame<Game1>.Create("", this);
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
Please sign in to comment.
Something went wrong with that request. Please try again.