1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "Action.h"
#include "ActionIDs.h"
#include "ActionTranslator.h"
#include "input/Key.h"
CAction::CAction() : m_id(ACTION_NONE)
{
}
CAction::CAction(int actionID,
float amount1 /* = 1.0f */,
float amount2 /* = 0.0f */,
const std::string& name /* = "" */,
unsigned int holdTime /*= 0*/)
: m_name(name)
{
m_id = actionID;
m_amount[0] = amount1;
m_amount[1] = amount2;
m_repeat = 0;
m_buttonCode = 0;
m_unicode = 0;
m_holdTime = holdTime;
}
CAction::CAction(int actionID,
unsigned int state,
float posX,
float posY,
float offsetX,
float offsetY,
float velocityX,
float velocityY,
const std::string& name)
: m_name(name)
{
m_id = actionID;
m_amount[0] = posX;
m_amount[1] = posY;
m_amount[2] = offsetX;
m_amount[3] = offsetY;
m_amount[4] = velocityX;
m_amount[5] = velocityY;
m_repeat = 0;
m_buttonCode = 0;
m_unicode = 0;
m_holdTime = state;
}
CAction::CAction(int actionID, wchar_t unicode)
{
m_id = actionID;
m_repeat = 0;
m_buttonCode = 0;
m_unicode = unicode;
m_holdTime = 0;
}
CAction::CAction(int actionID, const std::string& name, const CKey& key) : m_name(name)
{
m_id = actionID;
m_amount[0] = 1; // digital button (could change this for repeat acceleration)
m_repeat = key.GetRepeat();
m_buttonCode = key.GetButtonCode();
m_unicode = key.GetUnicode();
m_holdTime = key.GetHeld();
// get the action amounts of the analog buttons
if (key.GetButtonCode() == KEY_BUTTON_LEFT_ANALOG_TRIGGER)
m_amount[0] = (float)key.GetLeftTrigger() / 255.0f;
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_ANALOG_TRIGGER)
m_amount[0] = (float)key.GetRightTrigger() / 255.0f;
else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK)
{
m_amount[0] = key.GetLeftThumbX();
m_amount[1] = key.GetLeftThumbY();
}
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK)
{
m_amount[0] = key.GetRightThumbX();
m_amount[1] = key.GetRightThumbY();
}
else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_UP)
m_amount[0] = key.GetLeftThumbY();
else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_DOWN)
m_amount[0] = -key.GetLeftThumbY();
else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_LEFT)
m_amount[0] = -key.GetLeftThumbX();
else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_RIGHT)
m_amount[0] = key.GetLeftThumbX();
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_UP)
m_amount[0] = key.GetRightThumbY();
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_DOWN)
m_amount[0] = -key.GetRightThumbY();
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_LEFT)
m_amount[0] = -key.GetRightThumbX();
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_RIGHT)
m_amount[0] = key.GetRightThumbX();
}
CAction::CAction(int actionID, const std::string& name) : m_name(name)
{
m_id = actionID;
m_repeat = 0;
m_buttonCode = 0;
m_unicode = 0;
m_holdTime = 0;
}
CAction& CAction::operator=(const CAction& rhs)
{
if (this != &rhs)
{
m_id = rhs.m_id;
for (unsigned int i = 0; i < max_amounts; i++)
m_amount[i] = rhs.m_amount[i];
m_name = rhs.m_name;
m_repeat = rhs.m_repeat;
m_buttonCode = rhs.m_buttonCode;
m_unicode = rhs.m_unicode;
m_holdTime = rhs.m_holdTime;
m_text = rhs.m_text;
}
return *this;
}
void CAction::ClearAmount()
{
for (float& amount : m_amount)
amount = 0;
}
bool CAction::IsMouse() const
{
return (m_id >= ACTION_MOUSE_START && m_id <= ACTION_MOUSE_END);
}
bool CAction::IsGesture() const
{
return (m_id >= ACTION_GESTURE_NOTIFY && m_id <= ACTION_GESTURE_END);
}
bool CAction::IsAnalog() const
{
return CActionTranslator::IsAnalog(m_id);
}
|