source: trunk/src/input/stick.cpp @ 2183

Last change on this file since 2183 was 2183, checked in by sam, 7 years ago

build: fix the WTFPL site URL in all code comments.

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