Microsoft.Xna.Framework.AndroidGameWindow.GetEffectiveSupportedOrientations C# (CSharp) Method

GetEffectiveSupportedOrientations() private method

In Xna, setting SupportedOrientations = DisplayOrientation.Default (which is the default value) has the effect of setting SupportedOrientations to landscape only or portrait only, based on the aspect ratio of PreferredBackBufferWidth / PreferredBackBufferHeight
private GetEffectiveSupportedOrientations ( ) : DisplayOrientation
return DisplayOrientation
        internal DisplayOrientation GetEffectiveSupportedOrientations()
        {
            if (_supportedOrientations == DisplayOrientation.Default)
            {
                var deviceManager = (_game.Services.GetService(typeof(IGraphicsDeviceManager)) as GraphicsDeviceManager);
                if (deviceManager == null)
                    return DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;

                if (deviceManager.PreferredBackBufferWidth > deviceManager.PreferredBackBufferHeight)
                {
                    return DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
                }
                else
                {
                    return DisplayOrientation.Portrait | DisplayOrientation.PortraitDown;
                }
            }
            else
            {
                return _supportedOrientations;
            }
        }

Usage Example

Esempio n. 1
0
        public override void OnOrientationChanged(int orientation)
        {
            if (orientation == OrientationEventListener.OrientationUnknown)
            {
                return;
            }

            // Avoid changing orientation whilst the screen is locked
            if (ScreenReceiver.ScreenLocked)
            {
                return;
            }

            if (_naturalOrientation.Value == Orientation.Landscape)
            {
                orientation += 270;
            }

            // Round orientation into one of 4 positions, either 0, 90, 180, 270.
            int ort = ((orientation + 45) / 90 * 90) % 360;

            var disporientation = DisplayOrientation.Unknown;

            switch (ort)
            {
            case 90: disporientation = AndroidCompatibility.FlipLandscape ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight;
                break;

            case 270: disporientation = AndroidCompatibility.FlipLandscape ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft;
                break;

            case 0: disporientation = DisplayOrientation.Portrait;
                break;

            case 180: disporientation = DisplayOrientation.PortraitDown;
                break;

            default:
                disporientation = DisplayOrientation.LandscapeLeft;
                break;
            }

            // Only auto-rotate if target orientation is supported and not current
            AndroidGameWindow gameWindow = (AndroidGameWindow)Game.Instance.Window;

            if ((gameWindow.GetEffectiveSupportedOrientations() & disporientation) != 0 &&
                disporientation != gameWindow.CurrentOrientation)
            {
                gameWindow.SetOrientation(disporientation, true);
            }
        }
All Usage Examples Of Microsoft.Xna.Framework.AndroidGameWindow::GetEffectiveSupportedOrientations