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 
30 class SdlWindow {
31 public:
32  SdlWindow();
33  virtual ~SdlWindow();
34 
38  virtual void setupIcon();
39 
45  void setWindowCaption(const Common::String &caption);
46 
51  void grabMouse(bool grab);
52 
56  void setMouseRect(const Common::Rect &rect);
57 
61  bool lockMouse(bool lock);
62 
66  bool hasMouseFocus() const;
67 
74  bool warpMouseInWindow(int x, int y);
75 
79  void iconifyWindow();
80 
87  bool getSDLWMInformation(SDL_SysWMinfo *info) const;
88 
89  /*
90  * Retrieve the current desktop resolution.
91  */
92  Common::Rect getDesktopResolution();
93 
94  /*
95  * Get the scaling between the SDL Window size and the SDL
96  * drawable area size. On some system, when HiDPI support is
97  * enabled, those two sizes are different.
98  *
99  * To convert from window coordinate to drawable area coordinate,
100  * multiple the coordinate by this scaling factor. To convert
101  * from drawable area coordinate to window coordinate, divide the
102  * coordinate by this scaling factor.
103  */
104  float getSdlDpiScalingFactor() const;
105 
109  virtual float getDpiScalingFactor() const;
110 
111  bool mouseIsGrabbed() const {
112 #if SDL_VERSION_ATLEAST(2, 0, 0)
113  if (_window) {
114  return SDL_GetWindowGrab(_window) == SDL_TRUE;
115  }
116 #endif
117  return _inputGrabState;
118  }
119 
120  bool mouseIsLocked() const {
121 #if SDL_VERSION_ATLEAST(2, 0, 0)
122  return SDL_GetRelativeMouseMode() == SDL_TRUE;
123 #else
124  return _inputLockState;
125 #endif
126  }
127 
128 private:
129  Common::Rect _desktopRes;
130  bool _inputGrabState, _inputLockState;
131  SDL_Rect grabRect;
132 
133 protected:
134  void getDisplayDpi(float *dpi, float *defaultDpi) const;
135 
136 #if SDL_VERSION_ATLEAST(2, 0, 0)
137 public:
141  SDL_Window *getSDLWindow() const { return _window; }
142 
146  int getDisplayIndex() const;
147 
156  virtual bool createOrUpdateWindow(int width, int height, uint32 flags);
157 
161  void destroyWindow();
162 
163 protected:
164  SDL_Window *_window;
165 
166 private:
167  uint32 _lastFlags;
168 
174  int _lastX, _lastY;
175 
176  Common::String _windowCaption;
177 #endif
178 };
179 
180 class SdlIconlessWindow : public SdlWindow {
181 public:
182  virtual void setupIcon() {}
183 };
184 
185 #endif
Definition: str.h:59
void setMouseRect(const Common::Rect &rect)
virtual void setupIcon()
Definition: sdl-window.h:180
void setWindowCaption(const Common::String &caption)
Definition: rect.h:144
bool warpMouseInWindow(int x, int y)
bool lockMouse(bool lock)
bool hasMouseFocus() const
void grabMouse(bool grab)
bool getSDLWMInformation(SDL_SysWMinfo *info) const
Definition: sdl-window.h:30
virtual float getDpiScalingFactor() const
virtual void setupIcon()
Definition: sdl-window.h:182
void iconifyWindow()