ScummVM API documentation
sdl-events.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 BACKEND_EVENTS_SDL_H
23#define BACKEND_EVENTS_SDL_H
24
25#include "backends/platform/sdl/sdl-sys.h"
26#include "backends/graphics/sdl/sdl-graphics.h"
27
28#include "common/events.h"
29
30// Type names which changed between SDL 1.2 and SDL 2.
31#if !SDL_VERSION_ATLEAST(2, 0, 0)
32typedef SDLKey SDL_Keycode;
33typedef SDLMod SDL_Keymod;
34typedef SDL_keysym SDL_Keysym;
35#endif
36
41public:
43 virtual ~SdlEventSource();
44
45 void setGraphicsManager(SdlGraphicsManager *gMan) { _graphicsManager = gMan; }
46
50 bool pollEvent(Common::Event &event) override;
51
56 void fakeWarpMouse(const int x, const int y);
57
59 bool isJoystickConnected() const;
60
62 void setEngineRunning(bool value);
63
64protected:
67
68 bool _engineRunning;
69
70 int _mouseX;
71 int _mouseY;
72
74 SDL_Joystick *_joystick;
75
76#if SDL_VERSION_ATLEAST(3, 0, 0)
78 SDL_Gamepad *_controller;
79#elif SDL_VERSION_ATLEAST(2, 0, 0)
81 SDL_GameController *_controller;
82#endif
83
86
91
96
105 void openJoystick(int joystickIndex);
106
111
115 virtual void preprocessEvents(SDL_Event *event) {}
116
120 virtual bool dispatchSDLEvent(SDL_Event &ev, Common::Event &event);
121
122
130
131 virtual bool handleKeyDown(SDL_Event &ev, Common::Event &event);
132 virtual bool handleKeyUp(SDL_Event &ev, Common::Event &event);
133 virtual bool handleMouseMotion(SDL_Event &ev, Common::Event &event);
134 virtual bool handleMouseButtonDown(SDL_Event &ev, Common::Event &event);
135 virtual bool handleMouseButtonUp(SDL_Event &ev, Common::Event &event);
136 virtual bool handleSysWMEvent(SDL_Event &ev, Common::Event &event);
137 virtual int mapSDLJoystickButtonToOSystem(Uint8 sdlButton);
138 virtual bool handleJoyButtonDown(SDL_Event &ev, Common::Event &event);
139 virtual bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event);
140 virtual bool handleJoyAxisMotion(SDL_Event &ev, Common::Event &event);
141 virtual bool handleJoyHatMotion(SDL_Event &ev, Common::Event &event);
142
143#if SDL_VERSION_ATLEAST(2, 0, 0)
144 virtual bool handleJoystickAdded(const SDL_JoyDeviceEvent &device, Common::Event &event);
145 virtual bool handleJoystickRemoved(const SDL_JoyDeviceEvent &device, Common::Event &event);
146 virtual int mapSDLControllerButtonToOSystem(Uint8 sdlButton);
147 virtual bool handleControllerButton(const SDL_Event &ev, Common::Event &event, bool buttonUp);
148 virtual bool handleControllerAxisMotion(const SDL_Event &ev, Common::Event &event);
149
150 virtual bool isTouchPortTouchpadMode(SDL_TouchID port);
151 virtual bool isTouchPortActive(SDL_TouchID port);
152 virtual Common::Point getTouchscreenSize();
153 virtual void convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY);
154#endif
155
157
163 virtual bool processMouseEvent(Common::Event &event, int x, int y, int relx = 0, int rely = 0);
164
169 virtual bool remapKey(SDL_Event &ev, Common::Event &event);
170
174 virtual int mapKey(SDL_Keycode key, SDL_Keymod mod, Uint16 unicode);
175
179 virtual void SDLModToOSystemKeyFlags(SDL_Keymod mod, Common::Event &event);
180
184 Common::KeyCode SDLToOSystemKeycode(const SDL_Keycode key);
185
189 bool handleResizeEvent(Common::Event &event, int w, int h);
190
195 uint32 obtainUnicode(const SDL_KeyboardEvent &key);
196
197#if !SDL_VERSION_ATLEAST(3, 0, 0)
201 SDL_Keycode obtainKeycode(const SDL_Keysym keySym);
202#endif
203
208
215
223
224public:
225 void setStaleMousePositionWorkaround(bool enable) { _staleMousePositionWorkaround = enable; }
226 bool getStaleMousePositionWorkaround() const { return _staleMousePositionWorkaround; }
227
228protected:
229
230 uint8 _lastHatPosition;
231
232#if SDL_VERSION_ATLEAST(2, 0, 0)
236 bool _queuedFakeKeyUp;
237
242 Common::Event _fakeKeyUp;
243
247 int _queuedFakeMouseScroll;
248
254 Common::Event _fakeMouseScroll;
255
256 enum {
257 MAX_NUM_FINGERS = 3, // number of fingers to track per panel
258 MAX_TAP_TIME = 250, // taps longer than this will not result in mouse click events
259 MAX_TAP_MOTION_DISTANCE = 10, // max distance finger motion in Vita screen pixels to be considered a tap
260 SIMULATED_CLICK_DURATION = 50, // time in ms how long simulated mouse clicks should be
261 FINGER_SUBPIXEL_MULTIPLIER = 16 // multiplier for sub-pixel resolution
262 };
263
264 struct TouchFinger {
265#if SDL_VERSION_ATLEAST(3, 0, 0)
266 SDL_FingerID id = 0; // 0: no touch
267#else
268 int id = -1; // -1: no touch
269#endif
270 uint32 timeLastDown = 0;
271 int lastX = 0; // last known screen coordinates
272 int lastY = 0; // last known screen coordinates
273 float lastDownX = 0; // SDL touch coordinates when last pressed down
274 float lastDownY = 0; // SDL touch coordinates when last pressed down
275 };
276
277 enum DraggingType {
278 DRAG_NONE = 0,
279 DRAG_TWO_FINGER,
280 DRAG_THREE_FINGER,
281 };
282
283 struct TouchPanelState {
284 TouchFinger _finger[MAX_NUM_FINGERS]; // keep track of finger status
285 DraggingType _multiFingerDragging = DRAG_NONE; // keep track whether we are currently drag-and-dropping
286 unsigned int _simulatedClickStartTime[2] = {0, 0}; // initiation time of last simulated left or right click (zero if no click)
287 int _hiresDX = 0; // keep track of slow, sub-pixel, finger motion across multiple frames
288 int _hiresDY = 0;
289 bool _tapMade = false;
290 };
291
293
294private:
295 void preprocessFingerDown(SDL_Event *event);
296 bool preprocessFingerUp(SDL_Event *event, Common::Event *ev);
297 void preprocessFingerMotion(SDL_Event *event);
298 void finishSimulatedMouseClicks(void);
299#endif
300};
301
302#endif
Definition: events.h:278
Definition: hashmap.h:85
Definition: sdl-events.h:40
bool _staleMousePositionWorkaround
Definition: sdl-events.h:222
void closeJoystick()
void setEngineRunning(bool value)
SDL_Keycode obtainKeycode(const SDL_Keysym keySym)
virtual bool remapKey(SDL_Event &ev, Common::Event &event)
virtual bool dispatchSDLEvent(SDL_Event &ev, Common::Event &event)
virtual void SDLModToOSystemKeyFlags(SDL_Keymod mod, Common::Event &event)
virtual int mapKey(SDL_Keycode key, SDL_Keymod mod, Uint16 unicode)
uint32 obtainUnicode(const SDL_KeyboardEvent &key)
SDL_Joystick * _joystick
Definition: sdl-events.h:74
bool _queuedFakeMouseMove
Definition: sdl-events.h:207
void openJoystick(int joystickIndex)
SdlGraphicsManager * _graphicsManager
Definition: sdl-events.h:90
bool pollEvent(Common::Event &event) override
Common::KeyCode SDLToOSystemKeycode(const SDL_Keycode key)
void loadGameControllerMappingFile()
virtual void preprocessEvents(SDL_Event *event)
Definition: sdl-events.h:115
bool handleResizeEvent(Common::Event &event, int w, int h)
void fakeWarpMouse(const int x, const int y)
bool isJoystickConnected() const
virtual bool processMouseEvent(Common::Event &event, int x, int y, int relx=0, int rely=0)
int _lastScreenID
Definition: sdl-events.h:85
bool _scrollLock
Definition: sdl-events.h:66
Common::Event _fakeMouseMove
Definition: sdl-events.h:214
Definition: sdl-graphics.h:38
Definition: events.h:218
Definition: rect.h:144