ScummVM API documentation
sdl-window.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_PLATFORM_SDL_WINDOW_H
23#define BACKENDS_PLATFORM_SDL_WINDOW_H
24
25#include "backends/platform/sdl/sdl-sys.h"
26
27#include "common/rect.h"
28#include "common/str.h"
29
30class SdlWindow {
31public:
32 SdlWindow();
33 virtual ~SdlWindow();
34
38 virtual void setupIcon();
39
45 void setWindowCaption(const Common::String &caption);
46
52 void setResizable(bool resizable);
53
58 void grabMouse(bool grab);
59
63 void setMouseRect(const Common::Rect &rect);
64
68 bool lockMouse(bool lock);
69
73 bool hasMouseFocus() const;
74
81 bool warpMouseInWindow(int x, int y);
82
87
88#if !SDL_VERSION_ATLEAST(3, 0, 0)
95 bool getSDLWMInformation(SDL_SysWMinfo *info) const;
96#endif
97
98 /*
99 * Retrieve the current desktop resolution.
100 */
101 Common::Rect getDesktopResolution();
102
103 /*
104 * Get the scaling between the SDL Window size and the SDL
105 * drawable area size. On some system, when HiDPI support is
106 * enabled, those two sizes are different.
107 *
108 * To convert from window coordinate to drawable area coordinate,
109 * multiple the coordinate by this scaling factor. To convert
110 * from drawable area coordinate to window coordinate, divide the
111 * coordinate by this scaling factor.
112 */
113 float getSdlDpiScalingFactor() const;
114
118 virtual float getDpiScalingFactor() const;
119
120 bool resizable() const {
121#if SDL_VERSION_ATLEAST(2, 0, 0)
122 if (_window) {
123 return SDL_GetWindowFlags(_window) & SDL_WINDOW_RESIZABLE;
124 }
125#endif
126 return _resizable;
127 }
128
129 bool mouseIsGrabbed() const {
130#if SDL_VERSION_ATLEAST(3, 0, 0)
131 if (_window) {
132 return SDL_GetWindowMouseGrab(_window);
133 }
134#elif SDL_VERSION_ATLEAST(2, 0, 0)
135 if (_window) {
136 return SDL_GetWindowGrab(_window) == SDL_TRUE;
137 }
138#endif
139 return _inputGrabState;
140 }
141
142 bool mouseIsLocked() const {
143#if SDL_VERSION_ATLEAST(3, 0, 0)
144 return SDL_GetWindowRelativeMouseMode(_window);
145#elif SDL_VERSION_ATLEAST(2, 0, 0)
146 return SDL_GetRelativeMouseMode() == SDL_TRUE;
147#else
148 return _inputLockState;
149#endif
150 }
151
152private:
153 Common::Rect _desktopRes;
154 bool _resizable;
155 bool _inputGrabState, _inputLockState;
156 SDL_Rect grabRect;
157
158protected:
159 void getDisplayDpi(float *dpi, float *defaultDpi) const;
160
161#if SDL_VERSION_ATLEAST(2, 0, 0)
162public:
166 SDL_Window *getSDLWindow() const { return _window; }
167
171 int getDisplayIndex() const;
172
181 virtual bool createOrUpdateWindow(int width, int height, uint32 flags);
182
186 void destroyWindow();
187
191 uint32 getWindowFlags() const { return _lastFlags; }
192
193protected:
194 SDL_Window *_window;
195
196private:
197 uint32 _lastFlags;
198
204 int _lastX, _lastY;
205
206 Common::String _windowCaption;
207#endif
208};
209
211public:
212 void setupIcon() override {}
213};
214
215#endif
Definition: str.h:59
Definition: sdl-window.h:210
void setupIcon() override
Definition: sdl-window.h:212
Definition: sdl-window.h:30
void setMouseRect(const Common::Rect &rect)
virtual void setupIcon()
void iconifyWindow()
virtual float getDpiScalingFactor() const
void setResizable(bool resizable)
void setWindowCaption(const Common::String &caption)
bool warpMouseInWindow(int x, int y)
void grabMouse(bool grab)
bool getSDLWMInformation(SDL_SysWMinfo *info) const
bool hasMouseFocus() const
bool lockMouse(bool lock)
Definition: rect.h:536