diff --git a/libraries/controllers/src/controllers/StateController.cpp b/libraries/controllers/src/controllers/StateController.cpp new file mode 100644 index 0000000000..93985fe8e3 --- /dev/null +++ b/libraries/controllers/src/controllers/StateController.cpp @@ -0,0 +1,61 @@ +// +// StateController.cpp +// controllers/src/controllers +// +// Created by Sam Gateau on 2015-10-27. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "StateController.h" + +#include + +#include "DeviceProxy.h" +#include "UserInputMapper.h" +#include "impl/Endpoint.h" + +namespace controller { + +StateController::StateController() : InputDevice("Application") { +} + +StateController::~StateController() { +} + +void StateController::update(float deltaTime, bool jointsCaptured) {} + +void StateController::focusOutEvent() {} + +void StateController::addInputVariant(QString name, ReadLambda& lambda) { + namedReadLambdas.push_back(NamedReadLambda(name, lambda)); +} +void StateController::buildDeviceProxy(DeviceProxy::Pointer proxy) { + proxy->_name = _name; + proxy->getButton = [this] (const Input& input, int timestamp) -> bool { return getButton(input.getChannel()); }; + proxy->getAxis = [this] (const Input& input, int timestamp) -> float { return getAxis(input.getChannel()); }; + proxy->getAvailabeInputs = [this] () -> QVector { + + + QVector availableInputs; + + int i = 0; + for (auto pair : namedReadLambdas) { + availableInputs.push_back(Input::NamedPair(Input(_deviceID, i, ChannelType::BUTTON), pair.first)); + i++; + } + return availableInputs; + }; + proxy->createEndpoint = [this] (const Input& input) -> Endpoint::Pointer { + if (input.getChannel() < namedReadLambdas.size()) { + return std::make_shared(namedReadLambdas[input.getChannel()].second); + } + + return Endpoint::Pointer(); + }; +} + + +} diff --git a/libraries/controllers/src/controllers/StateController.h b/libraries/controllers/src/controllers/StateController.h new file mode 100644 index 0000000000..f17b31f64b --- /dev/null +++ b/libraries/controllers/src/controllers/StateController.h @@ -0,0 +1,49 @@ +// +// StateController.h +// controllers/src/controllers +// +// Created by Sam Gateau on 2015-10-27. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_StateController_h +#define hifi_StateController_h + +#include +#include + +#include "InputDevice.h" + +namespace controller { + +class StateController : public QObject, public InputDevice { + Q_OBJECT + Q_PROPERTY(QString name READ getName) + +public: + const QString& getName() const { return _name; } + + // Device functions + virtual void buildDeviceProxy(DeviceProxy::Pointer proxy) override; + virtual QString getDefaultMappingConfig() override { return QString(); } + virtual void update(float deltaTime, bool jointsCaptured) override; + virtual void focusOutEvent() override; + + StateController(); + virtual ~StateController(); + + using ReadLambda = std::function; + using NamedReadLambda = QPair; + + void addInputVariant(QString name, ReadLambda& lambda); + + QVector namedReadLambdas; + QVector availableInputs; +}; + +} + +#endif // hifi_StateController_h \ No newline at end of file