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#include "util/circle-buffer.h"
11
12#include "gba/supervisor/thread.h"
13
14#include <SDL.h>
15
16#define SDL_BINDING_KEY 0x53444C4BU
17#define SDL_BINDING_BUTTON 0x53444C42U
18
19#define MAX_PLAYERS 4
20
21struct GBAVideoSoftwareRenderer;
22struct Configuration;
23
24struct GBASDLEvents {
25 SDL_Joystick** joysticks;
26 size_t nJoysticks;
27 const char* preferredJoysticks[MAX_PLAYERS];
28 int playersAttached;
29 size_t joysticksClaimed[MAX_PLAYERS];
30#if SDL_VERSION_ATLEAST(2, 0, 0)
31 SDL_Haptic** haptic;
32 int screensaverSuspendDepth;
33 bool screensaverSuspendable;
34#endif
35};
36
37struct GBASDLPlayer {
38 size_t playerId;
39 struct GBAInputMap* bindings;
40 SDL_Joystick* joystick;
41 size_t joystickIndex;
42#if SDL_VERSION_ATLEAST(2, 0, 0)
43 SDL_Window* window;
44 int fullscreen;
45 int windowUpdated;
46 SDL_Haptic* haptic;
47
48 struct GBASDLRumble {
49 struct GBARumble d;
50 struct GBASDLPlayer* p;
51 } rumble;
52#endif
53
54 struct GBASDLRotation {
55 struct GBARotationSource d;
56 struct GBASDLPlayer* p;
57
58 // Tilt
59 int axisX;
60 int axisY;
61
62 // Gyro
63 int gyroX;
64 int gyroY;
65 float gyroSensitivity;
66 struct CircleBuffer zHistory;
67 int oldX;
68 int oldY;
69 float zDelta;
70 } rotation;
71};
72
73bool GBASDLInitEvents(struct GBASDLEvents*);
74void GBASDLDeinitEvents(struct GBASDLEvents*);
75
76bool GBASDLAttachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*);
77void GBASDLDetachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*);
78void GBASDLEventsLoadConfig(struct GBASDLEvents*, const struct Configuration*);
79void GBASDLPlayerChangeJoystick(struct GBASDLEvents*, struct GBASDLPlayer*, size_t index);
80
81void GBASDLInitBindings(struct GBAInputMap* inputMap);
82void GBASDLPlayerLoadConfig(struct GBASDLPlayer*, const struct Configuration*);
83void GBASDLPlayerSaveConfig(const struct GBASDLPlayer*, struct Configuration*);
84
85void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const union SDL_Event* event);
86
87#if SDL_VERSION_ATLEAST(2, 0, 0)
88void GBASDLSuspendScreensaver(struct GBASDLEvents*);
89void GBASDLResumeScreensaver(struct GBASDLEvents*);
90void GBASDLSetScreensaverSuspendable(struct GBASDLEvents*, bool suspendable);
91#endif
92
93#endif