Fix the removal of implicit conversions in libfmt 10 by using explicit casts.
[0ad.git] / source / ps / VideoMode.h
blob3faae583326234da1b5d0978492f97f7228c4e0e
1 /* Copyright (C) 2023 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_VIDEOMODE
19 #define INCLUDED_VIDEOMODE
21 #include "ps/CStrForward.h"
22 #include "renderer/backend/Backend.h"
24 #include <memory>
26 typedef struct SDL_Window SDL_Window;
28 namespace Renderer
30 namespace Backend
32 class IDevice;
36 class CVideoMode
38 public:
39 CVideoMode();
40 ~CVideoMode();
42 /**
43 * Initialise the video mode, for use in an SDL-using application.
45 bool InitSDL();
47 /**
48 * Initialise parts of the video mode, for use in Atlas (which uses
49 * wxWidgets instead of SDL for GL).
51 bool InitNonSDL();
53 /**
54 * Shut down after InitSDL/InitNonSDL, so that they can be used again.
56 void Shutdown();
58 /**
59 * Creates a backend device. Also we use wxWidgets in Atlas so we don't need
60 * to create one for that case.
62 bool CreateBackendDevice(const bool createSDLContext);
64 /**
65 * Resize the SDL window and associated graphics stuff to the new size.
67 bool ResizeWindow(int w, int h);
69 /**
70 * Set scale and tell dependent compoenent to recompute sizes.
72 void Rescale(float scale);
74 /**
75 * Switch to fullscreen or windowed mode.
77 bool SetFullscreen(bool fullscreen);
79 /**
80 * Returns true if window runs in fullscreen mode.
82 bool IsInFullscreen() const;
84 /**
85 * Switch between fullscreen and windowed mode.
87 bool ToggleFullscreen();
89 /**
90 * Update window position, to restore later if necessary (SDL2 only).
92 void UpdatePosition(int x, int y);
94 /**
95 * Update the graphics code to start drawing to the new size.
96 * This should be called after the GL context has been resized.
97 * This can also be used when the GL context is managed externally, not via SDL.
99 static void UpdateRenderer(int w, int h);
101 int GetXRes() const;
102 int GetYRes() const;
103 int GetBPP() const;
105 bool IsVSyncEnabled() const;
107 int GetDesktopXRes() const;
108 int GetDesktopYRes() const;
109 int GetDesktopBPP() const;
110 int GetDesktopFreq() const;
112 float GetScale() const;
114 SDL_Window* GetWindow();
116 void SetWindowIcon();
118 void SetCursor(const CStrW& name);
119 void ResetCursor();
121 Renderer::Backend::IDevice* GetBackendDevice() { return m_BackendDevice.get(); }
123 private:
124 void ReadConfig();
125 int GetBestBPP();
126 bool SetVideoMode(int w, int h, int bpp, bool fullscreen);
128 bool TryCreateBackendDevice(SDL_Window* window);
129 void DowngradeBackendSettingAfterCreationFailure();
132 * Remember whether Init has been called. (This isn't used for anything
133 * important, just for verifying that the callers call our methods in
134 * the right order.)
136 bool m_IsInitialised = false;
138 SDL_Window* m_Window = nullptr;
140 // Initial desktop settings.
141 // Frequency is in Hz, and BPP means bits per pixels (not bytes per pixels).
142 int m_PreferredW = 0;
143 int m_PreferredH = 0;
144 int m_PreferredBPP = 0;
145 int m_PreferredFreq = 0;
147 float m_Scale = 1.0f;
149 // Config file settings (0 if unspecified)
150 int m_ConfigW = 0;
151 int m_ConfigH = 0;
152 int m_ConfigBPP = 0;
153 int m_ConfigDisplay = 0;
154 bool m_ConfigEnableHiDPI = false;
155 bool m_ConfigVSync = false;
157 // (m_ConfigFullscreen defaults to false, so users don't get stuck if
158 // e.g. half the filesystem is missing and the config files aren't loaded).
159 bool m_ConfigFullscreen = false;
161 // If we're fullscreen, size/position of window when we were last windowed (or the default window
162 // size/position if we started fullscreen), to support switching back to the old window size/position
163 int m_WindowedW;
164 int m_WindowedH;
165 int m_WindowedX;
166 int m_WindowedY;
168 // Whether we're currently being displayed fullscreen
169 bool m_IsFullscreen = false;
171 // The last mode selected
172 int m_CurrentW;
173 int m_CurrentH;
174 int m_CurrentBPP;
176 class CCursor;
177 std::unique_ptr<CCursor> m_Cursor;
179 Renderer::Backend::Backend m_Backend = Renderer::Backend::Backend::GL;
180 std::unique_ptr<Renderer::Backend::IDevice> m_BackendDevice;
183 extern CVideoMode g_VideoMode;
185 #endif // INCLUDED_VIDEOMODE