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_SDL_WINDOW_H |
22 | #define LOVE_WINDOW_SDL_WINDOW_H |
23 | |
24 | // LOVE |
25 | #include "window/Window.h" |
26 | |
27 | // SDL |
28 | #include <SDL.h> |
29 | |
30 | namespace love |
31 | { |
32 | namespace window |
33 | { |
34 | namespace sdl |
35 | { |
36 | |
37 | class Window final : public love::window::Window |
38 | { |
39 | public: |
40 | |
41 | Window(); |
42 | ~Window(); |
43 | |
44 | void setGraphics(graphics::Graphics *graphics) override; |
45 | |
46 | bool setWindow(int width = 800, int height = 600, WindowSettings *settings = nullptr) override; |
47 | void getWindow(int &width, int &height, WindowSettings &settings) override; |
48 | |
49 | void close() override; |
50 | |
51 | bool setFullscreen(bool fullscreen, FullscreenType fstype) override; |
52 | bool setFullscreen(bool fullscreen) override; |
53 | |
54 | bool onSizeChanged(int width, int height) override; |
55 | |
56 | int getDisplayCount() const override; |
57 | |
58 | const char *getDisplayName(int displayindex) const override; |
59 | |
60 | DisplayOrientation getDisplayOrientation(int displayindex) const override; |
61 | |
62 | std::vector<WindowSize> getFullscreenSizes(int displayindex) const override; |
63 | |
64 | void getDesktopDimensions(int displayindex, int &width, int &height) const override; |
65 | |
66 | void setPosition(int x, int y, int displayindex) override; |
67 | void getPosition(int &x, int &y, int &displayindex) override; |
68 | |
69 | Rect getSafeArea() const override; |
70 | |
71 | bool isOpen() const override; |
72 | |
73 | void setWindowTitle(const std::string &title) override; |
74 | const std::string &getWindowTitle() const override; |
75 | |
76 | bool setIcon(love::image::ImageData *imgd) override; |
77 | love::image::ImageData *getIcon() override; |
78 | |
79 | void setVSync(int vsync) override; |
80 | int getVSync() const override; |
81 | |
82 | void setDisplaySleepEnabled(bool enable) override; |
83 | bool isDisplaySleepEnabled() const override; |
84 | |
85 | void minimize() override; |
86 | void maximize() override; |
87 | void restore() override; |
88 | |
89 | bool isMaximized() const override; |
90 | bool isMinimized() const override; |
91 | |
92 | void swapBuffers() override; |
93 | |
94 | bool hasFocus() const override; |
95 | bool hasMouseFocus() const override; |
96 | |
97 | bool isVisible() const override; |
98 | |
99 | void setMouseGrab(bool grab) override; |
100 | bool isMouseGrabbed() const override; |
101 | |
102 | int getWidth() const override; |
103 | int getHeight() const override; |
104 | int getPixelWidth() const override; |
105 | int getPixelHeight() const override; |
106 | |
107 | void windowToPixelCoords(double *x, double *y) const override; |
108 | void pixelToWindowCoords(double *x, double *y) const override; |
109 | |
110 | void windowToDPICoords(double *x, double *y) const override; |
111 | void DPIToWindowCoords(double *x, double *y) const override; |
112 | |
113 | double getDPIScale() const override; |
114 | double getNativeDPIScale() const override; |
115 | |
116 | double toPixels(double x) const override; |
117 | void toPixels(double wx, double wy, double &px, double &py) const override; |
118 | double fromPixels(double x) const override; |
119 | void fromPixels(double px, double py, double &wx, double &wy) const override; |
120 | |
121 | const void *getHandle() const override; |
122 | |
123 | bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow) override; |
124 | int showMessageBox(const MessageBoxData &data) override; |
125 | |
126 | void requestAttention(bool continuous) override; |
127 | |
128 | const char *getName() const override; |
129 | |
130 | private: |
131 | |
132 | void close(bool allowExceptions); |
133 | |
134 | struct ContextAttribs |
135 | { |
136 | int versionMajor; |
137 | int versionMinor; |
138 | bool gles; |
139 | bool debug; |
140 | }; |
141 | |
142 | void setGLFramebufferAttributes(int msaa, bool sRGB, bool stencil, int depth); |
143 | void setGLContextAttributes(const ContextAttribs &attribs); |
144 | bool checkGLVersion(const ContextAttribs &attribs, std::string &outversion); |
145 | std::vector<ContextAttribs> getContextAttribsList() const; |
146 | bool createWindowAndContext(int x, int y, int w, int h, Uint32 windowflags, int msaa, bool stencil, int depth); |
147 | |
148 | // Update the saved window settings based on the window's actual state. |
149 | void updateSettings(const WindowSettings &newsettings, bool updateGraphicsViewport); |
150 | |
151 | SDL_MessageBoxFlags convertMessageBoxType(MessageBoxType type) const; |
152 | |
153 | std::string title; |
154 | |
155 | int windowWidth = 800; |
156 | int windowHeight = 600; |
157 | int pixelWidth = 800; |
158 | int pixelHeight = 600; |
159 | WindowSettings settings; |
160 | StrongRef<love::image::ImageData> icon; |
161 | |
162 | bool open; |
163 | |
164 | bool mouseGrabbed; |
165 | |
166 | SDL_Window *window; |
167 | SDL_GLContext context; |
168 | |
169 | bool displayedWindowError; |
170 | bool hasSDL203orEarlier; |
171 | ContextAttribs contextAttribs; |
172 | |
173 | StrongRef<graphics::Graphics> graphics; |
174 | |
175 | }; // Window |
176 | |
177 | } // sdl |
178 | } // window |
179 | } // love |
180 | |
181 | #endif // LOVE_WINDOW_WINDOW_H |
182 | |