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 
31 class SdlEventSource;
32 
33 #define USE_OSD 1
34 
39 public:
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  Common::RotationMode getRotationMode() const override;
95 
96  virtual bool showMouse(bool visible) override;
97  bool lockMouse(bool lock) override;
98 
99  virtual bool saveScreenshot(const Common::Path &filename) const { return false; }
100  void saveScreenshot() override;
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 
116 #ifdef USE_RGB_COLOR
117  Graphics::PixelFormat pixelFormat;
118 #endif
119  };
120 
124  State getState() const;
125 
129  bool setState(const State &state);
130 
134  SdlWindow *getWindow() const { return _window; }
135 
136  void initSizeHint(const Graphics::ModeList &modes) override;
137 
138  Common::Keymap *getKeymap();
139 
140 protected:
141  enum CustomEventAction {
142  kActionToggleFullscreen = 100,
143  kActionToggleMouseCapture,
144  kActionSaveScreenshot,
145  kActionToggleAspectRatioCorrection,
146  kActionToggleFilteredScaling,
147  kActionCycleStretchMode,
148  kActionIncreaseScaleFactor,
149  kActionDecreaseScaleFactor,
150  kActionNextScaleFilter,
151  kActionPreviousScaleFilter
152  };
153 
156 
157  bool defaultGraphicsModeConfig() const;
158 
163  void getWindowSizeFromSdl(int *width, int *height) const {
164 #if SDL_VERSION_ATLEAST(2, 0, 0)
165  assert(_window);
166  SDL_GL_GetDrawableSize(_window->getSDLWindow(), width, height);
167 #else
168  assert(_hwScreen);
169 
170  if (width) {
171  *width = _hwScreen->w;
172  }
173 
174  if (height) {
175  *height = _hwScreen->h;
176  }
177 #endif
178  }
179 
180  virtual void showSystemMouseCursor(bool visible);
181 
182  void setSystemMousePosition(const int x, const int y) override;
183 
184  void notifyActiveAreaChanged() override;
185 
186  void handleResizeImpl(const int width, const int height) override;
187 
188 #if SDL_VERSION_ATLEAST(2, 0, 0)
189 public:
190  void unlockWindowSize() {
191  _allowWindowSizeReset = true;
192  _hintedWidth = 0;
193  _hintedHeight = 0;
194  }
195 
196 protected:
197  Uint32 _lastFlags;
198  bool _allowWindowSizeReset;
199  int _hintedWidth, _hintedHeight;
200 
201  bool createOrUpdateWindow(const int width, const int height, const Uint32 flags);
202 #endif
203 
204  SDL_Surface *_hwScreen;
205  SdlEventSource *_eventSource;
206  SdlWindow *_window;
207 
208 private:
209  void toggleFullScreen();
210 
211 #if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
212 public:
213  void setImGuiCallbacks(const ImGuiCallbacks &callbacks) override { _imGuiCallbacks = callbacks; }
214 
215 protected:
216  ImGuiCallbacks _imGuiCallbacks;
217  bool _imGuiReady = false;
218  bool _imGuiInited = false;
219  SDL_Renderer *_imGuiSDLRenderer = nullptr;
220 
221  void initImGui(SDL_Renderer *renderer, void *glContext);
222  void renderImGui();
223  void destroyImGui();
224 #endif
225 
226 };
227 
228 #endif
virtual void activateManager()
Definition: keymap.h:66
virtual bool notifyMousePosition(Common::Point &mouse)
void setSystemMousePosition(const int x, const int y) override
Definition: sdl-events.h:40
Common::Rect getPreferredFullscreenResolution()
bool notifyEvent(const Common::Event &event) override
Definition: sdl-graphics.h:38
virtual void deactivateManager()
Definition: array.h:52
State getState() const
SdlWindow * getWindow() const
Definition: sdl-graphics.h:134
Definition: pixelformat.h:138
virtual void notifyVideoExpose()=0
Definition: rect.h:144
Definition: path.h:52
void getWindowSizeFromSdl(int *width, int *height) const
Definition: sdl-graphics.h:163
void handleResizeImpl(const int width, const int height) override
Definition: windowed.h:52
Definition: sdl-graphics.h:109
Definition: events.h:318
Definition: events.h:199
bool setState(const State &state)
Definition: rect.h:45
RotationMode
Definition: rotationmode.h:44
void notifyActiveAreaChanged() override
Definition: sdl-window.h:30
virtual void notifyResize(const int width, const int height)
Definition: sdl-graphics.h:77