From 9283ecdd9d1d9c8f9b62de5adab389593b976360 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Thu, 31 Jul 2014 01:15:41 +0200 Subject: [PATCH] refs #317 Adding joystick support to input manager --- libraries.pri | 4 ++++ src/blackcore/input_manager.cpp | 25 ++++++++++++++++++++++++- src/blackcore/input_manager.h | 8 ++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/libraries.pri b/libraries.pri index c43bf8afe..4a7496c93 100644 --- a/libraries.pri +++ b/libraries.pri @@ -23,6 +23,10 @@ blacksound { blackinput { LIBS += -lblackinput + + win32 { + LIBS += -ldxguid -lole32 -ldinput8 -lUser32 + } } blacksim { diff --git a/src/blackcore/input_manager.cpp b/src/blackcore/input_manager.cpp index 47e5301a6..bfe26321d 100644 --- a/src/blackcore/input_manager.cpp +++ b/src/blackcore/input_manager.cpp @@ -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; diff --git a/src/blackcore/input_manager.h b/src/blackcore/input_manager.h index 3522506bf..fe9455b75 100644 --- a/src/blackcore/input_manager.h +++ b/src/blackcore/input_manager.h @@ -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 @@ -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 function); @@ -91,9 +97,11 @@ namespace BlackCore static CInputManager *m_instance; BlackInput::IKeyboard *m_keyboard = nullptr; + BlackInput::IJoystick *m_joystick = nullptr; QHash > m_hashRegisteredFunctions; QHash m_hashKeyboardKeyFunctions; + QHash m_hashJoystickKeyFunctions; }; }