ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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  kActionToggleResizableWindow,
145  kActionSaveScreenshot,
146  kActionToggleAspectRatioCorrection,
147  kActionToggleFilteredScaling,
148  kActionCycleStretchMode,
149  kActionIncreaseScaleFactor,
150  kActionDecreaseScaleFactor,
151  kActionNextScaleFilter,
152  kActionPreviousScaleFilter
153  };
154 
157 
158  bool defaultGraphicsModeConfig() const;
159 
164  void getWindowSizeFromSdl(int *width, int *height) const {
165 #if SDL_VERSION_ATLEAST(3, 0, 0)
166  assert(_window);
167  SDL_GetWindowSizeInPixels(_window->getSDLWindow(), width, height);
168 #elif SDL_VERSION_ATLEAST(2, 0, 0)
169  assert(_window);
170  SDL_GL_GetDrawableSize(_window->getSDLWindow(), width, height);
171 #else
172  assert(_hwScreen);
173 
174  if (width) {
175  *width = _hwScreen->w;
176  }
177 
178  if (height) {
179  *height = _hwScreen->h;
180  }
181 #endif
182  }
183 
184  virtual void showSystemMouseCursor(bool visible);
185 
186  void setSystemMousePosition(const int x, const int y) override;
187 
188  void notifyActiveAreaChanged() override;
189 
190  void handleResizeImpl(const int width, const int height) override;
191 
192 #if SDL_VERSION_ATLEAST(2, 0, 0)
193 public:
194  void unlockWindowSize() {
195  _allowWindowSizeReset = true;
196  _hintedWidth = 0;
197  _hintedHeight = 0;
198  }
199 
200 protected:
201  Uint32 _lastFlags;
202  bool _allowWindowSizeReset;
203  int _hintedWidth, _hintedHeight;
204 
205  bool createOrUpdateWindow(const int width, const int height, const Uint32 flags);
206 #endif
207 
208  SDL_Surface *_hwScreen;
209  SdlEventSource *_eventSource;
210  SdlWindow *_window;
211 
212 private:
213  void toggleFullScreen();
214 
215 #if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
216 public:
217  void setImGuiCallbacks(const ImGuiCallbacks &callbacks) override;
218 
219 protected:
220  ImGuiCallbacks _imGuiCallbacks;
221  bool _imGuiReady = false;
222  bool _imGuiInited = false;
223  SDL_Renderer *_imGuiSDLRenderer = nullptr;
224 
225  void initImGui(SDL_Renderer *renderer, void *glContext);
226  void renderImGui();
227  void destroyImGui();
228 #endif
229 
230 };
231 
232 #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:164
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