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

Last change on this file since 1355 was 1355, checked in by sam, 8 years ago

input: allow to remap gamepad axes in the generic input layer.

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