all repos — mgba @ 60577e83948647d36a2e6a8b4ec8f8556df3f72f

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 <mgba-util/common.h>
 10
 11CXX_GUARD_START
 12
 13#include <mgba/core/interface.h>
 14#include <mgba/core/log.h>
 15#include <mgba-util/circle-buffer.h>
 16#include <mgba-util/vector.h>
 17
 18#include <SDL.h>
 19// Altivec sometimes defines this
 20#ifdef vector
 21#undef vector
 22#endif
 23#ifdef bool
 24#undef bool
 25#define bool _Bool
 26#endif
 27
 28mLOG_DECLARE_CATEGORY(SDL_EVENTS);
 29
 30#define SDL_BINDING_KEY 0x53444C4BU
 31#define SDL_BINDING_BUTTON 0x53444C42U
 32
 33#define MAX_PLAYERS 4
 34
 35struct Configuration;
 36
 37struct SDL_JoystickCombo {
 38	size_t index;
 39	SDL_Joystick* joystick;
 40#if SDL_VERSION_ATLEAST(2, 0, 0)
 41	SDL_Haptic* haptic;
 42	SDL_JoystickID id;
 43#else
 44	int id;
 45#endif
 46};
 47
 48DECLARE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo);
 49
 50struct mSDLPlayer;
 51struct mSDLEvents {
 52	struct SDL_JoystickList joysticks;
 53	const char* preferredJoysticks[MAX_PLAYERS];
 54	int playersAttached;
 55	struct mSDLPlayer* players[MAX_PLAYERS];
 56#if SDL_VERSION_ATLEAST(2, 0, 0)
 57	int screensaverSuspendDepth;
 58	bool screensaverSuspendable;
 59#endif
 60};
 61
 62struct mSDLPlayer {
 63	size_t playerId;
 64	struct mInputMap* bindings;
 65	struct SDL_JoystickCombo* joystick;
 66#if SDL_VERSION_ATLEAST(2, 0, 0)
 67	SDL_Window* window;
 68	int fullscreen;
 69	int windowUpdated;
 70
 71	struct mSDLRumble {
 72		struct mRumble d;
 73		struct mSDLPlayer* p;
 74
 75		int level;
 76		float activeLevel;
 77		struct CircleBuffer history;
 78	} rumble;
 79#endif
 80
 81	struct mSDLRotation {
 82		struct mRotationSource d;
 83		struct mSDLPlayer* p;
 84
 85		// Tilt
 86		int axisX;
 87		int axisY;
 88
 89		// Gyro
 90		int gyroX;
 91		int gyroY;
 92		float gyroSensitivity;
 93		struct CircleBuffer zHistory;
 94		int oldX;
 95		int oldY;
 96		float zDelta;
 97	} rotation;
 98};
 99
100bool mSDLInitEvents(struct mSDLEvents*);
101void mSDLDeinitEvents(struct mSDLEvents*);
102
103bool mSDLAttachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
104void mSDLDetachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
105void mSDLEventsLoadConfig(struct mSDLEvents*, const struct Configuration*);
106void mSDLPlayerChangeJoystick(struct mSDLEvents*, struct mSDLPlayer*, size_t index);
107void mSDLUpdateJoysticks(struct mSDLEvents* events, const struct Configuration*);
108
109void mSDLPlayerLoadConfig(struct mSDLPlayer*, const struct Configuration*);
110void mSDLPlayerSaveConfig(const struct mSDLPlayer*, struct Configuration*);
111
112void mSDLInitBindingsGBA(struct mInputMap* inputMap);
113
114struct mCoreThread;
115void mSDLHandleEvent(struct mCoreThread* context, struct mSDLPlayer* sdlContext, const union SDL_Event* event);
116
117#if SDL_VERSION_ATLEAST(2, 0, 0)
118void mSDLSuspendScreensaver(struct mSDLEvents*);
119void mSDLResumeScreensaver(struct mSDLEvents*);
120void mSDLSetScreensaverSuspendable(struct mSDLEvents*, bool suspendable);
121#endif
122
123CXX_GUARD_END
124
125#endif