Showing the changes to interface/src/scripting/ControllerScriptingInterface.cpp (1 of 8 files). Show all
Unified · Split
| @@ -28,6 +28,90 @@ ControllerScriptingInterface::ControllerScriptingInterface() : · 27 unmodified lines | |||
| 28 | { | 28 | { |
| 29 | 29 | ||
| 30 | } | 30 | } |
| 31 | static int actionMetaTypeId = qRegisterMetaType<UserInputMapper::Action>(); | ||
| 32 | static int inputChannelMetaTypeId = qRegisterMetaType<UserInputMapper::InputChannel>(); | ||
| 33 | static int inputMetaTypeId = qRegisterMetaType<UserInputMapper::Input>(); | ||
| 34 | static int inputPairMetaTypeId = qRegisterMetaType<UserInputMapper::InputPair>(); | ||
| 35 | |||
| 36 | QScriptValue inputToScriptValue(QScriptEngine* engine, const UserInputMapper::Input& input); | ||
| 37 | void inputFromScriptValue(const QScriptValue& object, UserInputMapper::Input& input); | ||
| 38 | QScriptValue inputChannelToScriptValue(QScriptEngine* engine, const UserInputMapper::InputChannel& inputChannel); | ||
| 39 | void inputChannelFromScriptValue(const QScriptValue& object, UserInputMapper::InputChannel& inputChannel); | ||
| 40 | QScriptValue actionToScriptValue(QScriptEngine* engine, const UserInputMapper::Action& action); | ||
| 41 | void actionFromScriptValue(const QScriptValue& object, UserInputMapper::Action& action); | ||
| 42 | QScriptValue inputPairToScriptValue(QScriptEngine* engine, const UserInputMapper::InputPair& inputPair); | ||
| 43 | void inputPairFromScriptValue(const QScriptValue& object, UserInputMapper::InputPair& inputPair); | ||
| 44 | |||
| 45 | QScriptValue inputToScriptValue(QScriptEngine* engine, const UserInputMapper::Input& input) { | ||
| 46 | QScriptValue obj = engine->newObject(); | ||
| 47 | obj.setProperty("device", input.getDevice()); | ||
| 48 | obj.setProperty("channel", input.getChannel()); | ||
| 49 | obj.setProperty("type", input._type); | ||
| 50 | obj.setProperty("id", input.getID()); | ||
| 51 | return obj; | ||
| 52 | } | ||
| 53 | |||
| 54 | void inputFromScriptValue(const QScriptValue& object, UserInputMapper::Input& input) { | ||
| 55 | input._device = object.property("device").toUInt16(); | ||
| 56 | input._channel = object.property("channel").toUInt16(); | ||
| 57 | input._type = object.property("type").toUInt16(); | ||
| 58 | input._id = object.property("id").toInt32(); | ||
| 59 | } | ||
| 60 | |||
| 61 | QScriptValue inputChannelToScriptValue(QScriptEngine* engine, const UserInputMapper::InputChannel& inputChannel) { | ||
| 62 | QScriptValue obj = engine->newObject(); | ||
| 63 | obj.setProperty("input", inputToScriptValue(engine, inputChannel._input)); | ||
| 64 | obj.setProperty("modifier", inputToScriptValue(engine, inputChannel._modifier)); | ||
| 65 | obj.setProperty("action", inputChannel._action); | ||
| 66 | obj.setProperty("scale", inputChannel._scale); | ||
| 67 | return obj; | ||
| 68 | } | ||
| 69 | |||
| 70 | void inputChannelFromScriptValue(const QScriptValue& object, UserInputMapper::InputChannel& inputChannel) { | ||
| 71 | inputFromScriptValue(object.property("input"), inputChannel._input); | ||
| 72 | inputFromScriptValue(object.property("modifier"), inputChannel._modifier); | ||
| 73 | inputChannel._action = UserInputMapper::Action(object.property("action").toVariant().toInt()); | ||
| 74 | inputChannel._scale = object.property("scale").toVariant().toFloat(); | ||
| 75 | } | ||
| 76 | |||
| 77 | QScriptValue actionToScriptValue(QScriptEngine* engine, const UserInputMapper::Action& action) { | ||
| 78 | QScriptValue obj = engine->newObject(); | ||
| 79 | QVector<UserInputMapper::InputChannel> inputChannels = Application::getUserInputMapper()->getInputChannelsForAction(action); | ||
| 80 | QScriptValue _inputChannels = engine->newArray(inputChannels.size()); | ||
| 81 | for (int i = 0; i < inputChannels.size(); i++) { | ||
| 82 | _inputChannels.setProperty(i, inputChannelToScriptValue(engine, inputChannels[i])); | ||
| 83 | } | ||
| 84 | obj.setProperty("action", (int) action); | ||
| 85 | obj.setProperty("actionName", Application::getUserInputMapper()->getActionName(action)); | ||
| 86 | obj.setProperty("inputChannels", _inputChannels); | ||
| 87 | return obj; | ||
| 88 | } | ||
| 89 | |||
| 90 | void actionFromScriptValue(const QScriptValue& object, UserInputMapper::Action& action) { | ||
| 91 | action = UserInputMapper::Action(object.property("action").toVariant().toInt()); | ||
| 92 | } | ||
| 93 | |||
| 94 | QScriptValue inputPairToScriptValue(QScriptEngine* engine, const UserInputMapper::InputPair& inputPair) { | ||
| 95 | QScriptValue obj = engine->newObject(); | ||
| 96 | obj.setProperty("input", inputToScriptValue(engine, inputPair.first)); | ||
| 97 | obj.setProperty("inputName", inputPair.second); | ||
| 98 | return obj; | ||
| 99 | } | ||
| 100 | |||
| 101 | void inputPairFromScriptValue(const QScriptValue& object, UserInputMapper::InputPair& inputPair) { | ||
| 102 | inputFromScriptValue(object.property("input"), inputPair.first); | ||
| 103 | inputPair.second = QString(object.property("inputName").toVariant().toString()); | ||
| 104 | } | ||
| 105 | |||
| 106 | void ControllerScriptingInterface::registerControllerTypes(QScriptEngine* engine) { | ||
| 107 | qScriptRegisterSequenceMetaType<QVector<UserInputMapper::Action> >(engine); | ||
| 108 | qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputChannel> >(engine); | ||
| 109 | qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputPair> >(engine); | ||
| 110 | qScriptRegisterMetaType(engine, actionToScriptValue, actionFromScriptValue); | ||
| 111 | qScriptRegisterMetaType(engine, inputChannelToScriptValue, inputChannelFromScriptValue); | ||
| 112 | qScriptRegisterMetaType(engine, inputToScriptValue, inputFromScriptValue); | ||
| 113 | qScriptRegisterMetaType(engine, inputPairToScriptValue, inputPairFromScriptValue); | ||
| 114 | } | ||
| 31 | 115 | ||
| 32 | void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) { | 116 | void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) { |
| 33 | if (event->type() == HFActionEvent::startType()) { | 117 | if (event->type() == HFActionEvent::startType()) { |
| @@ -337,6 +421,37 @@ void ControllerScriptingInterface::updateInputControllers() { · 303 unmodified lines | |||
| 337 | } | 421 | } |
| 338 | } | 422 | } |
| 339 | 423 | ||
| 424 | QVector<UserInputMapper::Action> ControllerScriptingInterface::getAllActions() { | ||
| 425 | return Application::getUserInputMapper()->getAllActions(); | ||
| 426 | } | ||
| 427 | |||
| 428 | QVector<UserInputMapper::InputChannel> ControllerScriptingInterface::getInputChannelsForAction(UserInputMapper::Action action) { | ||
| 429 | return Application::getUserInputMapper()->getInputChannelsForAction(action); | ||
| 430 | } | ||
| 431 | |||
| 432 | QString ControllerScriptingInterface::getDeviceName(unsigned int device) { | ||
| 433 | return Application::getUserInputMapper()->getDeviceName((unsigned short) device); | ||
| 434 | } | ||
| 435 | |||
| 436 | QVector<UserInputMapper::InputChannel> ControllerScriptingInterface::getAllInputsForDevice(unsigned int device) { | ||
| 437 | return Application::getUserInputMapper()->getAllInputsForDevice(device); | ||
| 438 | } | ||
| 439 | |||
| 440 | bool ControllerScriptingInterface::addInputChannel(UserInputMapper::InputChannel inputChannel) { | ||
| 441 | return Application::getUserInputMapper()->addInputChannel(inputChannel._action, inputChannel._input, inputChannel._modifier, inputChannel._scale); | ||
| 442 | } | ||
| 443 | |||
| 444 | bool ControllerScriptingInterface::removeInputChannel(UserInputMapper::InputChannel inputChannel) { | ||
| 445 | return Application::getUserInputMapper()->removeInputChannel(inputChannel); | ||
| 446 | } | ||
| 447 | |||
| 448 | QVector<UserInputMapper::InputPair> ControllerScriptingInterface::getAvailableInputs(unsigned int device) { | ||
| 449 | return Application::getUserInputMapper()->getAvailableInputs((unsigned short) device); | ||
| 450 | } | ||
| 451 | |||
| 452 | void ControllerScriptingInterface::resetAllDeviceBindings() { | ||
| 453 | Application::getUserInputMapper()->resetAllDeviceBindings(); | ||
| 454 | } | ||
| 340 | 455 | ||
| 341 | InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) : | 456 | InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) : |
| 342 | AbstractInputController(), | 457 | AbstractInputController(), |
| @@ -373,4 +488,4 @@ const unsigned int INPUTCONTROLLER_KEY_DEVICE_MASK = 16; · 30 unmodified lines | |||
| 373 | 488 | ||
| 374 | InputController::Key InputController::getKey() const { | 489 | InputController::Key InputController::getKey() const { |
| 375 | return (((_deviceTrackerId & INPUTCONTROLLER_KEY_DEVICE_MASK) << INPUTCONTROLLER_KEY_DEVICE_OFFSET) | _subTrackerId); | 490 | return (((_deviceTrackerId & INPUTCONTROLLER_KEY_DEVICE_MASK) << INPUTCONTROLLER_KEY_DEVICE_OFFSET) | _subTrackerId); |
| 376 | } | 491 | } |