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)
32 typedef SDLKey SDL_Keycode;
33 typedef SDLMod SDL_Keymod;
34 typedef SDL_keysym SDL_Keysym;
35 #endif
36 
41 public:
43  virtual ~SdlEventSource();
44 
45  void setGraphicsManager(SdlGraphicsManager *gMan) { _graphicsManager = gMan; }
46 
50  virtual bool pollEvent(Common::Event &event);
51 
56  void fakeWarpMouse(const int x, const int y);
57 
59  bool isJoystickConnected() const;
60 
62  void setEngineRunning(bool value);
63 
64 protected:
67 
68  bool _engineRunning;
69 
70  int _mouseX;
71  int _mouseY;
72 
74  SDL_Joystick *_joystick;
75 
76 #if SDL_VERSION_ATLEAST(2, 0, 0)
77 
78  SDL_GameController *_controller;
79 #endif
80 
83 
88 
93 
102  void openJoystick(int joystickIndex);
103 
107  void closeJoystick();
108 
112  virtual void preprocessEvents(SDL_Event *event) {}
113 
117  virtual bool dispatchSDLEvent(SDL_Event &ev, Common::Event &event);
118 
119 
127 
128  virtual bool handleKeyDown(SDL_Event &ev, Common::Event &event);
129  virtual bool handleKeyUp(SDL_Event &ev, Common::Event &event);
130  virtual bool handleMouseMotion(SDL_Event &ev, Common::Event &event);
131  virtual bool handleMouseButtonDown(SDL_Event &ev, Common::Event &event);
132  virtual bool handleMouseButtonUp(SDL_Event &ev, Common::Event &event);
133  virtual bool handleSysWMEvent(SDL_Event &ev, Common::Event &event);
134  virtual int mapSDLJoystickButtonToOSystem(Uint8 sdlButton);
135  virtual bool handleJoyButtonDown(SDL_Event &ev, Common::Event &event);
136  virtual bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event);
137  virtual bool handleJoyAxisMotion(SDL_Event &ev, Common::Event &event);
138  virtual bool handleJoyHatMotion(SDL_Event &ev, Common::Event &event);
139 
140 #if SDL_VERSION_ATLEAST(2, 0, 0)
141  virtual bool handleJoystickAdded(const SDL_JoyDeviceEvent &device, Common::Event &event);
142  virtual bool handleJoystickRemoved(const SDL_JoyDeviceEvent &device, Common::Event &event);
143  virtual int mapSDLControllerButtonToOSystem(Uint8 sdlButton);
144  virtual bool handleControllerButton(const SDL_Event &ev, Common::Event &event, bool buttonUp);
145  virtual bool handleControllerAxisMotion(const SDL_Event &ev, Common::Event &event);
146 
147  virtual bool isTouchPortTouchpadMode(SDL_TouchID port);
148  virtual bool isTouchPortActive(SDL_TouchID port);
149  virtual Common::Point getTouchscreenSize();
150  virtual void convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY);
151 #endif
152 
154 
160  virtual bool processMouseEvent(Common::Event &event, int x, int y, int relx = 0, int rely = 0);
161 
166  virtual bool remapKey(SDL_Event &ev, Common::Event &event);
167 
171  virtual int mapKey(SDL_Keycode key, SDL_Keymod mod, Uint16 unicode);
172 
176  virtual void SDLModToOSystemKeyFlags(SDL_Keymod mod, Common::Event &event);
177 
181  Common::KeyCode SDLToOSystemKeycode(const SDL_Keycode key);
182 
186  bool handleResizeEvent(Common::Event &event, int w, int h);
187 
192  uint32 obtainUnicode(const SDL_Keysym keySym);
193 
197  SDL_Keycode obtainKeycode(const SDL_Keysym keySym);
198 
203 
210 
211  uint8 _lastHatPosition;
212 
213 #if SDL_VERSION_ATLEAST(2, 0, 0)
214 
217  bool _queuedFakeKeyUp;
218 
223  Common::Event _fakeKeyUp;
224 
225  enum {
226  MAX_NUM_FINGERS = 3, // number of fingers to track per panel
227  MAX_TAP_TIME = 250, // taps longer than this will not result in mouse click events
228  MAX_TAP_MOTION_DISTANCE = 10, // max distance finger motion in Vita screen pixels to be considered a tap
229  SIMULATED_CLICK_DURATION = 50, // time in ms how long simulated mouse clicks should be
230  FINGER_SUBPIXEL_MULTIPLIER = 16 // multiplier for sub-pixel resolution
231  };
232 
233  struct TouchFinger {
234  int id = -1; // -1: no touch
235  uint32 timeLastDown = 0;
236  int lastX = 0; // last known screen coordinates
237  int lastY = 0; // last known screen coordinates
238  float lastDownX = 0; // SDL touch coordinates when last pressed down
239  float lastDownY = 0; // SDL touch coordinates when last pressed down
240  };
241 
242  enum DraggingType {
243  DRAG_NONE = 0,
244  DRAG_TWO_FINGER,
245  DRAG_THREE_FINGER,
246  };
247 
248  struct TouchPanelState {
249  TouchFinger _finger[MAX_NUM_FINGERS]; // keep track of finger status
250  DraggingType _multiFingerDragging = DRAG_NONE; // keep track whether we are currently drag-and-dropping
251  unsigned int _simulatedClickStartTime[2] = {0, 0}; // initiation time of last simulated left or right click (zero if no click)
252  int _hiresDX = 0; // keep track of slow, sub-pixel, finger motion across multiple frames
253  int _hiresDY = 0;
254  bool _tapMade = false;
255  };
256 
258 
259 private:
260  void preprocessFingerDown(SDL_Event *event);
261  bool preprocessFingerUp(SDL_Event *event, Common::Event *ev);
262  void preprocessFingerMotion(SDL_Event *event);
263  void finishSimulatedMouseClicks(void);
264 #endif
265 };
266 
267 #endif
void setEngineRunning(bool value)
virtual bool dispatchSDLEvent(SDL_Event &ev, Common::Event &event)
void closeJoystick()
SdlGraphicsManager * _graphicsManager
Definition: sdl-events.h:87
Definition: sdl-events.h:40
bool _queuedFakeMouseMove
Definition: sdl-events.h:202
Definition: sdl-graphics.h:38
bool _scrollLock
Definition: sdl-events.h:66
void fakeWarpMouse(const int x, const int y)
bool handleResizeEvent(Common::Event &event, int w, int h)
void loadGameControllerMappingFile()
Definition: hashmap.h:85
virtual int mapKey(SDL_Keycode key, SDL_Keymod mod, Uint16 unicode)
void openJoystick(int joystickIndex)
virtual bool pollEvent(Common::Event &event)
uint32 obtainUnicode(const SDL_Keysym keySym)
bool isJoystickConnected() const
virtual void SDLModToOSystemKeyFlags(SDL_Keymod mod, Common::Event &event)
Definition: events.h:199
virtual void preprocessEvents(SDL_Event *event)
Definition: sdl-events.h:112
Definition: rect.h:45
int _lastScreenID
Definition: sdl-events.h:82
Common::Event _fakeMouseMove
Definition: sdl-events.h:209
virtual bool processMouseEvent(Common::Event &event, int x, int y, int relx=0, int rely=0)
Common::KeyCode SDLToOSystemKeycode(const SDL_Keycode key)
Definition: events.h:259
SDL_Joystick * _joystick
Definition: sdl-events.h:74
virtual bool remapKey(SDL_Event &ev, Common::Event &event)
SDL_Keycode obtainKeycode(const SDL_Keysym keySym)