Add joystickWithName for PrioVR

This commit is contained in:
Ryan Huffman 2014-10-10 18:03:08 -07:00
parent a24b5c24a9
commit 42479b1ae2
2 changed files with 20 additions and 20 deletions

View file

@ -78,6 +78,19 @@ const QObjectList JoystickScriptingInterface::getAllJoysticks() const {
return objectList;
}
Joystick* JoystickScriptingInterface::joystickWithName(const QString& name) {
#ifdef HAVE_SDL2
QMap<SDL_JoystickID, Joystick*>::iterator iter = _openJoysticks.begin();
while (iter != _openJoysticks.end()) {
if (iter.value()->getName() == name) {
return iter.value();
}
iter++;
}
#endif
return NULL;
}
void JoystickScriptingInterface::update() {
#ifdef HAVE_SDL2
if (_isInitialized) {
@ -111,15 +124,3 @@ void JoystickScriptingInterface::update() {
}
#endif
}
#ifdef HAVE_SDL2
SDL_Joystick* JoystickScriptingInterface::openSDLJoystickWithName(const QString& name) {
// we haven't opened a joystick with this name yet - enumerate our SDL devices and see if it exists
int joystickCount = SDL_NumJoysticks();
return NULL;
}
#endif

View file

@ -24,7 +24,7 @@
/// Handles joystick input through SDL.
class JoystickScriptingInterface : public QObject {
Q_OBJECT
#ifdef HAVE_SDL2
Q_PROPERTY(int AXIS_INVALID READ axisInvalid)
Q_PROPERTY(int AXIS_LEFT_X READ axisLeftX)
@ -59,16 +59,17 @@ class JoystickScriptingInterface : public QObject {
public:
static JoystickScriptingInterface& getInstance();
void update();
public slots:
Joystick* joystickWithName(const QString& name);
const QObjectList getAllJoysticks() const;
signals:
void joystickAdded(Joystick* joystick);
void joystickRemoved(Joystick* joystick);
private:
#ifdef HAVE_SDL2
int axisInvalid() const { return SDL_CONTROLLER_AXIS_INVALID; }
@ -100,13 +101,11 @@ private:
int buttonPressed() const { return SDL_PRESSED; }
int buttonRelease() const { return SDL_RELEASED; }
SDL_Joystick* openSDLJoystickWithName(const QString& name);
#endif
JoystickScriptingInterface();
~JoystickScriptingInterface();
#ifdef HAVE_SDL2
QMap<SDL_JoystickID, Joystick*> _openJoysticks;
#endif