Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Game.cs:

* GameWindow.cs:
* GraphicsDeviceManager.cs: 
Patch 8519 for iOS. Thanks SlyGamer.

git-svn-id: https://xnatouch.svn.codeplex.com/svn@58728 ffd33b8c-2492-42e0-bdc5-587b920b7d6d
  • Loading branch information...
commit ee7185334ae0d9b5bacd20fab0a4846a45a3bbd9 1 parent f23e09e
SND\CartBlanche_cp authored
View
69 MonoGame.Framework/Game.cs
@@ -109,12 +109,26 @@ public Game()
private void ObserveDeviceRotation ()
{
NSNotificationCenter.DefaultCenter.AddObserver( new NSString("UIDeviceOrientationDidChangeNotification"), (notification) => {
- UIDeviceOrientation orientation = UIDevice.CurrentDevice.Orientation;
+ UIDeviceOrientation orientation = UIDevice.CurrentDevice.Orientation;
+
+ // Calculate supported orientations if it has been left as "default"
+ DisplayOrientation supportedOrientations = (graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations;
+ if ((supportedOrientations & DisplayOrientation.Default) != 0)
+ {
+ if (GraphicsDevice.PresentationParameters.BackBufferWidth > GraphicsDevice.PresentationParameters.BackBufferHeight)
+ {
+ supportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
+ }
+ else
+ {
+ supportedOrientations = DisplayOrientation.Portrait | DisplayOrientation.PortraitUpsideDown;
+ }
+ }
switch (orientation)
{
case UIDeviceOrientation.Portrait :
- if ( (graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations == DisplayOrientation.Portrait)
+ if ((supportedOrientations & DisplayOrientation.Portrait) != 0)
{
_view.CurrentOrientation = DisplayOrientation.Portrait;
GraphicsDevice.PresentationParameters.DisplayOrientation = DisplayOrientation.Portrait;
@@ -122,65 +136,50 @@ private void ObserveDeviceRotation ()
}
break;
case UIDeviceOrientation.LandscapeLeft :
- switch ((graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations)
- {
- case DisplayOrientation.LandscapeLeft:
- case DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight :
- {
- _view.CurrentOrientation = DisplayOrientation.LandscapeLeft;
- GraphicsDevice.PresentationParameters.DisplayOrientation = DisplayOrientation.LandscapeLeft;
- TouchPanel.DisplayOrientation = DisplayOrientation.LandscapeLeft;
- break;
- }
- }
+ if ((supportedOrientations & DisplayOrientation.LandscapeLeft) != 0)
+ {
+ _view.CurrentOrientation = DisplayOrientation.LandscapeLeft;
+ GraphicsDevice.PresentationParameters.DisplayOrientation = DisplayOrientation.LandscapeLeft;
+ TouchPanel.DisplayOrientation = DisplayOrientation.LandscapeLeft;
+ }
break;
- case UIDeviceOrientation.LandscapeRight :
- switch ((graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations)
- {
- case DisplayOrientation.LandscapeRight:
- case DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight :
- {
- _view.CurrentOrientation = DisplayOrientation.LandscapeRight;
- GraphicsDevice.PresentationParameters.DisplayOrientation = DisplayOrientation.LandscapeRight;
- TouchPanel.DisplayOrientation = DisplayOrientation.LandscapeRight;
- break;
- }
- }
+ case UIDeviceOrientation.LandscapeRight :
+ if ((supportedOrientations & DisplayOrientation.LandscapeRight) != 0)
+ {
+ _view.CurrentOrientation = DisplayOrientation.LandscapeRight;
+ GraphicsDevice.PresentationParameters.DisplayOrientation = DisplayOrientation.LandscapeRight;
+ TouchPanel.DisplayOrientation = DisplayOrientation.LandscapeRight;
+ }
break;
case UIDeviceOrientation.FaceDown :
- if ( (graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations == DisplayOrientation.FaceDown)
+ if ((supportedOrientations & DisplayOrientation.FaceDown) != 0)
{
_view.CurrentOrientation = DisplayOrientation.FaceDown;
TouchPanel.DisplayOrientation = DisplayOrientation.FaceDown;
}
break;
case UIDeviceOrientation.FaceUp :
- if ( (graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations == DisplayOrientation.FaceDown)
+ if ((supportedOrientations & DisplayOrientation.FaceUp) != 0)
{
_view.CurrentOrientation = DisplayOrientation.FaceUp;
TouchPanel.DisplayOrientation = DisplayOrientation.FaceUp;
}
break;
case UIDeviceOrientation.PortraitUpsideDown :
- if ( (graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations == DisplayOrientation.PortraitUpsideDown)
+ if ((supportedOrientations & DisplayOrientation.PortraitUpsideDown) != 0)
{
_view.CurrentOrientation = DisplayOrientation.PortraitUpsideDown;
TouchPanel.DisplayOrientation = DisplayOrientation.PortraitUpsideDown;
}
break;
case UIDeviceOrientation.Unknown :
- if ( (graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations == DisplayOrientation.Unknown)
+ if ((supportedOrientations & DisplayOrientation.Unknown) != 0)
{
_view.CurrentOrientation = DisplayOrientation.Unknown;
TouchPanel.DisplayOrientation = DisplayOrientation.Unknown;
}
break;
- default:
- if ( (graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations == DisplayOrientation.Default)
- {
- _view.CurrentOrientation = DisplayOrientation.Default;
- TouchPanel.DisplayOrientation = DisplayOrientation.Default;
- }
+ default:
break;
}
});
View
20 MonoGame.Framework/GameWindow.cs
@@ -380,13 +380,27 @@ public bool AllowUserResizing
}
}
+ private DisplayOrientation _currentOrientation;
public DisplayOrientation CurrentOrientation
{
- get;
- set;
+ get
+ {
+ return _currentOrientation;
+ }
+ internal set
+ {
+ if (value != _currentOrientation)
+ {
+ _currentOrientation = value;
+ if (OrientationChanged != null)
+ {
+ OrientationChanged(this, EventArgs.Empty);
+ }
+ }
+ }
}
-
+ public event EventHandler<EventArgs> OrientationChanged;
public event EventHandler ClientSizeChanged;
public event EventHandler ScreenDeviceNameChanged;
}
View
12 MonoGame.Framework/GraphicsDeviceManager.cs
@@ -55,6 +55,7 @@ public class GraphicsDeviceManager : IGraphicsDeviceService, IDisposable, IGraph
private int _preferredBackBufferHeight;
private int _preferredBackBufferWidth;
private bool _preferMultiSampling;
+ private DisplayOrientation _supportedOrientations;
public GraphicsDeviceManager(Game game)
{
@@ -66,6 +67,7 @@ public GraphicsDeviceManager(Game game)
_game = game;
_preferredBackBufferHeight = game.Window.ClientBounds.Height;
_preferredBackBufferWidth = game.Window.ClientBounds.Width;
+ _supportedOrientations = DisplayOrientation.Default;
if (game.Services.GetService(typeof(IGraphicsDeviceManager)) != null)
{
@@ -241,8 +243,14 @@ public bool SynchronizeWithVerticalRetrace
public DisplayOrientation SupportedOrientations
{
- get;
- set;
+ get
+ {
+ return _supportedOrientations;
+ }
+ set
+ {
+ _supportedOrientations = value;
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.