Exemplo n.º 1
0
        private static void SetOrientation(DisplayOrientation supportedOrientations, bool bUpdateDimensions)
        {
            bool ll = (supportedOrientations & DisplayOrientation.LandscapeLeft) == DisplayOrientation.LandscapeLeft;
            bool lr = (supportedOrientations & DisplayOrientation.LandscapeRight) == DisplayOrientation.LandscapeRight;
            bool p  = (supportedOrientations & DisplayOrientation.Portrait) == DisplayOrientation.Portrait;

            bool onlyLandscape = (ll || lr) && !p;
            bool onlyPortrait  = !(ll || lr) && p;

#if WINDOWS_PHONE
            bool bSwapDims = bUpdateDimensions && ((m_GraphicsDeviceMgr.SupportedOrientations & supportedOrientations) == DisplayOrientation.Default);
#else
            bool bSwapDims = bUpdateDimensions && ((m_GraphicsDeviceMgr.SupportedOrientations & supportedOrientations) == 0);
#endif
            if (bSwapDims && (ll || lr))
            {
                // Check for landscape changes that do not need a swap
#if WINDOWS_PHONE
                if (((m_GraphicsDeviceMgr.SupportedOrientations & DisplayOrientation.LandscapeLeft) != DisplayOrientation.Default) ||
                    ((m_GraphicsDeviceMgr.SupportedOrientations & DisplayOrientation.LandscapeRight) != DisplayOrientation.Default))
#else
                if (((m_GraphicsDeviceMgr.SupportedOrientations & DisplayOrientation.LandscapeLeft) != 0) ||
                    ((m_GraphicsDeviceMgr.SupportedOrientations & DisplayOrientation.LandscapeRight) != 0))
#endif
                {
                    bSwapDims = false;
                }
            }
            int preferredBackBufferWidth  = m_GraphicsDeviceMgr.PreferredBackBufferWidth;
            int preferredBackBufferHeight = m_GraphicsDeviceMgr.PreferredBackBufferHeight;
            if (bSwapDims)
            {
                CCSize newSize = m_obDesignResolutionSize.Inverted;
                CCDrawManager.SetDesignResolutionSize(newSize.Width, newSize.Height, m_eResolutionPolicy);

                /*
                 * m_obViewPortRect = m_obViewPortRect.InvertedSize;
                 * m_obDesignResolutionSize = m_obDesignResolutionSize.Inverted;
                 * CCDirector.SharedDirector.m_obWinSizeInPoints = CCDirector.SharedDirector.m_obWinSizeInPoints.Inverted;
                 * CCDirector.SharedDirector.m_obWinSizeInPixels = CCDirector.SharedDirector.m_obWinSizeInPixels.Inverted;
                 * m_obScreenSize = m_obScreenSize.Inverted;
                 * float f = m_fScaleX;
                 * m_fScaleX = m_fScaleY;
                 * m_fScaleY = f;
                 */
            }
            preferredBackBufferWidth  = m_GraphicsDeviceMgr.PreferredBackBufferWidth;
            preferredBackBufferHeight = m_GraphicsDeviceMgr.PreferredBackBufferHeight;
#if ANDROID
            if (onlyLandscape && m_GraphicsDeviceMgr.PreferredBackBufferHeight > m_GraphicsDeviceMgr.PreferredBackBufferWidth)
            {
                m_GraphicsDeviceMgr.PreferredBackBufferWidth  = preferredBackBufferHeight;
                m_GraphicsDeviceMgr.PreferredBackBufferHeight = preferredBackBufferWidth;
            }
            m_GraphicsDeviceMgr.SupportedOrientations = supportedOrientations;
#endif
#if WINDOWS_PHONE
            if (bSwapDims)
            {
                m_GraphicsDeviceMgr.PreferredBackBufferWidth  = preferredBackBufferHeight;
                m_GraphicsDeviceMgr.PreferredBackBufferHeight = preferredBackBufferWidth;
            }
            else
            {
                if (onlyLandscape)
                {
                    m_GraphicsDeviceMgr.PreferredBackBufferWidth  = 840;
                    m_GraphicsDeviceMgr.PreferredBackBufferHeight = 480;
                }
                else if (onlyPortrait)
                {
                    m_GraphicsDeviceMgr.PreferredBackBufferWidth  = 480;
                    m_GraphicsDeviceMgr.PreferredBackBufferHeight = 840;
                }
            }
            m_GraphicsDeviceMgr.SupportedOrientations = supportedOrientations;
#endif
#if IOS || IPHONE
            if (bSwapDims)
            {
                m_GraphicsDeviceMgr.PreferredBackBufferWidth  = preferredBackBufferHeight;
                m_GraphicsDeviceMgr.PreferredBackBufferHeight = preferredBackBufferWidth;
            }
            else if (onlyLandscape && m_GraphicsDeviceMgr.PreferredBackBufferHeight > m_GraphicsDeviceMgr.PreferredBackBufferWidth)
            {
                m_GraphicsDeviceMgr.PreferredBackBufferWidth  = preferredBackBufferHeight;
                m_GraphicsDeviceMgr.PreferredBackBufferHeight = preferredBackBufferWidth;
            }
            m_GraphicsDeviceMgr.SupportedOrientations = supportedOrientations;
#endif
#if WINDOWS
            if (bSwapDims)
            {
                m_GraphicsDeviceMgr.PreferredBackBufferWidth  = preferredBackBufferHeight;
                m_GraphicsDeviceMgr.PreferredBackBufferHeight = preferredBackBufferWidth;
            }
            else
            {
                if (onlyPortrait)
                {
                    m_GraphicsDeviceMgr.PreferredBackBufferWidth  = 480;
                    m_GraphicsDeviceMgr.PreferredBackBufferHeight = 800;
                }
                else
                {
                    m_GraphicsDeviceMgr.PreferredBackBufferWidth  = 800;
                    m_GraphicsDeviceMgr.PreferredBackBufferHeight = 480;
                }
            }
#endif
            m_GraphicsDeviceMgr.ApplyChanges();
        }