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
11#include "gba/supervisor/thread.h"
12
13#include <SDL.h>
14
15#define SDL_BINDING_KEY 0x53444C4BU
16#define SDL_BINDING_BUTTON 0x53444C42U
17
18#define MAX_PLAYERS 4
19
20struct GBAVideoSoftwareRenderer;
21struct Configuration;
22
23struct GBASDLEvents {
24 SDL_Joystick** joysticks;
25 size_t nJoysticks;
26 const char* preferredJoysticks[MAX_PLAYERS];
27 int playersAttached;
28 size_t joysticksClaimed[MAX_PLAYERS];
29#if SDL_VERSION_ATLEAST(2, 0, 0)
30 SDL_Haptic** haptic;
31#endif
32};
33
34struct GBASDLPlayer {
35 size_t playerId;
36 struct GBAInputMap* bindings;
37 SDL_Joystick* joystick;
38 size_t joystickIndex;
39#if SDL_VERSION_ATLEAST(2, 0, 0)
40 SDL_Window* window;
41 int fullscreen;
42 int windowUpdated;
43 SDL_Haptic* haptic;
44
45 struct GBASDLRumble {
46 struct GBARumble d;
47 struct GBASDLPlayer* p;
48 } rumble;
49#endif
50};
51
52bool GBASDLInitEvents(struct GBASDLEvents*);
53void GBASDLDeinitEvents(struct GBASDLEvents*);
54
55bool GBASDLAttachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*);
56void GBASDLEventsLoadConfig(struct GBASDLEvents*, const struct Configuration*);
57void GBASDLPlayerChangeJoystick(struct GBASDLEvents*, struct GBASDLPlayer*, size_t index);
58
59void GBASDLInitBindings(struct GBAInputMap* inputMap);
60void GBASDLPlayerLoadConfig(struct GBASDLPlayer*, const struct Configuration*);
61
62void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const union SDL_Event* event);
63
64#endif