all repos — mgba @ 2da3d3e6ba282d437c69a8d80b0a2e0f46214a39

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