You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

129 lines
3.2 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2010—2015 Benjamin Litzelmann
  5. // © 2017—2018 Sam Hocevar <sam@hocevar.net>
  6. //
  7. // Lol Engine is free software. It comes without any warranty, to
  8. // the extent permitted by applicable law. You can redistribute it
  9. // and/or modify it under the terms of the Do What the Fuck You Want
  10. // to Public License, Version 2, as published by the WTFPL Task Force.
  11. // See http://www.wtfpl.net/ for more details.
  12. //
  13. #include <lol/engine-internal.h>
  14. #include <string>
  15. #include "input/input_internal.h"
  16. namespace lol
  17. {
  18. array<InputDevice*> InputDevice::devices;
  19. int InputDevice::joystick_count = 0;
  20. bool InputDevice::m_capturemouse;
  21. array<std::string> InputDevice::GetAvailableDevices()
  22. {
  23. array<std::string> result;
  24. for (auto const &device : devices)
  25. result.push(device->m_name);
  26. return result;
  27. }
  28. std::string InputDevice::GetText()
  29. {
  30. std::string ret = m_text;
  31. m_text = "";
  32. return ret;
  33. }
  34. bool InputDevice::IsTextInputActive()
  35. {
  36. return m_input_active;
  37. }
  38. void InputDevice::SetTextInputActive(bool status)
  39. {
  40. m_input_active = status;
  41. }
  42. void InputDeviceInternal::AddKey(int index, const char* name)
  43. {
  44. if (index == -1)
  45. index = m_keynames.count();
  46. while (index >= m_keynames.count())
  47. {
  48. m_keynames.push(name);
  49. m_keys.push(false);
  50. }
  51. m_keynames.last() = name;
  52. }
  53. void InputDeviceInternal::AddAxis(int index, const char* name, float sensitivity)
  54. {
  55. if (index == -1)
  56. index = m_axisnames.count();
  57. while (index >= m_axisnames.count())
  58. {
  59. m_axisnames.push(name);
  60. m_axis.push(0.0f, 1.0f);
  61. }
  62. m_axisnames.last() = name;
  63. m_axis.last().m1 = 0.0f;
  64. m_axis.last().m2 = sensitivity;
  65. }
  66. void InputDeviceInternal::AddCursor(int index, const char* name)
  67. {
  68. if (index == -1)
  69. index = m_cursornames.count();
  70. while (index >= m_cursornames.count())
  71. {
  72. m_cursornames.push(name);
  73. m_cursors.push(vec2::zero, ivec2::zero);
  74. }
  75. m_cursornames.last() = name;
  76. }
  77. InputDeviceInternal* InputDeviceInternal::CreateStandardKeyboard()
  78. {
  79. InputDeviceInternal* keyboard = new InputDeviceInternal(g_name_keyboard.c_str());
  80. /* Register all scancodes known to SDL (from the USB standard) */
  81. # define _SC(id, str, name) keyboard->AddKey(id, #name);
  82. # include "input/keys.h"
  83. return keyboard;
  84. }
  85. InputDeviceInternal* InputDeviceInternal::CreateStandardMouse()
  86. {
  87. InputDeviceInternal* mouse = new InputDeviceInternal(g_name_mouse.c_str());
  88. mouse->AddKey(g_name_mouse_key_left.c_str());
  89. mouse->AddKey(g_name_mouse_key_middle.c_str());
  90. mouse->AddKey(g_name_mouse_key_right.c_str());
  91. //Added to manage if mouse is in the screen or not.
  92. mouse->AddKey(g_name_mouse_key_in_screen.c_str());
  93. mouse->AddAxis(g_name_mouse_axis_x.c_str());
  94. mouse->AddAxis(g_name_mouse_axis_y.c_str());
  95. mouse->AddAxis(g_name_mouse_axis_xpixel.c_str());
  96. mouse->AddAxis(g_name_mouse_axis_ypixel.c_str());
  97. mouse->AddAxis(g_name_mouse_axis_scroll.c_str(), .0000001f);
  98. mouse->AddCursor(g_name_mouse_cursor.c_str());
  99. // TODO: extended button, and wheel (as axis or as buttons? or both?)
  100. return mouse;
  101. }
  102. } /* namespace lol */