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 "util/circle-buffer.h"
13#include "util/vector.h"
14
15#include <SDL.h>
16
17#define SDL_BINDING_KEY 0x53444C4BU
18#define SDL_BINDING_BUTTON 0x53444C42U
19
20#define MAX_PLAYERS 4
21
22struct Configuration;
23
24struct SDL_JoystickCombo {
25 SDL_JoystickID id;
26 size_t index;
27 SDL_Joystick* joystick;
28#if SDL_VERSION_ATLEAST(2, 0, 0)
29 SDL_Haptic* haptic;
30#endif
31};
32
33DECLARE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo);
34
35struct mSDLPlayer;
36struct mSDLEvents {
37 struct SDL_JoystickList joysticks;
38 const char* preferredJoysticks[MAX_PLAYERS];
39 int playersAttached;
40 struct mSDLPlayer* players[MAX_PLAYERS];
41#if SDL_VERSION_ATLEAST(2, 0, 0)
42 int screensaverSuspendDepth;
43 bool screensaverSuspendable;
44#endif
45};
46
47struct mSDLPlayer {
48 size_t playerId;
49 struct mInputMap* bindings;
50 struct SDL_JoystickCombo* joystick;
51#if SDL_VERSION_ATLEAST(2, 0, 0)
52 SDL_Window* window;
53 int fullscreen;
54 int windowUpdated;
55
56 struct mSDLRumble {
57 struct mRumble d;
58 struct mSDLPlayer* p;
59
60 int level;
61 struct CircleBuffer history;
62 } rumble;
63#endif
64
65 struct mSDLRotation {
66 struct mRotationSource d;
67 struct mSDLPlayer* p;
68
69 // Tilt
70 int axisX;
71 int axisY;
72
73 // Gyro
74 int gyroX;
75 int gyroY;
76 float gyroSensitivity;
77 struct CircleBuffer zHistory;
78 int oldX;
79 int oldY;
80 float zDelta;
81 } rotation;
82};
83
84bool mSDLInitEvents(struct mSDLEvents*);
85void mSDLDeinitEvents(struct mSDLEvents*);
86
87bool mSDLAttachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
88void mSDLDetachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
89void mSDLEventsLoadConfig(struct mSDLEvents*, const struct Configuration*);
90void mSDLPlayerChangeJoystick(struct mSDLEvents*, struct mSDLPlayer*, size_t index);
91void mSDLUpdateJoysticks(struct mSDLEvents* events);
92
93void mSDLPlayerLoadConfig(struct mSDLPlayer*, const struct Configuration*);
94void mSDLPlayerSaveConfig(const struct mSDLPlayer*, struct Configuration*);
95
96void mSDLInitBindingsGBA(struct mInputMap* inputMap);
97
98struct mCoreThread;
99void mSDLHandleEvent(struct mCoreThread* context, struct mSDLPlayer* sdlContext, const union SDL_Event* event);
100
101#if SDL_VERSION_ATLEAST(2, 0, 0)
102void mSDLSuspendScreensaver(struct mSDLEvents*);
103void mSDLResumeScreensaver(struct mSDLEvents*);
104void mSDLSetScreensaverSuspendable(struct mSDLEvents*, bool suspendable);
105#endif
106
107#endif