all repos — mgba @ 723b91dfe346c9f59ddd37e5e2074699b791907f

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