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.

115 lines
2.8 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Benjamin Litzelmann
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #include <lol/engine-internal.h>
  11. #include "input/input_internal.h"
  12. namespace lol
  13. {
  14. array<InputDevice*> InputDevice::devices;
  15. bool InputDevice::m_capturemouse;
  16. array<String> InputDevice::GetAvailableDevices()
  17. {
  18. array<String> result;
  19. for (int i = 0; i < devices.Count(); ++i)
  20. {
  21. result.Push(devices[i]->m_name);
  22. }
  23. return result;
  24. }
  25. String InputDevice::GetText()
  26. {
  27. String ret = m_text;
  28. m_text = "";
  29. return ret;
  30. }
  31. void InputDeviceInternal::AddKey(int index, const char* name)
  32. {
  33. if (index == -1)
  34. index = m_keynames.Count();
  35. while (index >= m_keynames.Count())
  36. {
  37. m_keynames.Push(name);
  38. m_keys.Push(false);
  39. }
  40. m_keynames.Last() = name;
  41. }
  42. void InputDeviceInternal::AddAxis(int index, const char* name, float sensitivity)
  43. {
  44. if (index == -1)
  45. index = m_axisnames.Count();
  46. while (index >= m_axisnames.Count())
  47. {
  48. m_axisnames.Push(name);
  49. m_axis.Push(0.0f, 1.0f);
  50. }
  51. m_axisnames.Last() = name;
  52. m_axis.Last().m1 = 0.0f;
  53. m_axis.Last().m2 = sensitivity;
  54. }
  55. void InputDeviceInternal::AddCursor(int index, const char* name)
  56. {
  57. if (index == -1)
  58. index = m_cursornames.Count();
  59. while (index >= m_cursornames.Count())
  60. {
  61. m_cursornames.Push(name);
  62. m_cursors.Push(vec2::zero, ivec2::zero);
  63. }
  64. m_cursornames.Last() = name;
  65. }
  66. InputDeviceInternal* InputDeviceInternal::CreateStandardKeyboard()
  67. {
  68. InputDeviceInternal* keyboard = new InputDeviceInternal(g_name_keyboard.C());
  69. /* Register all scancodes known to SDL (from the USB standard) */
  70. # define _SC(id, str, name) keyboard->AddKey(id, #name);
  71. # include "input/keys.h"
  72. return keyboard;
  73. }
  74. InputDeviceInternal* InputDeviceInternal::CreateStandardMouse()
  75. {
  76. InputDeviceInternal* mouse = new InputDeviceInternal(g_name_mouse.C());
  77. mouse->AddKey(g_name_mouse_key_left.C());
  78. mouse->AddKey(g_name_mouse_key_middle.C());
  79. mouse->AddKey(g_name_mouse_key_right.C());
  80. //Added to manage if mouse is in the screen or not.
  81. mouse->AddKey(g_name_mouse_key_inScreen.C());
  82. mouse->AddAxis(g_name_mouse_axis_x.C());
  83. mouse->AddAxis(g_name_mouse_axis_y.C());
  84. mouse->AddAxis(g_name_mouse_axis_xpixel.C());
  85. mouse->AddAxis(g_name_mouse_axis_ypixel.C());
  86. mouse->AddAxis(g_name_mouse_axis_scroll.C());
  87. mouse->AddCursor(g_name_mouse_cursor.C());
  88. // TODO: extended button, and wheel (as axis or as buttons? or both?)
  89. return mouse;
  90. }
  91. } /* namespace lol */