1 | /** |
2 | * Copyright (c) 2006-2023 LOVE Development Team |
3 | * |
4 | * This software is provided 'as-is', without any express or implied |
5 | * warranty. In no event will the authors be held liable for any damages |
6 | * arising from the use of this software. |
7 | * |
8 | * Permission is granted to anyone to use this software for any purpose, |
9 | * including commercial applications, and to alter it and redistribute it |
10 | * freely, subject to the following restrictions: |
11 | * |
12 | * 1. The origin of this software must not be misrepresented; you must not |
13 | * claim that you wrote the original software. If you use this software |
14 | * in a product, an acknowledgment in the product documentation would be |
15 | * appreciated but is not required. |
16 | * 2. Altered source versions must be plainly marked as such, and must not be |
17 | * misrepresented as being the original software. |
18 | * 3. This notice may not be removed or altered from any source distribution. |
19 | **/ |
20 | |
21 | #ifndef LOVE_WINDOW_WINDOW_H |
22 | #define LOVE_WINDOW_WINDOW_H |
23 | |
24 | // LOVE |
25 | #include "common/Module.h" |
26 | #include "common/StringMap.h" |
27 | #include "common/math.h" |
28 | #include "common/Optional.h" |
29 | #include "image/ImageData.h" |
30 | |
31 | // C++ |
32 | #include <string> |
33 | #include <vector> |
34 | |
35 | namespace love |
36 | { |
37 | |
38 | namespace graphics |
39 | { |
40 | class Graphics; |
41 | } |
42 | |
43 | namespace window |
44 | { |
45 | |
46 | // Forward-declared so it can be used in the class methods. We can't define the |
47 | // whole thing here because it uses the Window::Type enum. |
48 | struct WindowSettings; |
49 | |
50 | class Window : public Module |
51 | { |
52 | public: |
53 | |
54 | // Different window settings. |
55 | enum Setting |
56 | { |
57 | SETTING_FULLSCREEN, |
58 | SETTING_FULLSCREEN_TYPE, |
59 | SETTING_VSYNC, |
60 | SETTING_MSAA, |
61 | SETTING_STENCIL, |
62 | SETTING_DEPTH, |
63 | SETTING_RESIZABLE, |
64 | SETTING_MIN_WIDTH, |
65 | SETTING_MIN_HEIGHT, |
66 | SETTING_BORDERLESS, |
67 | SETTING_CENTERED, |
68 | SETTING_DISPLAY, |
69 | SETTING_HIGHDPI, |
70 | SETTING_USE_DPISCALE, |
71 | SETTING_REFRESHRATE, |
72 | SETTING_X, |
73 | SETTING_Y, |
74 | SETTING_MAX_ENUM |
75 | }; |
76 | |
77 | enum FullscreenType |
78 | { |
79 | FULLSCREEN_EXCLUSIVE, |
80 | FULLSCREEN_DESKTOP, |
81 | FULLSCREEN_MAX_ENUM |
82 | }; |
83 | |
84 | enum MessageBoxType |
85 | { |
86 | MESSAGEBOX_ERROR, |
87 | MESSAGEBOX_WARNING, |
88 | MESSAGEBOX_INFO, |
89 | MESSAGEBOX_MAX_ENUM |
90 | }; |
91 | |
92 | enum DisplayOrientation |
93 | { |
94 | ORIENTATION_UNKNOWN, |
95 | ORIENTATION_LANDSCAPE, |
96 | ORIENTATION_LANDSCAPE_FLIPPED, |
97 | ORIENTATION_PORTRAIT, |
98 | ORIENTATION_PORTRAIT_FLIPPED, |
99 | ORIENTATION_MAX_ENUM |
100 | }; |
101 | |
102 | struct WindowSize |
103 | { |
104 | int width; |
105 | int height; |
106 | |
107 | bool operator == (const WindowSize &w) const |
108 | { |
109 | return w.width == width && w.height == height; |
110 | } |
111 | }; |
112 | |
113 | struct MessageBoxData |
114 | { |
115 | MessageBoxType type; |
116 | |
117 | std::string title; |
118 | std::string message; |
119 | |
120 | std::vector<std::string> buttons; |
121 | int enterButtonIndex; |
122 | int escapeButtonIndex; |
123 | |
124 | bool attachToWindow; |
125 | }; |
126 | |
127 | virtual ~Window(); |
128 | |
129 | // Implements Module. |
130 | virtual ModuleType getModuleType() const { return M_WINDOW; } |
131 | |
132 | virtual void setGraphics(graphics::Graphics *graphics) = 0; |
133 | |
134 | virtual bool setWindow(int width = 800, int height = 600, WindowSettings *settings = nullptr) = 0; |
135 | virtual void getWindow(int &width, int &height, WindowSettings &settings) = 0; |
136 | |
137 | virtual void close() = 0; |
138 | |
139 | virtual bool setFullscreen(bool fullscreen, FullscreenType fstype) = 0; |
140 | virtual bool setFullscreen(bool fullscreen) = 0; |
141 | |
142 | virtual bool onSizeChanged(int width, int height) = 0; |
143 | |
144 | virtual int getDisplayCount() const = 0; |
145 | |
146 | virtual const char *getDisplayName(int displayindex) const = 0; |
147 | |
148 | virtual DisplayOrientation getDisplayOrientation(int displayindex) const = 0; |
149 | |
150 | virtual std::vector<WindowSize> getFullscreenSizes(int displayindex) const = 0; |
151 | |
152 | virtual void getDesktopDimensions(int displayindex, int &width, int &height) const = 0; |
153 | |
154 | virtual void setPosition(int x, int y, int displayindex) = 0; |
155 | virtual void getPosition(int &x, int &y, int &displayindex) = 0; |
156 | |
157 | virtual Rect getSafeArea() const = 0; |
158 | |
159 | virtual bool isOpen() const = 0; |
160 | |
161 | virtual void setWindowTitle(const std::string &title) = 0; |
162 | virtual const std::string &getWindowTitle() const = 0; |
163 | |
164 | virtual bool setIcon(love::image::ImageData *imgd) = 0; |
165 | virtual love::image::ImageData *getIcon() = 0; |
166 | |
167 | virtual void setVSync(int vsync) = 0; |
168 | virtual int getVSync() const = 0; |
169 | |
170 | virtual void setDisplaySleepEnabled(bool enable) = 0; |
171 | virtual bool isDisplaySleepEnabled() const = 0; |
172 | |
173 | virtual void minimize() = 0; |
174 | virtual void maximize() = 0; |
175 | virtual void restore() = 0; |
176 | |
177 | virtual bool isMaximized() const = 0; |
178 | virtual bool isMinimized() const = 0; |
179 | |
180 | // default no-op implementation |
181 | virtual void swapBuffers(); |
182 | |
183 | virtual bool hasFocus() const = 0; |
184 | virtual bool hasMouseFocus() const = 0; |
185 | |
186 | virtual bool isVisible() const = 0; |
187 | |
188 | virtual void setMouseGrab(bool grab) = 0; |
189 | virtual bool isMouseGrabbed() const = 0; |
190 | |
191 | virtual int getWidth() const = 0; |
192 | virtual int getHeight() const = 0; |
193 | virtual int getPixelWidth() const = 0; |
194 | virtual int getPixelHeight() const = 0; |
195 | |
196 | // Note: window-space coordinates are not necessarily the same as |
197 | // density-independent units (which toPixels and fromPixels use.) |
198 | virtual void windowToPixelCoords(double *x, double *y) const = 0; |
199 | virtual void pixelToWindowCoords(double *x, double *y) const = 0; |
200 | |
201 | virtual void windowToDPICoords(double *x, double *y) const = 0; |
202 | virtual void DPIToWindowCoords(double *x, double *y) const = 0; |
203 | |
204 | virtual double getDPIScale() const = 0; |
205 | virtual double getNativeDPIScale() const = 0; |
206 | |
207 | virtual double toPixels(double x) const = 0; |
208 | virtual void toPixels(double wx, double wy, double &px, double &py) const = 0; |
209 | virtual double fromPixels(double x) const = 0; |
210 | virtual void fromPixels(double px, double py, double &wx, double &wy) const = 0; |
211 | |
212 | virtual const void *getHandle() const = 0; |
213 | |
214 | virtual bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow) = 0; |
215 | virtual int showMessageBox(const MessageBoxData &data) = 0; |
216 | |
217 | virtual void requestAttention(bool continuous) = 0; |
218 | |
219 | static bool getConstant(const char *in, Setting &out); |
220 | static bool getConstant(Setting in, const char *&out); |
221 | |
222 | static bool getConstant(const char *in, FullscreenType &out); |
223 | static bool getConstant(FullscreenType in, const char *&out); |
224 | static std::vector<std::string> getConstants(FullscreenType); |
225 | |
226 | static bool getConstant(const char *in, MessageBoxType &out); |
227 | static bool getConstant(MessageBoxType in, const char *&out); |
228 | static std::vector<std::string> getConstants(MessageBoxType); |
229 | |
230 | static bool getConstant(const char *in, DisplayOrientation &out); |
231 | static bool getConstant(DisplayOrientation in, const char *&out); |
232 | static std::vector<std::string> getConstants(DisplayOrientation); |
233 | |
234 | private: |
235 | |
236 | static StringMap<Setting, SETTING_MAX_ENUM>::Entry settingEntries[]; |
237 | static StringMap<Setting, SETTING_MAX_ENUM> settings; |
238 | |
239 | static StringMap<FullscreenType, FULLSCREEN_MAX_ENUM>::Entry fullscreenTypeEntries[]; |
240 | static StringMap<FullscreenType, FULLSCREEN_MAX_ENUM> fullscreenTypes; |
241 | |
242 | static StringMap<MessageBoxType, MESSAGEBOX_MAX_ENUM>::Entry messageBoxTypeEntries[]; |
243 | static StringMap<MessageBoxType, MESSAGEBOX_MAX_ENUM> messageBoxTypes; |
244 | |
245 | static StringMap<DisplayOrientation, ORIENTATION_MAX_ENUM>::Entry orientationEntries[]; |
246 | static StringMap<DisplayOrientation, ORIENTATION_MAX_ENUM> orientations; |
247 | |
248 | }; // Window |
249 | |
250 | struct WindowSettings |
251 | { |
252 | bool fullscreen = false; |
253 | Window::FullscreenType fstype = Window::FULLSCREEN_DESKTOP; |
254 | int vsync = 1; |
255 | int msaa = 0; |
256 | bool stencil = true; |
257 | int depth = 0; |
258 | bool resizable = false; |
259 | int minwidth = 1; |
260 | int minheight = 1; |
261 | bool borderless = false; |
262 | bool centered = true; |
263 | int display = 0; |
264 | bool highdpi = false; |
265 | bool usedpiscale = true; |
266 | double refreshrate = 0.0; |
267 | bool useposition = false; |
268 | int x = 0; |
269 | int y = 0; |
270 | }; |
271 | |
272 | } // window |
273 | } // love |
274 | |
275 | #endif // LOVE_WINDOW_WINDOW_H |
276 | |