refs #317 Adding joystick support to input manager

This commit is contained in:
Roland Winklmeier
2014-07-31 01:15:41 +02:00
parent 78cab16a3d
commit 9283ecdd9d
3 changed files with 36 additions and 1 deletions

View File

@@ -23,6 +23,10 @@ blacksound {
blackinput {
LIBS += -lblackinput
win32 {
LIBS += -ldxguid -lole32 -ldinput8 -lUser32
}
}
blacksim {

View File

@@ -15,10 +15,13 @@ namespace BlackCore
CInputManager::CInputManager(QObject *parent) :
QObject(parent),
m_keyboard(IKeyboard::getInstance())
m_keyboard(IKeyboard::getInstance()),
m_joystick(IJoystick::getInstance())
{
connect(m_keyboard, &IKeyboard::keyUp, this, &CInputManager::ps_processKeyboardKeyUp);
connect(m_keyboard, &IKeyboard::keyDown, this, &CInputManager::ps_processKeyboardKeyDown);
connect(m_joystick, &IJoystick::buttonUp, this, &CInputManager::ps_processJoystickButtonUp);
connect(m_joystick, &IJoystick::buttonDown, this, &CInputManager::ps_processJoystickButtonDown);
}
CInputManager *CInputManager::getInstance()
@@ -62,6 +65,26 @@ namespace BlackCore
callFunctionsBy(hotkeyFunc, false);
}
void CInputManager::ps_processJoystickButtonDown(const CJoystickButton &button)
{
qDebug() << "Pressed Button" << button.getButtonIndex();
if (!m_hashJoystickKeyFunctions.contains(button)) return;
// Get configured hotkey function
CHotkeyFunction hotkeyFunc = m_hashJoystickKeyFunctions.value(button);
callFunctionsBy(hotkeyFunc, true);
}
void CInputManager::ps_processJoystickButtonUp(const CJoystickButton &button)
{
qDebug() << "Released Button" << button.getButtonIndex();
if (!m_hashJoystickKeyFunctions.contains(button)) return;
// Get configured hotkey function
CHotkeyFunction hotkeyFunc = m_hashJoystickKeyFunctions.value(button);
callFunctionsBy(hotkeyFunc, false);
}
void CInputManager::callFunctionsBy(const CHotkeyFunction &hotkeyFunction, bool isKeyDown)
{
if (!m_hashRegisteredFunctions.contains(hotkeyFunction)) return;

View File

@@ -7,7 +7,9 @@
#define BLACKCORE_INPUTMANAGER_H
#include "blackinput/keyboard.h"
#include "blackinput/joystick.h"
#include "blackmisc/hwkeyboardkeylist.h"
#include "blackmisc/hwjoystickbutton.h"
#include "blackmisc/hotkeyfunction.h"
#include "blackmisc/setkeyboardhotkeylist.h"
#include <QObject>
@@ -84,6 +86,10 @@ namespace BlackCore
void ps_processKeyboardKeyUp(const BlackMisc::Hardware::CKeyboardKey &);
void ps_processJoystickButtonDown(const BlackMisc::Hardware::CJoystickButton &button);
void ps_processJoystickButtonUp(const BlackMisc::Hardware::CJoystickButton &button);
private:
RegistrationHandle registerHotkeyFuncImpl(const BlackMisc::CHotkeyFunction &hotkeyFunction, QObject *receiver, std::function<void(bool)> function);
@@ -91,9 +97,11 @@ namespace BlackCore
static CInputManager *m_instance;
BlackInput::IKeyboard *m_keyboard = nullptr;
BlackInput::IJoystick *m_joystick = nullptr;
QHash<BlackMisc::CHotkeyFunction, std::function<void(bool)> > m_hashRegisteredFunctions;
QHash<BlackMisc::Hardware::CKeyboardKey, BlackMisc::CHotkeyFunction> m_hashKeyboardKeyFunctions;
QHash<BlackMisc::Hardware::CJoystickButton, BlackMisc::CHotkeyFunction> m_hashJoystickKeyFunctions;
};
}