| 292 | } |
| 293 | |
| 294 | void SetBinding(HBinding binding, dmInputDDF::InputBinding* ddf) |
| 295 | { |
| 296 | uint32_t total_actions = ddf->m_KeyTrigger.m_Count + |
| 297 | ddf->m_MouseTrigger.m_Count + |
| 298 | ddf->m_TouchTrigger.m_Count + |
| 299 | ddf->m_TextTrigger.m_Count + 2; |
| 300 | |
| 301 | uint32_t current_capacity = binding->m_Actions.Capacity(); |
| 302 | if (total_actions > current_capacity) { |
| 303 | binding->m_Actions.OffsetCapacity(total_actions - current_capacity); |
| 304 | } |
| 305 | binding->m_Actions.Clear(); |
| 306 | |
| 307 | Action action; |
| 308 | memset(&action, 0, sizeof(Action)); |
| 309 | // add null action for mouse movement |
| 310 | binding->m_Actions.Put(0, action); |
| 311 | if (ddf->m_KeyTrigger.m_Count > 0) |
| 312 | { |
| 313 | if (binding->m_KeyboardBinding == 0x0) |
| 314 | { |
| 315 | binding->m_KeyboardBinding = new KeyboardBinding(); |
| 316 | memset(binding->m_KeyboardBinding, 0, sizeof(*binding->m_KeyboardBinding)); |
| 317 | |
| 318 | binding->m_KeyboardBinding->m_Keyboard = dmHID::GetKeyboard(binding->m_Context->m_HidContext, 0); |
| 319 | } |
| 320 | else |
| 321 | { |
| 322 | binding->m_KeyboardBinding->m_Triggers.SetSize(0); |
| 323 | } |
| 324 | binding->m_KeyboardBinding->m_Triggers.SetCapacity(ddf->m_KeyTrigger.m_Count); |
| 325 | for (uint32_t i = 0; i < ddf->m_KeyTrigger.m_Count; ++i) |
| 326 | { |
| 327 | const dmInputDDF::KeyTrigger& ddf_trigger = ddf->m_KeyTrigger[i]; |
| 328 | dmInput::KeyTrigger trigger; |
| 329 | trigger.m_ActionId = dmHashString64(ddf_trigger.m_Action); |
| 330 | trigger.m_Input = ddf_trigger.m_Input; |
| 331 | binding->m_KeyboardBinding->m_Triggers.Push(trigger); |
| 332 | binding->m_Actions.Put(trigger.m_ActionId, action); |
| 333 | } |
| 334 | } |
| 335 | else if (binding->m_KeyboardBinding != 0x0) |
| 336 | { |
| 337 | delete binding->m_KeyboardBinding; |
| 338 | binding->m_KeyboardBinding = 0x0; |
| 339 | } |
| 340 | if (ddf->m_MouseTrigger.m_Count > 0) |
| 341 | { |
| 342 | if (binding->m_MouseBinding == 0x0) |
| 343 | { |
| 344 | binding->m_MouseBinding = new MouseBinding(); |
| 345 | memset(binding->m_MouseBinding, 0, sizeof(*binding->m_MouseBinding)); |
| 346 | |
| 347 | binding->m_MouseBinding->m_Mouse = dmHID::GetMouse(binding->m_Context->m_HidContext, 0); |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | binding->m_MouseBinding->m_Triggers.SetSize(0); |