From 567c422f8cd42eba2437f9a8c2522716a1649be7 Mon Sep 17 00:00:00 2001 From: hazel Date: Mon, 26 Jan 2026 22:04:39 +0100 Subject: celesteia archive, last updated april 9th 2024 Signed-off-by: hazel --- source/graphics/GraphicsManager.cs | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 source/graphics/GraphicsManager.cs (limited to 'source/graphics/GraphicsManager.cs') diff --git a/source/graphics/GraphicsManager.cs b/source/graphics/GraphicsManager.cs new file mode 100644 index 0000000..2e285cf --- /dev/null +++ b/source/graphics/GraphicsManager.cs @@ -0,0 +1,65 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Celesteia.Graphics { + public enum FullscreenMode { + Windowed, Fullscreen, Borderless + } + + public class GraphicsManager : GameComponent { + private new GameInstance Game => (GameInstance) base.Game; + private GraphicsDeviceManager _manager; + public GraphicsManager(GameInstance Game) : base(Game) { + _manager = new GraphicsDeviceManager(Game); + _manager.PreferHalfPixelOffset = true; + } + + private FullscreenMode _screenMode; + private bool _useBorderless = false; + private Rectangle _resolution = new Rectangle(0, 0, 1280, 720); + private Rectangle _lastBounds; + + public FullscreenMode FullScreen { + get { return _screenMode; } + set { _screenMode = value; ResolveResolution(); } + } + + public bool VSync = false; + + public bool IsFullScreen { + get { return (_screenMode != FullscreenMode.Windowed); } + } + + public Rectangle Resolution { + get { return _resolution; } + set { _lastBounds = _resolution = value; } + } + + public bool MSAA = false; + + private void ResolveResolution() { + if (!IsFullScreen) _resolution = _lastBounds; + else { + _lastBounds = Game.Window.ClientBounds; + _resolution = new Rectangle(0, 0, _manager.GraphicsDevice.Adapter.CurrentDisplayMode.Width, _manager.GraphicsDevice.Adapter.CurrentDisplayMode.Height); + } + } + + public void Apply() { + Game.Window.AllowUserResizing = true; + _manager.PreferMultiSampling = MSAA; + _manager.PreferredBackBufferWidth = _resolution.Width; + _manager.PreferredBackBufferHeight = _resolution.Height; + _manager.PreferredBackBufferFormat = SurfaceFormat.Color; + _manager.HardwareModeSwitch = (_screenMode == FullscreenMode.Borderless); + _manager.IsFullScreen = IsFullScreen; + _manager.SynchronizeWithVerticalRetrace = VSync; + _manager.ApplyChanges(); + } + + public GraphicsManager ToggleFullScreen() { + FullScreen = IsFullScreen ? FullscreenMode.Windowed : (_useBorderless ? FullscreenMode.Borderless : FullscreenMode.Fullscreen); + return this; + } + } +} \ No newline at end of file -- cgit v1.2.3