all repos — mgba @ 9085bbb8a4f0c40bbc4965bb2cf89343e940551a

mGBA Game Boy Advance Emulator

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
52		int level;
53		struct CircleBuffer history;
54	} rumble;
55#endif
56
57	struct GBASDLRotation {
58		struct GBARotationSource d;
59		struct GBASDLPlayer* p;
60
61		// Tilt
62		int axisX;
63		int axisY;
64
65		// Gyro
66		int gyroX;
67		int gyroY;
68		float gyroSensitivity;
69		struct CircleBuffer zHistory;
70		int oldX;
71		int oldY;
72		float zDelta;
73	} rotation;
74};
75
76bool GBASDLInitEvents(struct GBASDLEvents*);
77void GBASDLDeinitEvents(struct GBASDLEvents*);
78
79bool GBASDLAttachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*);
80void GBASDLDetachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*);
81void GBASDLEventsLoadConfig(struct GBASDLEvents*, const struct Configuration*);
82void GBASDLPlayerChangeJoystick(struct GBASDLEvents*, struct GBASDLPlayer*, size_t index);
83
84void GBASDLInitBindings(struct GBAInputMap* inputMap);
85void GBASDLPlayerLoadConfig(struct GBASDLPlayer*, const struct Configuration*);
86void GBASDLPlayerSaveConfig(const struct GBASDLPlayer*, struct Configuration*);
87
88void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const union SDL_Event* event);
89
90#if SDL_VERSION_ATLEAST(2, 0, 0)
91void GBASDLSuspendScreensaver(struct GBASDLEvents*);
92void GBASDLResumeScreensaver(struct GBASDLEvents*);
93void GBASDLSetScreensaverSuspendable(struct GBASDLEvents*, bool suspendable);
94#endif
95
96#endif