History

exposed input key bindings to js to enable key remapping

Sam Gondelman committed 11 years ago

Commit 984d4491 parent a12fd5c8 files · +289 −16Browse files

Showing the changes to interface/src/ui/UserInputMapper.cpp (1 of 8 files). Show all

Unified · Split

interface/src/ui/UserInputMapper.cpp+95−1
@@ -13,7 +13,15 @@ · 12 unmodified lines
1313
1414
1515 // UserInputMapper Class
16+
17+// Default contruct allocate the poutput size with the current hardcoded action channels
18+UserInputMapper::UserInputMapper() {
19+ assignDefaulActionScales();
20+ createActionNames();
21+}
22+
1623 bool UserInputMapper::registerDevice(uint16 deviceID, const DeviceProxy::Pointer& proxy){
24+ proxy->_name += " (" + QString::number(deviceID) + ")";
1725 _registeredDevices[deviceID] = proxy;
1826 return true;
1927 }
@@ -27,6 +35,12 @@ UserInputMapper::DeviceProxy::Pointer UserInputMapper::getDeviceProxy(const Inpu · 7 unmodified lines
2735 }
2836 }
2937
38+void UserInputMapper::resetAllDeviceBindings() {
39+ for (auto device : _registeredDevices) {
40+ device.second->resetDeviceBindings();
41+ }
42+}
43+
3044 bool UserInputMapper::addInputChannel(Action action, const Input& input, float scale) {
3145 return addInputChannel(action, input, Input(), scale);
3246 }
@@ -37,7 +51,7 @@ bool UserInputMapper::addInputChannel(Action action, const Input& input, const I · 4 unmodified lines
3751 qDebug() << "UserInputMapper::addInputChannel: The input comes from a device #" << input.getDevice() << "is unknown. no inputChannel mapped.";
3852 return false;
3953 }
40−
54+
4155 auto inputChannel = InputChannel(input, modifier, action, scale);
4256
4357 // Insert or replace the input to modifiers
@@ -61,6 +75,37 @@ int UserInputMapper::addInputChannels(const InputChannels& channels) { · 17 unmodified lines
6175 return nbAdded;
6276 }
6377
78+bool UserInputMapper::removeInputChannel(InputChannel inputChannel) {
79+ // Remove from Input to Modifiers map
80+ if (inputChannel.hasModifier()) {
81+ _inputToModifiersMap.erase(inputChannel._input.getID());
82+ }
83+
84+ // Remove from Action to Inputs map
85+ std::pair<ActionToInputsMap::iterator, ActionToInputsMap::iterator> ret;
86+ ret = _actionToInputsMap.equal_range(inputChannel._action);
87+ for (ActionToInputsMap::iterator it=ret.first; it!=ret.second; ++it) {
88+ if (it->second == inputChannel) {
89+ _actionToInputsMap.erase(it);
90+ return true;
91+ }
92+ }
93+
94+ return false;
95+}
96+
97+void UserInputMapper::removeAllInputChannels() {
98+ _inputToModifiersMap.clear();
99+ _actionToInputsMap.clear();
100+}
101+
102+void UserInputMapper::removeAllInputChannelsForDevice(uint16 device) {
103+ QVector<InputChannel> channels = getAllInputsForDevice(device);
104+ for (auto& channel : channels) {
105+ removeInputChannel(channel);
106+ }
107+}
108+
64109 int UserInputMapper::getInputChannels(InputChannels& channels) const {
65110 for (auto& channel : _actionToInputsMap) {
66111 channels.push_back(channel.second);
@@ -69,6 +114,20 @@ int UserInputMapper::getInputChannels(InputChannels& channels) const { · 2 unmodified lines
69114 return _actionToInputsMap.size();
70115 }
71116
117+QVector<UserInputMapper::InputChannel> UserInputMapper::getAllInputsForDevice(uint16 device) {
118+ InputChannels allChannels;
119+ getInputChannels(allChannels);
120+
121+ QVector<InputChannel> channels;
122+ for (InputChannel inputChannel : allChannels) {
123+ if (inputChannel._input._device == device) {
124+ channels.push_back(inputChannel);
125+ }
126+ }
127+
128+ return channels;
129+}
130+
72131 void UserInputMapper::update(float deltaTime) {
73132
74133 // Reset the axis state for next loop
@@ -130,6 +189,24 @@ void UserInputMapper::update(float deltaTime) { · 55 unmodified lines
130189 }
131190 }
132191
192+QVector<UserInputMapper::Action> UserInputMapper::getAllActions() {
193+ QVector<Action> actions;
194+ for (auto i = 0; i < NUM_ACTIONS; i++) {
195+ actions.append(Action(i));
196+ }
197+ return actions;
198+}
199+
200+QVector<UserInputMapper::InputChannel> UserInputMapper::getInputChannelsForAction(UserInputMapper::Action action) {
201+ QVector<InputChannel> inputChannels;
202+ std::pair <ActionToInputsMap::iterator, ActionToInputsMap::iterator> ret;
203+ ret = _actionToInputsMap.equal_range(action);
204+ for (ActionToInputsMap::iterator it=ret.first; it!=ret.second; ++it) {
205+ inputChannels.append(it->second);
206+ }
207+ return inputChannels;
208+}
209+
133210 void UserInputMapper::assignDefaulActionScales() {
134211 _actionScales[LONGITUDINAL_BACKWARD] = 1.0f; // 1m per unit
135212 _actionScales[LONGITUDINAL_FORWARD] = 1.0f; // 1m per unit
@@ -144,3 +221,20 @@ void UserInputMapper::assignDefaulActionScales() { · 8 unmodified lines
144221 _actionScales[BOOM_IN] = 1.0f; // 1m per unit
145222 _actionScales[BOOM_OUT] = 1.0f; // 1m per unit
146223 }
224+
225+// This is only necessary as long as the actions are hardcoded
226+// Eventually you can just add the string when you add the action
227+void UserInputMapper::createActionNames() {
228+ _actionNames[LONGITUDINAL_BACKWARD] = "LONGITUDINAL_BACKWARD";
229+ _actionNames[LONGITUDINAL_FORWARD] = "LONGITUDINAL_FORWARD";
230+ _actionNames[LATERAL_LEFT] = "LATERAL_LEFT";
231+ _actionNames[LATERAL_RIGHT] = "LATERAL_RIGHT";
232+ _actionNames[VERTICAL_DOWN] = "VERTICAL_DOWN";
233+ _actionNames[VERTICAL_UP] = "VERTICAL_UP";
234+ _actionNames[YAW_LEFT] = "YAW_LEFT";
235+ _actionNames[YAW_RIGHT] = "YAW_RIGHT";
236+ _actionNames[PITCH_DOWN] = "PITCH_DOWN";
237+ _actionNames[PITCH_UP] = "PITCH_UP";
238+ _actionNames[BOOM_IN] = "BOOM_IN";
239+ _actionNames[BOOM_OUT] = "BOOM_OUT";
240+}