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