all repos — mgba @ ff637c84d1f229b0891e0d7f9a40ad5c7a8b12f0

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