aboutsummaryrefslogtreecommitdiff
path: root/source/graphics/GraphicsManager.cs
diff options
context:
space:
mode:
authorhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
committerhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
commit567c422f8cd42eba2437f9a8c2522716a1649be7 (patch)
tree93c5b296f3b7c14b626d0aadf5cad37764c41c74 /source/graphics/GraphicsManager.cs
downloadcelesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.gz
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.bz2
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.zip
celesteia archive, last updated april 9th 2024
Signed-off-by: hazel <hazel@hazelthats.me>
Diffstat (limited to 'source/graphics/GraphicsManager.cs')
-rw-r--r--source/graphics/GraphicsManager.cs65
1 files changed, 65 insertions, 0 deletions
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