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#include "util/vector.h"
12
13#include "gba/supervisor/thread.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 GBAVideoSoftwareRenderer;
23struct Configuration;
24
25struct SDL_JoystickCombo {
26 size_t index;
27 SDL_Joystick* joystick;
28#if SDL_VERSION_ATLEAST(2, 0, 0)
29 SDL_Haptic* haptic;
30 SDL_JoystickID id;
31#else
32 int id;
33#endif
34};
35
36DECLARE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo);
37
38struct GBASDLPlayer;
39
40struct GBASDLEvents {
41 struct SDL_JoystickList joysticks;
42 const char* preferredJoysticks[MAX_PLAYERS];
43 int playersAttached;
44 struct GBASDLPlayer* players[MAX_PLAYERS];
45#if SDL_VERSION_ATLEAST(2, 0, 0)
46 int screensaverSuspendDepth;
47 bool screensaverSuspendable;
48#endif
49};
50
51struct GBASDLPlayer {
52 size_t playerId;
53 struct GBAInputMap* bindings;
54 struct SDL_JoystickCombo* joystick;
55#if SDL_VERSION_ATLEAST(2, 0, 0)
56 SDL_Window* window;
57 int fullscreen;
58 int windowUpdated;
59
60 struct GBASDLRumble {
61 struct GBARumble d;
62 struct GBASDLPlayer* p;
63
64 int level;
65 struct CircleBuffer history;
66 } rumble;
67#endif
68
69 struct GBASDLRotation {
70 struct GBARotationSource d;
71 struct GBASDLPlayer* p;
72
73 // Tilt
74 int axisX;
75 int axisY;
76
77 // Gyro
78 int gyroX;
79 int gyroY;
80 float gyroSensitivity;
81 struct CircleBuffer zHistory;
82 int oldX;
83 int oldY;
84 float zDelta;
85 } rotation;
86};
87
88bool GBASDLInitEvents(struct GBASDLEvents*);
89void GBASDLDeinitEvents(struct GBASDLEvents*);
90
91bool GBASDLAttachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*);
92void GBASDLDetachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*);
93void GBASDLEventsLoadConfig(struct GBASDLEvents*, const struct Configuration*);
94void GBASDLPlayerChangeJoystick(struct GBASDLEvents*, struct GBASDLPlayer*, size_t index);
95void GBASDLUpdateJoysticks(struct GBASDLEvents* events);
96
97void GBASDLInitBindings(struct GBAInputMap* inputMap);
98void GBASDLPlayerLoadConfig(struct GBASDLPlayer*, const struct Configuration*);
99void GBASDLPlayerSaveConfig(const struct GBASDLPlayer*, struct Configuration*);
100
101void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const union SDL_Event* event);
102
103#if SDL_VERSION_ATLEAST(2, 0, 0)
104void GBASDLSuspendScreensaver(struct GBASDLEvents*);
105void GBASDLResumeScreensaver(struct GBASDLEvents*);
106void GBASDLSetScreensaverSuspendable(struct GBASDLEvents*, bool suspendable);
107#endif
108
109#endif