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  virtual 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 
125  State getState() const;
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 
141 protected:
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)
194 public:
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 
204 protected:
205  Uint32 _lastFlags;
206  bool _allowWindowSizeReset;
207  int _hintedWidth, _hintedHeight;
208 
209  bool createOrUpdateWindow(const int width, const int height, const Uint32 flags);
210 #endif
211 
212  SDL_Surface *_hwScreen;
213  SdlEventSource *_eventSource;
214  SdlWindow *_window;
215 
219  virtual bool canSwitchFullscreen() const { return false; }
220 
221 private:
222  void toggleFullScreen();
223 
224 #if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
225 public:
226  void setImGuiCallbacks(const ImGuiCallbacks &callbacks) override;
227 
228 protected:
229  ImGuiCallbacks _imGuiCallbacks;
230  bool _imGuiReady = false;
231  bool _imGuiInited = false;
232  SDL_Renderer *_imGuiSDLRenderer = nullptr;
233 
234  void initImGui(SDL_Renderer *renderer, void *glContext);
235  void renderImGui();
236  void destroyImGui();
237 #endif
238 
239 };
240 
241 #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:135
Definition: pixelformat.h:138
virtual void notifyVideoExpose()=0
Definition: rect.h:524
Definition: path.h:52
void getWindowSizeFromSdl(int *width, int *height) const
Definition: sdl-graphics.h:165
void handleResizeImpl(const int width, const int height) override
Definition: windowed.h:52
Common::RotationMode _rotationMode
Definition: windowed.h:467
Definition: sdl-graphics.h:109
Definition: events.h:329
Definition: events.h:210
bool setState(const State &state)
Definition: rect.h:144
virtual bool canSwitchFullscreen() const
Definition: sdl-graphics.h:219
void notifyActiveAreaChanged() override
RotationMode
Definition: rotationmode.h:44
Definition: sdl-window.h:30
virtual void notifyResize(const int width, const int height)
Definition: sdl-graphics.h:77