Beispiel #1
0
        public void ApplyGraphicsSettings()
        {
            GraphicsWidth  = Config.GraphicsWidth;
            GraphicsHeight = Config.GraphicsHeight;
            switch (Config.WindowMode)
            {
            case WindowMode.BorderlessWindowed:
                GraphicsWidth  = GraphicsDevice.DisplayMode.Width;
                GraphicsHeight = GraphicsDevice.DisplayMode.Height;
                break;

            case WindowMode.Windowed:
                GraphicsWidth  = Math.Min(GraphicsDevice.DisplayMode.Width, GraphicsWidth);
                GraphicsHeight = Math.Min(GraphicsDevice.DisplayMode.Height, GraphicsHeight);
                break;
            }
            GraphicsDeviceManager.GraphicsProfile                = GraphicsProfile.Reach;
            GraphicsDeviceManager.PreferredBackBufferFormat      = SurfaceFormat.Color;
            GraphicsDeviceManager.PreferMultiSampling            = false;
            GraphicsDeviceManager.SynchronizeWithVerticalRetrace = Config.VSyncEnabled;
            SetWindowMode(Config.WindowMode);

            defaultViewport = GraphicsDevice.Viewport;

            OnResolutionChanged?.Invoke();
        }
Beispiel #2
0
        private void SetResolution(int width, int height)
        {
            if (width > k_MaxResolution || height > k_MaxResolution || width < 0 || height < 0)
            {
                Debug.LogError($"Failed to change resolution. Make sure that both width and height are at least 0 and less than {k_MaxResolution}.");
                return;
            }

            if (width == 0 && height == 0)
            {
                InitResolution();
                return;
            }

            if (width == 0)
            {
                width = 1;
            }
            else if (height == 0)
            {
                height = 1;
            }

            m_CurrentWidth  = width;
            m_CurrentHeight = height;
            CalculateSafeAreaAndCutouts();

            OnResolutionChanged?.Invoke(m_CurrentWidth, m_CurrentHeight);
        }
Beispiel #3
0
        public void ApplyGraphicsSettings()
        {
            GraphicsWidth  = Config.GraphicsWidth;
            GraphicsHeight = Config.GraphicsHeight;
            GraphicsDeviceManager.GraphicsProfile                = GraphicsProfile.Reach;
            GraphicsDeviceManager.PreferredBackBufferFormat      = SurfaceFormat.Color;
            GraphicsDeviceManager.PreferMultiSampling            = false;
            GraphicsDeviceManager.SynchronizeWithVerticalRetrace = Config.VSyncEnabled;

            if (Config.WindowMode == WindowMode.Windowed)
            {
                //for whatever reason, window isn't centered automatically
                //since MonoGame 3.6 (nuget package might be broken), so
                //let's do it manually
                Window.Position = new Point((GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - GraphicsWidth) / 2,
                                            (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - GraphicsHeight) / 2);
            }

            GraphicsDeviceManager.PreferredBackBufferWidth  = GraphicsWidth;
            GraphicsDeviceManager.PreferredBackBufferHeight = GraphicsHeight;

            SetWindowMode(Config.WindowMode);

            defaultViewport = GraphicsDevice.Viewport;

            OnResolutionChanged?.Invoke();
        }
Beispiel #4
0
        private void ForceNewOrientation(ScreenOrientation orientation)
        {
            // Swap resolution Width and Height if changing from Portrait to Landscape or vice versa
            if ((orientation == ScreenOrientation.Portrait || orientation == ScreenOrientation.PortraitUpsideDown) && IsRenderingLandscape ||
                (orientation == ScreenOrientation.LandscapeLeft || orientation == ScreenOrientation.LandscapeRight) && !IsRenderingLandscape)
            {
                var temp = m_CurrentHeight;
                m_CurrentHeight = m_CurrentWidth;
                m_CurrentWidth  = temp;
                OnResolutionChanged?.Invoke(m_CurrentWidth, m_CurrentHeight);
            }
            m_RenderedOrientation = orientation;
            OnOrientationChanged?.Invoke(m_AutoRotation);

            CalculateInsets();

            // We only change the resolution if we never set the resolution by calling Screen.SetResolution().
            if (!m_WasResolutionSet)
            {
                CalculateResolutionWithInsets(out int tempWidth, out int tempHeight);
                SetResolution(tempWidth, tempHeight);
            }

            CalculateSafeAreaAndCutouts();
        }
Beispiel #5
0
        /// <summary>
        /// Changes the window resolution and applies settings.
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public static void ChangeResolution(int width, int height)
        {
            Point max = GetMonitorResolution();

            if (width > max.X || height > max.Y)
            {
                Console.WriteLine("Too big: {0}x{1}", width, height);
                throw new ArgumentOutOfRangeException("width", "This resolution is bigger than the max resolution of: " + max.X + "x" + max.Y);
            }
            _graphicsManager.PreferredBackBufferWidth  = width;
            _graphicsManager.PreferredBackBufferHeight = height;
            TMBAW_Game.UserResWidth  = width;
            TMBAW_Game.UserResHeight = height;

            TMBAW_Game.WidthRatio  = ((double)TMBAW_Game.UserResWidth / TMBAW_Game.DefaultResWidth);
            TMBAW_Game.HeightRatio = ((double)TMBAW_Game.UserResHeight / TMBAW_Game.DefaultResHeight);

            TMBAW_Game.UiWidthRatio  = ((double)TMBAW_Game.UserResWidth / TMBAW_Game.DefaultUiWidth);
            TMBAW_Game.UiHeightRatio = ((double)TMBAW_Game.UserResHeight / TMBAW_Game.DefaultUiHeight);

            _graphicsManager.ApplyChanges();
            ChangeUserInterfaceResolution();

            OnResolutionChanged?.Invoke(width, height);
        }
Beispiel #6
0
        private void UpdateViewport()
        {
            var dimensions = GetDimensions(Window.ClientBounds);

            if (lastWindowDimensions == dimensions)
            {
                return;
            }
            lastWindowDimensions = dimensions;

            float ratio = (float)dimensions.X / dimensions.Y;

            if (ratio > WidescreenRatio)
            {
                var optimalDimensions = new Point(Calc.RoundToInt(dimensions.Y * WidescreenRatio), dimensions.Y);
                int leftEdge          = (dimensions.X - optimalDimensions.X) / 2;
                Viewport = new Viewport(leftEdge, 0, optimalDimensions.X, optimalDimensions.Y, 0, 1);
            }
            else if (ratio < WidescreenRatio)
            {
                var optimalDimensions = new Point(dimensions.X, Calc.RoundToInt(dimensions.X / WidescreenRatio));
                int topEdge           = (dimensions.Y - optimalDimensions.Y) / 2;
                Viewport = new Viewport(0, topEdge, optimalDimensions.X, optimalDimensions.Y, 0, 1);
            }
            else
            {
                Viewport = new Viewport(0, 0, dimensions.X, dimensions.Y, 0, 1);
            }

            MDraw.Camera.CalculateScale();

            OnResolutionChanged?.Invoke(this, EventArgs.Empty);
        }
Beispiel #7
0
        private void SetResolution(int width, int height)
        {
            m_CurrentWidth  = width;
            m_CurrentHeight = height;
            CalculateSafeAreaAndCutouts();

            OnResolutionChanged?.Invoke(m_CurrentWidth, m_CurrentHeight);
        }
Beispiel #8
0
        private void SetResolution(int width, int height)
        {
            m_CurrentWidth      = width;
            m_CurrentHeight     = height;
            m_Window.TargetSize = new Vector2(width, height);
            CalculateSafeAreaAndCutouts();

            OnResolutionChanged?.Invoke(m_CurrentWidth, m_CurrentHeight);
        }
Beispiel #9
0
        public void Tick()
        {
            Resolution currentRes = UnityEngine.Screen.currentResolution;

            if (currentRes.width == lastRes.width && currentRes.height == lastRes.height)
            {
                return;
            }

            OnResolutionChanged?.Invoke(lastRes, currentRes);
            lastRes = currentRes;
        }
Beispiel #10
0
        private void SetResolution(int width, int height)
        {
            // For now limit width & height from 1 to 9999.
            if (width < 1 || width > 9999 || height < 1 || height > 9999)
            {
                Debug.LogError("Failed to change resolution. Make sure that both width and height are between 1 and 9999.");
                return;
            }

            m_CurrentWidth  = width;
            m_CurrentHeight = height;
            CalculateSafeAreaAndCutouts();

            OnResolutionChanged?.Invoke(m_CurrentWidth, m_CurrentHeight);
        }
Beispiel #11
0
 private void ForceNewOrientation(ScreenOrientation orientation)
 {
     // Swap resolution Width and Height if changing from Portrait to Landscape or vice versa
     if ((orientation == ScreenOrientation.Portrait || orientation == ScreenOrientation.PortraitUpsideDown) && IsRenderingLandscape ||
         (orientation == ScreenOrientation.LandscapeLeft || orientation == ScreenOrientation.LandscapeRight) && !IsRenderingLandscape)
     {
         var temp = m_CurrentHeight;
         m_CurrentHeight = m_CurrentWidth;
         m_CurrentWidth  = temp;
         OnResolutionChanged?.Invoke(m_CurrentWidth, m_CurrentHeight);
     }
     m_RenderedOrientation = orientation;
     OnOrientationChanged?.Invoke(m_AutoRotation);
     CalculateInsets();
     CalculateSafeAreaAndCutouts();
 }
Beispiel #12
0
        public void ApplyChanges()
        {
            var updateSafeArea = false;

            var orientationEvent         = false;
            var resolutionEvent          = false;
            var fullScreenEvent          = false;
            var screenSpaceSafeAreaEvent = false;
            var insetsEvent = false;

            if (m_RequestedOrientation != m_RenderedOrientation)
            {
                if (m_RequestedOrientation.IsLandscape() != m_RenderedOrientation.IsLandscape())
                {
                    // Swap resolution Width and Height if changing from Portrait to Landscape or vice versa
                    if (m_WasResolutionSet)
                    {
                        (m_RequestedHeight, m_RequestedWidth) = (m_RequestedWidth, m_RequestedHeight);
                    }
                    else
                    {
                        m_RequestDefaultResolution = true;
                    }
                }

                m_RenderedOrientation = m_RequestedOrientation;
                orientationEvent      = true;
                m_RequestInsetUpdate  = true;
                updateSafeArea        = true;
            }

            if (m_RequestedFullScreen != m_IsFullScreen)
            {
                m_IsFullScreen       = m_RequestedFullScreen;
                m_RequestInsetUpdate = true;

                // We only change the resolution if we never set the resolution by calling Screen.SetResolution().
                if (!m_WasResolutionSet)
                {
                    m_RequestDefaultResolution = true;
                }

                updateSafeArea  = true;
                fullScreenEvent = true;
            }

            if (m_RequestInsetUpdate)
            {
                CalculateInsets();
                insetsEvent = true;
            }

            if ((m_RequestedWidth != m_CurrentWidth || m_RequestedHeight != m_CurrentHeight) && m_WasResolutionSet)
            {
                m_CurrentWidth  = m_RequestedWidth;
                m_CurrentHeight = m_RequestedHeight;
                updateSafeArea  = true;
                resolutionEvent = true;
            }
            else if (m_RequestDefaultResolution)
            {
                CalculateResolutionWithInsets();
                updateSafeArea  = true;
                resolutionEvent = true;
            }

            if (updateSafeArea)
            {
                CalculateSafeAreaAndCutouts();
                screenSpaceSafeAreaEvent = true;
            }

            if (orientationEvent)
            {
                OnOrientationChanged?.Invoke();
            }
            if (resolutionEvent)
            {
                OnResolutionChanged?.Invoke(m_CurrentWidth, m_CurrentHeight);
            }
            if (fullScreenEvent)
            {
                OnFullScreenChanged?.Invoke(m_IsFullScreen);
            }
            if (screenSpaceSafeAreaEvent)
            {
                OnScreenSpaceSafeAreaChanged?.Invoke(ScreenSpaceSafeArea);
            }
            if (insetsEvent)
            {
                OnInsetsChanged?.Invoke(Insets);
            }

            m_RequestDefaultResolution = false;
            m_RequestedOrientation     = m_RenderedOrientation;
            m_RequestedHeight          = m_CurrentHeight;
            m_RequestedWidth           = m_CurrentWidth;
            m_RequestInsetUpdate       = false;
        }