From fa80d2d897a0dc866a94b5105a54f8c55bc46774 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Thu, 31 Jul 2014 01:14:56 +0200 Subject: [PATCH] refs #317 IJoystick interface definition --- src/blackinput/joystick.cpp | 47 ++++++++++++++++++++++++ src/blackinput/joystick.h | 72 +++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 src/blackinput/joystick.cpp create mode 100644 src/blackinput/joystick.h diff --git a/src/blackinput/joystick.cpp b/src/blackinput/joystick.cpp new file mode 100644 index 000000000..75237900c --- /dev/null +++ b/src/blackinput/joystick.cpp @@ -0,0 +1,47 @@ +/* Copyright (C) 2014 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "joystick.h" + +#if defined(Q_OS_WIN) + #include "win/joystick_windows.h" +#elif defined(Q_OS_LINUX) + #include "linux/joystick_linux.h" +#elif defined(Q_OS_OSX) + #include "osx/joystick_mac.h" +#else + #error "Platform is not supported!" +#endif + +namespace BlackInput +{ + IJoystick *IJoystick::m_instance = nullptr; + + IJoystick::IJoystick(QObject *parent) : + QObject(parent) + { + } + + IJoystick *IJoystick::getInstance() + { + if (!m_instance) + { +#if defined(Q_OS_WIN) + m_instance = new CJoystickWindows; +#elif defined(Q_OS_LINUX) + m_instance = new CJoystickLinux; +#elif defined(Q_OS_OSX) + m_instance = new CJoystickMac; +#endif + Q_ASSERT_X(m_instance, "IJoystick::getInstance", "Pointer to IJoystick is nullptr!"); + } + return m_instance; + } + +} // BlackInput diff --git a/src/blackinput/joystick.h b/src/blackinput/joystick.h new file mode 100644 index 000000000..56076e82b --- /dev/null +++ b/src/blackinput/joystick.h @@ -0,0 +1,72 @@ +/* Copyright (C) 2014 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKINPUT_JOYSTICK_H +#define BLACKINPUT_JOYSTICK_H + +#include "blackmisc/hwjoystickbutton.h" +#include +#include +#include +#include + +namespace BlackInput +{ + /*! + * \brief Abstract interface for native joystick handling. + * \todo Add implementation for Linux and OSX. + */ + class IJoystick : public QObject + { + Q_OBJECT + + public: + + //! Operation mode + enum Mode + { + ModeNominal, + ModeCapture + }; + + //! Constructor + IJoystick(QObject *parent = nullptr); + + //! Destructor + virtual ~IJoystick() {} + + //! Start joystick button selection for settings configuration + virtual void startCapture() = 0; + + //! Simulating press/release of a joystick button + virtual void triggerButton(const BlackMisc::Hardware::CJoystickButton button, bool isPressed) = 0; + + //! Creates a native joystick handler object + static IJoystick *getInstance(); + + signals: + + //! User has selected a joystick button + void buttonSelectionFinished(const BlackMisc::Hardware::CJoystickButton &button); + + //! Button down + void buttonDown(const BlackMisc::Hardware::CJoystickButton &); + + //! Button up + void buttonUp(const BlackMisc::Hardware::CJoystickButton &); + + private: + + static IJoystick *m_instance; + }; +} + +#endif // BLACKINPUT_JOYSTICK_H