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