all repos — mgba @ 13dfb144e88290b0e747ac51391f0882e57ce4b2

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#include "util/circle-buffer.h"
 11#include "util/vector.h"
 12
 13#include "gba/supervisor/thread.h"
 14
 15#include <SDL.h>
 16
 17#define SDL_BINDING_KEY 0x53444C4BU
 18#define SDL_BINDING_BUTTON 0x53444C42U
 19
 20#define MAX_PLAYERS 4
 21
 22struct GBAVideoSoftwareRenderer;
 23struct Configuration;
 24
 25struct SDL_JoystickCombo {
 26	SDL_JoystickID id;
 27	size_t index;
 28	SDL_Joystick* joystick;
 29#if SDL_VERSION_ATLEAST(2, 0, 0)
 30	SDL_Haptic* haptic;
 31#endif
 32};
 33
 34DECLARE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo);
 35
 36struct GBASDLPlayer;
 37
 38struct GBASDLEvents {
 39	struct SDL_JoystickList joysticks;
 40	const char* preferredJoysticks[MAX_PLAYERS];
 41	int playersAttached;
 42	struct GBASDLPlayer* players[MAX_PLAYERS];
 43#if SDL_VERSION_ATLEAST(2, 0, 0)
 44	int screensaverSuspendDepth;
 45	bool screensaverSuspendable;
 46#endif
 47};
 48
 49struct GBASDLPlayer {
 50	size_t playerId;
 51	struct GBAInputMap* bindings;
 52	struct SDL_JoystickCombo* joystick;
 53#if SDL_VERSION_ATLEAST(2, 0, 0)
 54	SDL_Window* window;
 55	int fullscreen;
 56	int windowUpdated;
 57
 58	struct GBASDLRumble {
 59		struct GBARumble d;
 60		struct GBASDLPlayer* p;
 61
 62		int level;
 63		struct CircleBuffer history;
 64	} rumble;
 65#endif
 66
 67	struct GBASDLRotation {
 68		struct GBARotationSource d;
 69		struct GBASDLPlayer* p;
 70
 71		// Tilt
 72		int axisX;
 73		int axisY;
 74
 75		// Gyro
 76		int gyroX;
 77		int gyroY;
 78		float gyroSensitivity;
 79		struct CircleBuffer zHistory;
 80		int oldX;
 81		int oldY;
 82		float zDelta;
 83	} rotation;
 84};
 85
 86bool GBASDLInitEvents(struct GBASDLEvents*);
 87void GBASDLDeinitEvents(struct GBASDLEvents*);
 88
 89bool GBASDLAttachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*);
 90void GBASDLDetachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*);
 91void GBASDLEventsLoadConfig(struct GBASDLEvents*, const struct Configuration*);
 92void GBASDLPlayerChangeJoystick(struct GBASDLEvents*, struct GBASDLPlayer*, size_t index);
 93void GBASDLUpdateJoysticks(struct GBASDLEvents* events);
 94
 95void GBASDLInitBindings(struct GBAInputMap* inputMap);
 96void GBASDLPlayerLoadConfig(struct GBASDLPlayer*, const struct Configuration*);
 97void GBASDLPlayerSaveConfig(const struct GBASDLPlayer*, struct Configuration*);
 98
 99void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const union SDL_Event* event);
100
101#if SDL_VERSION_ATLEAST(2, 0, 0)
102void GBASDLSuspendScreensaver(struct GBASDLEvents*);
103void GBASDLResumeScreensaver(struct GBASDLEvents*);
104void GBASDLSetScreensaverSuspendable(struct GBASDLEvents*, bool suspendable);
105#endif
106
107#endif