1
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
8
#include "InputHandler.h"
9
#include "ConfigHandler.h"
10
#include "LogOutput.h"
11
#include "EventHandler.h"
13
Joystick* stick = NULL;
17
const bool useJoystick = configHandler->Get("JoystickEnabled", true);
20
const int err = SDL_InitSubSystem(SDL_INIT_JOYSTICK);
23
LogObject() << "Could not initialise joystick subsystem: " << SDL_GetError();
28
stick = new Joystick();
35
const int numSticks = SDL_NumJoysticks();
36
LogObject() << "Joysticks found: " << numSticks;
38
const int stickNum = configHandler->Get("JoystickUse", 0);
39
myStick = SDL_JoystickOpen(stickNum);
43
LogObject() << "Using joystick " << stickNum << ": " << SDL_JoystickName(stickNum);
44
inputCon = input.AddHandler(boost::bind(&Joystick::HandleEvent, this, _1));
48
LogObject() << "Joystick " << stickNum << " not found";
55
SDL_JoystickClose(myStick);
58
bool Joystick::HandleEvent(const SDL_Event& event)
61
case SDL_JOYAXISMOTION:
63
eventHandler.JoystickEvent("JoyAxis", event.jaxis.axis, event.jaxis.value);
66
case SDL_JOYHATMOTION:
68
eventHandler.JoystickEvent("JoyHat", event.jhat.hat, event.jhat.value);
71
case SDL_JOYBUTTONDOWN:
73
eventHandler.JoystickEvent("JoyButtonDown", event.jbutton.button, event.jbutton.state);
78
eventHandler.JoystickEvent("JoyButtonUp", event.jbutton.button, event.jbutton.state);