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

Last change on this file since 2810 was 2810, checked in by benlitz, 7 years ago

Completely reworked input system. Unified device interface, button, axis and cursor support, controller and binding system, mouse capture. Tutorial 07_input provided. Require to compile lolcore with LOL_INPUT_V2 to be activated (also needed app-side before including core.h)

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#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
21namespace lol
22{
23
24/*
25 * Stick implementation class
26 */
27
28static class StickData
29{
30    friend class Stick;
31
32public:
33    StickData() { }
34
35private:
36    /* First element is the remap target */
37    Array<int, float> m_axes;
38    Array<int, int> m_buttons;
39}
40stickdata;
41
42/*
43 * Public Stick class
44 */
45
46Stick::Stick()
47  : m_data(new StickData())
48{
49}
50
51Stick::~Stick()
52{
53    delete m_data;
54}
55
56void 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
63void 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
70void Stick::SetAxis(int n, float val)
71{
72    m_data->m_axes[m_data->m_axes[n].m1].m2 = val;
73}
74
75void Stick::SetButton(int n, int val)
76{
77    m_data->m_buttons[m_data->m_buttons[n].m1].m2 = val;
78}
79
80void Stick::RemapAxis(int src, int dst)
81{
82    m_data->m_axes[src].m1 = dst;
83}
84
85void Stick::RemapButton(int src, int dst)
86{
87    m_data->m_buttons[src].m1 = dst;
88}
89
90int Stick::GetAxisCount()
91{
92    return m_data->m_axes.Count();
93}
94
95int Stick::GetButtonCount()
96{
97    return m_data->m_buttons.Count();
98}
99
100float Stick::GetAxis(int n)
101{
102    return m_data->m_axes[n].m2;
103}
104
105int Stick::GetButton(int n)
106{
107    return m_data->m_buttons[n].m2;
108}
109
110} /* namespace lol */
111
112#endif // !LOL_INPUT_V2
Note: See TracBrowser for help on using the repository browser.