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.
 
 
 

110 lines
1.7 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  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. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstdlib>
  14. #include "core.h"
  15. namespace lol
  16. {
  17. /*
  18. * Stick implementation class
  19. */
  20. static class StickData
  21. {
  22. friend class Stick;
  23. public:
  24. StickData() { }
  25. private:
  26. /* First element is the remap target */
  27. Array<int, float> m_axes;
  28. Array<int, int> m_buttons;
  29. }
  30. stickdata;
  31. /*
  32. * Public Stick class
  33. */
  34. Stick::Stick()
  35. : m_data(new StickData())
  36. {
  37. }
  38. Stick::~Stick()
  39. {
  40. delete m_data;
  41. }
  42. void Stick::SetAxisCount(int n)
  43. {
  44. m_data->m_axes.Empty();
  45. for (int i = 0; i < n; i++)
  46. m_data->m_axes.Push(i, 0.f);
  47. }
  48. void Stick::SetButtonCount(int n)
  49. {
  50. m_data->m_buttons.Empty();
  51. for (int i = 0; i < n; i++)
  52. m_data->m_buttons.Push(i, 0);
  53. }
  54. void Stick::SetAxis(int n, float val)
  55. {
  56. m_data->m_axes[m_data->m_axes[n].m1].m2 = val;
  57. }
  58. void Stick::SetButton(int n, int val)
  59. {
  60. m_data->m_buttons[m_data->m_buttons[n].m1].m2 = val;
  61. }
  62. void Stick::RemapAxis(int src, int dst)
  63. {
  64. m_data->m_axes[src].m1 = dst;
  65. }
  66. void Stick::RemapButton(int src, int dst)
  67. {
  68. m_data->m_buttons[src].m1 = dst;
  69. }
  70. int Stick::GetAxisCount()
  71. {
  72. return m_data->m_axes.Count();
  73. }
  74. int Stick::GetButtonCount()
  75. {
  76. return m_data->m_buttons.Count();
  77. }
  78. float Stick::GetAxis(int n)
  79. {
  80. return m_data->m_axes[n].m2;
  81. }
  82. int Stick::GetButton(int n)
  83. {
  84. return m_data->m_buttons[n].m2;
  85. }
  86. } /* namespace lol */