ScummVM API documentation
sdl-graphics.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef BACKENDS_GRAPHICS_SDL_SDLGRAPHICS_H
23#define BACKENDS_GRAPHICS_SDL_SDLGRAPHICS_H
24
25#include "backends/graphics/windowed.h"
26#include "backends/platform/sdl/sdl-window.h"
27
28#include "common/events.h"
29#include "common/rect.h"
30
31class SdlEventSource;
32
33#define USE_OSD 1
34
39public:
41 virtual ~SdlGraphicsManager() {}
42
48 virtual void activateManager();
49
54 virtual void deactivateManager();
55
62 virtual void notifyVideoExpose() = 0;
63
77 virtual void notifyResize(const int width, const int height) {}
78
92 virtual bool notifyMousePosition(Common::Point &mouse);
93
94 bool showMouse(bool visible) override;
95 bool lockMouse(bool lock) override;
96
97 virtual bool saveScreenshot(const Common::Path &filename) const { return false; }
98 void saveScreenshot() override;
99
100 bool setRotationMode(Common::RotationMode rotation) override { _rotationMode = rotation; return true; }
101
102 // Override from Common::EventObserver
103 bool notifyEvent(const Common::Event &event) override;
104
109 struct State {
110 int screenWidth, screenHeight;
111 bool aspectRatio;
112 bool fullscreen;
113 bool cursorPalette;
114 bool vsync;
115 Common::RotationMode rotation;
116
117#ifdef USE_RGB_COLOR
118 Graphics::PixelFormat pixelFormat;
119#endif
120 };
121
126
130 bool setState(const State &state);
131
135 SdlWindow *getWindow() const { return _window; }
136
137 void initSizeHint(const Graphics::ModeList &modes) override;
138
139 Common::Keymap *getKeymap();
140
141protected:
142 enum CustomEventAction {
143 kActionToggleFullscreen = 100,
144 kActionToggleMouseCapture,
145 kActionToggleResizableWindow,
146 kActionSaveScreenshot,
147 kActionToggleAspectRatioCorrection,
148 kActionToggleFilteredScaling,
149 kActionCycleStretchMode,
150 kActionIncreaseScaleFactor,
151 kActionDecreaseScaleFactor,
152 kActionNextScaleFilter,
153 kActionPreviousScaleFilter
154 };
155
158
159 bool defaultGraphicsModeConfig() const;
160
165 void getWindowSizeFromSdl(int *width, int *height) const {
166#if SDL_VERSION_ATLEAST(3, 0, 0)
167 assert(_window);
168 SDL_GetWindowSizeInPixels(_window->getSDLWindow(), width, height);
169#elif SDL_VERSION_ATLEAST(2, 0, 0)
170 assert(_window);
171 SDL_GL_GetDrawableSize(_window->getSDLWindow(), width, height);
172#else
173 assert(_hwScreen);
174
175 if (width) {
176 *width = _hwScreen->w;
177 }
178
179 if (height) {
180 *height = _hwScreen->h;
181 }
182#endif
183 }
184
185 virtual void showSystemMouseCursor(bool visible);
186
187 void setSystemMousePosition(const int x, const int y) override;
188
189 void notifyActiveAreaChanged() override;
190
191 void handleResizeImpl(const int width, const int height) override;
192
193#if SDL_VERSION_ATLEAST(2, 0, 0)
194public:
195 void unlockWindowSize() {
196 _allowWindowSizeReset = true;
197 _hintedWidth = 0;
198 _hintedHeight = 0;
199 }
200
201 // Called by SdlWindow when the window is about to be destroyed
202 virtual void destroyingWindow() {}
203
204protected:
205 bool _allowWindowSizeReset;
206 int _hintedWidth, _hintedHeight;
207
208 bool createOrUpdateWindow(const int width, const int height, const Uint32 flags);
209#endif
210
211 SDL_Surface *_hwScreen;
212 SdlEventSource *_eventSource;
213 SdlWindow *_window;
214
218 virtual bool canSwitchFullscreen() const { return false; }
219
220private:
221 void toggleFullScreen();
222
223#if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
224public:
225 void setImGuiCallbacks(const ImGuiCallbacks &callbacks) override;
226
227protected:
228 ImGuiCallbacks _imGuiCallbacks;
229 bool _imGuiReady = false;
230 bool _imGuiInited = false;
231 SDL_Renderer *_imGuiSDLRenderer = nullptr;
232
233 void initImGui(SDL_Renderer *renderer, void *glContext);
234 void renderImGui();
235 void destroyImGui();
236#endif
237
238};
239
240#endif
Definition: array.h:52
Definition: events.h:337
Definition: keymap.h:66
Definition: path.h:52
Definition: sdl-events.h:40
Definition: sdl-graphics.h:38
virtual bool notifyMousePosition(Common::Point &mouse)
virtual bool canSwitchFullscreen() const
Definition: sdl-graphics.h:218
virtual void notifyResize(const int width, const int height)
Definition: sdl-graphics.h:77
void notifyActiveAreaChanged() override
State getState() const
void handleResizeImpl(const int width, const int height) override
SdlWindow * getWindow() const
Definition: sdl-graphics.h:135
void setSystemMousePosition(const int x, const int y) override
virtual void notifyVideoExpose()=0
bool notifyEvent(const Common::Event &event) override
void getWindowSizeFromSdl(int *width, int *height) const
Definition: sdl-graphics.h:165
Common::Rect getPreferredFullscreenResolution()
bool setState(const State &state)
virtual void activateManager()
virtual void deactivateManager()
Definition: sdl-window.h:30
Definition: windowed.h:52
Common::RotationMode _rotationMode
Definition: windowed.h:488
RotationMode
Definition: rotationmode.h:44
Definition: events.h:218
Definition: rect.h:144
Definition: rect.h:536
Definition: pixelformat.h:138
Definition: sdl-graphics.h:109