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