~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Source/Core/InputCommon/Src/ControllerInterface/Device.h

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#ifndef _DEVICE_H_
 
3
#define _DEVICE_H_
 
4
 
 
5
#include <string>
 
6
#include <vector>
 
7
 
 
8
#include "Common.h"
 
9
 
 
10
// idk in case I wanted to change it to double or something, idk what's best
 
11
typedef float ControlState;
 
12
 
 
13
namespace ciface
 
14
{
 
15
namespace Core
 
16
{
 
17
 
 
18
// Forward declarations
 
19
class DeviceQualifier;
 
20
 
 
21
//
 
22
//              Device
 
23
//
 
24
// a device class
 
25
//
 
26
class Device
 
27
{
 
28
public:
 
29
        class Input;
 
30
        class Output;
 
31
 
 
32
        //
 
33
        //              Control
 
34
        //
 
35
        //  control includes inputs and outputs
 
36
        //
 
37
        class Control           // input or output
 
38
        {
 
39
        public:
 
40
                virtual std::string GetName() const = 0;
 
41
                virtual ~Control() {}
 
42
 
 
43
                virtual Input* ToInput() { return NULL; }
 
44
                virtual Output* ToOutput() { return NULL; }
 
45
        };
 
46
 
 
47
        //
 
48
        //              Input
 
49
        //
 
50
        // an input on a device
 
51
        //
 
52
        class Input : public Control
 
53
        {
 
54
        public:
 
55
                // things like absolute axes/ absolute mouse position will override this
 
56
                virtual bool IsDetectable() { return true; }
 
57
 
 
58
                virtual ControlState GetState() const = 0;
 
59
 
 
60
                Input* ToInput() { return this; }
 
61
        };
 
62
 
 
63
        //
 
64
        //              Output
 
65
        //
 
66
        // an output on a device
 
67
        //
 
68
        class Output : public Control
 
69
        {
 
70
        public:
 
71
                virtual ~Output() {}
 
72
 
 
73
                virtual void SetState(ControlState state) = 0;
 
74
 
 
75
                Output* ToOutput() { return this; }
 
76
        };
 
77
 
 
78
        virtual ~Device();
 
79
 
 
80
        virtual std::string GetName() const = 0;
 
81
        virtual int GetId() const = 0;
 
82
        virtual std::string GetSource() const = 0;
 
83
        virtual bool UpdateInput() = 0;
 
84
        virtual bool UpdateOutput() = 0;
 
85
 
 
86
        virtual void ClearInputState();
 
87
 
 
88
        const std::vector<Input*>& Inputs() const { return m_inputs; }
 
89
        const std::vector<Output*>& Outputs() const { return m_outputs; }
 
90
 
 
91
        Input* FindInput(const std::string& name) const;
 
92
        Output* FindOutput(const std::string& name) const;
 
93
 
 
94
protected:
 
95
        void AddInput(Input* const i);
 
96
        void AddOutput(Output* const o);
 
97
 
 
98
        class FullAnalogSurface : public Input
 
99
        {
 
100
        public:
 
101
                FullAnalogSurface(Input* low, Input* high)
 
102
                        : m_low(*low), m_high(*high)
 
103
                {}
 
104
 
 
105
                ControlState GetState() const
 
106
                {
 
107
                        return (1 + m_high.GetState() - m_low.GetState()) / 2;
 
108
                }
 
109
 
 
110
                std::string GetName() const
 
111
                {
 
112
                        return m_low.GetName() + *m_high.GetName().rbegin();
 
113
                }
 
114
 
 
115
        private:
 
116
                Input& m_low;
 
117
                Input& m_high;
 
118
        };
 
119
 
 
120
        void AddAnalogInputs(Input* low, Input* high)
 
121
        {
 
122
                AddInput(low);
 
123
                AddInput(high);
 
124
                AddInput(new FullAnalogSurface(low, high));
 
125
                AddInput(new FullAnalogSurface(high, low));
 
126
        }
 
127
 
 
128
private:
 
129
        std::vector<Input*>             m_inputs;
 
130
        std::vector<Output*>    m_outputs;
 
131
};
 
132
 
 
133
//
 
134
//              DeviceQualifier
 
135
//
 
136
// device qualifier used to match devices
 
137
// currently has ( source, id, name ) properties which match a device
 
138
//
 
139
class DeviceQualifier
 
140
{
 
141
public:
 
142
        DeviceQualifier() : cid(-1) {}
 
143
        DeviceQualifier(const std::string& _source, const int _id, const std::string& _name)
 
144
                : source(_source), cid(_id), name(_name) {}
 
145
        void FromDevice(const Device* const dev);
 
146
        void FromString(const std::string& str);
 
147
        std::string ToString() const;
 
148
        bool operator==(const DeviceQualifier& devq) const;
 
149
        bool operator==(const Device* const dev) const;
 
150
 
 
151
        std::string             source;
 
152
        int                             cid;
 
153
        std::string             name;
 
154
};
 
155
 
 
156
class DeviceContainer
 
157
{
 
158
public:
 
159
        Device::Input* FindInput(const std::string& name, const Device* def_dev) const;
 
160
        Device::Output* FindOutput(const std::string& name, const Device* def_dev) const;
 
161
 
 
162
        const std::vector<Device*>& Devices() const { return m_devices; }
 
163
        Device* FindDevice(const DeviceQualifier& devq) const;
 
164
protected:
 
165
        std::vector<Device*> m_devices;
 
166
};
 
167
 
 
168
}
 
169
}
 
170
 
 
171
#endif