all repos — mgba @ 6248e44e47a8156555f5b9873a24093643a8a12f

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#endif
33};
34
35struct GBASDLPlayer {
36	size_t playerId;
37	struct GBAInputMap* bindings;
38	SDL_Joystick* joystick;
39	size_t joystickIndex;
40#if SDL_VERSION_ATLEAST(2, 0, 0)
41	SDL_Window* window;
42	int fullscreen;
43	int windowUpdated;
44	SDL_Haptic* haptic;
45
46	struct GBASDLRumble {
47		struct GBARumble d;
48		struct GBASDLPlayer* p;
49	} rumble;
50#endif
51
52	struct GBASDLRotation {
53		struct GBARotationSource d;
54		struct GBASDLPlayer* p;
55
56		// Tilt
57		int axisX;
58		int axisY;
59
60		// Gyro
61		int gyroX;
62		int gyroY;
63		float gyroSensitivity;
64		struct CircleBuffer zHistory;
65		int oldX;
66		int oldY;
67		float zDelta;
68	} rotation;
69};
70
71bool GBASDLInitEvents(struct GBASDLEvents*);
72void GBASDLDeinitEvents(struct GBASDLEvents*);
73
74bool GBASDLAttachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*);
75void GBASDLDetachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*);
76void GBASDLEventsLoadConfig(struct GBASDLEvents*, const struct Configuration*);
77void GBASDLPlayerChangeJoystick(struct GBASDLEvents*, struct GBASDLPlayer*, size_t index);
78
79void GBASDLInitBindings(struct GBAInputMap* inputMap);
80void GBASDLPlayerLoadConfig(struct GBASDLPlayer*, const struct Configuration*);
81void GBASDLPlayerSaveConfig(const struct GBASDLPlayer*, struct Configuration*);
82
83void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const union SDL_Event* event);
84
85#endif