added getters/setters for Inputs and InputChannels

This commit is contained in:
Sam Gondelman 2015-06-09 10:20:36 -07:00
parent d3a4eec5c5
commit 0769593ca8
2 changed files with 33 additions and 14 deletions

View file

@ -46,32 +46,36 @@ QScriptValue inputToScriptValue(QScriptEngine* engine, const UserInputMapper::In
QScriptValue obj = engine->newObject(); QScriptValue obj = engine->newObject();
obj.setProperty("device", input.getDevice()); obj.setProperty("device", input.getDevice());
obj.setProperty("channel", input.getChannel()); obj.setProperty("channel", input.getChannel());
obj.setProperty("type", input._type); obj.setProperty("type", (unsigned short) input.getType());
obj.setProperty("id", input.getID()); obj.setProperty("id", input.getID());
return obj; return obj;
} }
void inputFromScriptValue(const QScriptValue& object, UserInputMapper::Input& input) { void inputFromScriptValue(const QScriptValue& object, UserInputMapper::Input& input) {
input._device = object.property("device").toUInt16(); input.setDevice(object.property("device").toUInt16());
input._channel = object.property("channel").toUInt16(); input.setChannel(object.property("channel").toUInt16());
input._type = object.property("type").toUInt16(); input.setType(object.property("type").toUInt16());
input._id = object.property("id").toInt32(); input.setID(object.property("id").toInt32());
} }
QScriptValue inputChannelToScriptValue(QScriptEngine* engine, const UserInputMapper::InputChannel& inputChannel) { QScriptValue inputChannelToScriptValue(QScriptEngine* engine, const UserInputMapper::InputChannel& inputChannel) {
QScriptValue obj = engine->newObject(); QScriptValue obj = engine->newObject();
obj.setProperty("input", inputToScriptValue(engine, inputChannel._input)); obj.setProperty("input", inputToScriptValue(engine, inputChannel.getInput()));
obj.setProperty("modifier", inputToScriptValue(engine, inputChannel._modifier)); obj.setProperty("modifier", inputToScriptValue(engine, inputChannel.getModifier()));
obj.setProperty("action", inputChannel._action); obj.setProperty("action", inputChannel.getAction());
obj.setProperty("scale", inputChannel._scale); obj.setProperty("scale", inputChannel.getScale());
return obj; return obj;
} }
void inputChannelFromScriptValue(const QScriptValue& object, UserInputMapper::InputChannel& inputChannel) { void inputChannelFromScriptValue(const QScriptValue& object, UserInputMapper::InputChannel& inputChannel) {
inputFromScriptValue(object.property("input"), inputChannel._input); UserInputMapper::Input input;
inputFromScriptValue(object.property("modifier"), inputChannel._modifier); UserInputMapper::Input modifier;
inputChannel._action = UserInputMapper::Action(object.property("action").toVariant().toInt()); inputFromScriptValue(object.property("input"), input);
inputChannel._scale = object.property("scale").toVariant().toFloat(); inputChannel.setInput(input);
inputFromScriptValue(object.property("modifier"), modifier);
inputChannel.setModifier(modifier);
inputChannel.setAction(UserInputMapper::Action(object.property("action").toVariant().toInt()));
inputChannel.setScale(object.property("scale").toVariant().toFloat());
} }
QScriptValue actionToScriptValue(QScriptEngine* engine, const UserInputMapper::Action& action) { QScriptValue actionToScriptValue(QScriptEngine* engine, const UserInputMapper::Action& action) {

View file

@ -52,8 +52,13 @@ public:
uint16 getDevice() const { return _device; } uint16 getDevice() const { return _device; }
uint16 getChannel() const { return _channel; } uint16 getChannel() const { return _channel; }
uint32 getID() const { return _id; } uint32 getID() const { return _id; }
ChannelType getType() const { return (ChannelType) _type; } ChannelType getType() const { return (ChannelType) _type; }
void setDevice(uint16 device) { _device = device; }
void setChannel(uint16 channel) { _channel = channel; }
void setType(uint16 type) { _type = type; }
void setID(uint32 ID) { _id = ID; }
bool isButton() const { return getType() == ChannelType::BUTTON; } bool isButton() const { return getType() == ChannelType::BUTTON; }
bool isAxis() const { return getType() == ChannelType::AXIS; } bool isAxis() const { return getType() == ChannelType::AXIS; }
bool isJoint() const { return getType() == ChannelType::JOINT; } bool isJoint() const { return getType() == ChannelType::JOINT; }
@ -157,6 +162,16 @@ public:
Input _modifier = Input(); // make it invalid by default, meaning no modifier Input _modifier = Input(); // make it invalid by default, meaning no modifier
Action _action = LONGITUDINAL_BACKWARD; Action _action = LONGITUDINAL_BACKWARD;
float _scale = 0.0f; float _scale = 0.0f;
Input getInput() const { return _input; }
Input getModifier() const { return _modifier; }
Action getAction() const { return _action; }
float getScale() const { return _scale; }
void setInput(Input input) { _input = input; }
void setModifier(Input modifier) { _modifier = modifier; }
void setAction(Action action) { _action = action; }
void setScale(float scale) { _scale = scale; }
InputChannel() {} InputChannel() {}
InputChannel(const Input& input, const Input& modifier, Action action, float scale = 1.0f) : InputChannel(const Input& input, const Input& modifier, Action action, float scale = 1.0f) :