src/platform/sdl/sdl-events.h (view raw)
1/* Copyright (c) 2013-2014 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef SDL_EVENTS_H
7#define SDL_EVENTS_H
8
9#include "util/common.h"
10
11#include "core/interface.h"
12#include "core/log.h"
13#include "util/circle-buffer.h"
14#include "util/vector.h"
15
16#include <SDL.h>
17
18mLOG_DECLARE_CATEGORY(SDL_EVENTS);
19
20#define SDL_BINDING_KEY 0x53444C4BU
21#define SDL_BINDING_BUTTON 0x53444C42U
22
23#define MAX_PLAYERS 4
24
25struct Configuration;
26
27struct SDL_JoystickCombo {
28 size_t index;
29 SDL_Joystick* joystick;
30#if SDL_VERSION_ATLEAST(2, 0, 0)
31 SDL_Haptic* haptic;
32 SDL_JoystickID id;
33#else
34 int id;
35#endif
36};
37
38DECLARE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo);
39
40struct mSDLPlayer;
41struct mSDLEvents {
42 struct SDL_JoystickList joysticks;
43 const char* preferredJoysticks[MAX_PLAYERS];
44 int playersAttached;
45 struct mSDLPlayer* players[MAX_PLAYERS];
46#if SDL_VERSION_ATLEAST(2, 0, 0)
47 int screensaverSuspendDepth;
48 bool screensaverSuspendable;
49#endif
50};
51
52struct mSDLPlayer {
53 size_t playerId;
54 struct mInputMap* bindings;
55 struct SDL_JoystickCombo* joystick;
56#if SDL_VERSION_ATLEAST(2, 0, 0)
57 SDL_Window* window;
58 int fullscreen;
59 int windowUpdated;
60
61 struct mSDLRumble {
62 struct mRumble d;
63 struct mSDLPlayer* p;
64
65 int level;
66 float activeLevel;
67 struct CircleBuffer history;
68 } rumble;
69#endif
70
71 struct mSDLRotation {
72 struct mRotationSource d;
73 struct mSDLPlayer* p;
74
75 // Tilt
76 int axisX;
77 int axisY;
78
79 // Gyro
80 int gyroX;
81 int gyroY;
82 float gyroSensitivity;
83 struct CircleBuffer zHistory;
84 int oldX;
85 int oldY;
86 float zDelta;
87 } rotation;
88};
89
90bool mSDLInitEvents(struct mSDLEvents*);
91void mSDLDeinitEvents(struct mSDLEvents*);
92
93bool mSDLAttachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
94void mSDLDetachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
95void mSDLEventsLoadConfig(struct mSDLEvents*, const struct Configuration*);
96void mSDLPlayerChangeJoystick(struct mSDLEvents*, struct mSDLPlayer*, size_t index);
97void mSDLUpdateJoysticks(struct mSDLEvents* events);
98
99void mSDLPlayerLoadConfig(struct mSDLPlayer*, const struct Configuration*);
100void mSDLPlayerSaveConfig(const struct mSDLPlayer*, struct Configuration*);
101
102void mSDLInitBindingsGBA(struct mInputMap* inputMap);
103
104struct mCoreThread;
105void mSDLHandleEvent(struct mCoreThread* context, struct mSDLPlayer* sdlContext, const union SDL_Event* event);
106
107#if SDL_VERSION_ATLEAST(2, 0, 0)
108void mSDLSuspendScreensaver(struct mSDLEvents*);
109void mSDLResumeScreensaver(struct mSDLEvents*);
110void mSDLSetScreensaverSuspendable(struct mSDLEvents*, bool suspendable);
111#endif
112
113#endif