2 * Copyright (C) 2005-2024 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "ActionIDs.h"
12 #include "ActionTranslator.h"
13 #include "input/keyboard/Key.h"
14 #include "input/keyboard/KeyIDs.h"
17 using namespace ACTION
;
19 CAction::CAction() : m_id(ACTION_NONE
)
23 CAction::CAction(int actionID
,
24 float amount1
/* = 1.0f */,
25 float amount2
/* = 0.0f */,
26 const std::string
& name
/* = "" */,
27 unsigned int holdTime
/*= 0*/,
28 unsigned int buttonCode
/*= 0*/)
32 m_amount
[0] = amount1
;
33 m_amount
[1] = amount2
;
35 m_buttonCode
= buttonCode
;
37 m_holdTime
= holdTime
;
40 CAction::CAction(int actionID
,
48 const std::string
& name
)
54 m_amount
[2] = offsetX
;
55 m_amount
[3] = offsetY
;
56 m_amount
[4] = velocityX
;
57 m_amount
[5] = velocityY
;
64 CAction::CAction(int actionID
, wchar_t unicode
)
73 CAction::CAction(int actionID
, const std::string
& name
, const CKey
& key
) : m_name(name
)
76 m_amount
[0] = 1; // digital button (could change this for repeat acceleration)
77 m_repeat
= key
.GetRepeat();
78 m_buttonCode
= key
.GetButtonCode();
79 m_unicode
= key
.GetUnicode();
80 m_holdTime
= key
.GetHeld();
81 // get the action amounts of the analog buttons
82 if (key
.GetButtonCode() == KEY_BUTTON_LEFT_ANALOG_TRIGGER
)
83 m_amount
[0] = (float)key
.GetLeftTrigger() / 255.0f
;
84 else if (key
.GetButtonCode() == KEY_BUTTON_RIGHT_ANALOG_TRIGGER
)
85 m_amount
[0] = (float)key
.GetRightTrigger() / 255.0f
;
86 else if (key
.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK
)
88 m_amount
[0] = key
.GetLeftThumbX();
89 m_amount
[1] = key
.GetLeftThumbY();
91 else if (key
.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK
)
93 m_amount
[0] = key
.GetRightThumbX();
94 m_amount
[1] = key
.GetRightThumbY();
96 else if (key
.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_UP
)
97 m_amount
[0] = key
.GetLeftThumbY();
98 else if (key
.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_DOWN
)
99 m_amount
[0] = -key
.GetLeftThumbY();
100 else if (key
.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_LEFT
)
101 m_amount
[0] = -key
.GetLeftThumbX();
102 else if (key
.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_RIGHT
)
103 m_amount
[0] = key
.GetLeftThumbX();
104 else if (key
.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_UP
)
105 m_amount
[0] = key
.GetRightThumbY();
106 else if (key
.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_DOWN
)
107 m_amount
[0] = -key
.GetRightThumbY();
108 else if (key
.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_LEFT
)
109 m_amount
[0] = -key
.GetRightThumbX();
110 else if (key
.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_RIGHT
)
111 m_amount
[0] = key
.GetRightThumbX();
114 CAction::CAction(int actionID
, const std::string
& name
) : m_name(name
)
123 CAction
& CAction::operator=(const CAction
& rhs
)
128 for (unsigned int i
= 0; i
< max_amounts
; i
++)
129 m_amount
[i
] = rhs
.m_amount
[i
];
131 m_repeat
= rhs
.m_repeat
;
132 m_buttonCode
= rhs
.m_buttonCode
;
133 m_unicode
= rhs
.m_unicode
;
134 m_holdTime
= rhs
.m_holdTime
;
140 void CAction::ClearAmount()
142 for (float& amount
: m_amount
)
146 bool CAction::IsMouse() const
148 return (m_id
>= ACTION_MOUSE_START
&& m_id
<= ACTION_MOUSE_END
);
151 bool CAction::IsGesture() const
153 return (m_id
>= ACTION_GESTURE_NOTIFY
&& m_id
<= ACTION_GESTURE_END
);
156 bool CAction::IsAnalog() const
158 return CActionTranslator::IsAnalog(m_id
);