Merge pull request #26293 from the-black-eagle/mka_read_more_tags
[xbmc.git] / xbmc / input / actions / Action.cpp
blobe5ccdd8653064dae5e6c3812f73d1630e5362505
1 /*
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.
7 */
9 #include "Action.h"
11 #include "ActionIDs.h"
12 #include "ActionTranslator.h"
13 #include "input/keyboard/Key.h"
14 #include "input/keyboard/KeyIDs.h"
16 using namespace KODI;
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*/)
29 : m_name(name)
31 m_id = actionID;
32 m_amount[0] = amount1;
33 m_amount[1] = amount2;
34 m_repeat = 0;
35 m_buttonCode = buttonCode;
36 m_unicode = 0;
37 m_holdTime = holdTime;
40 CAction::CAction(int actionID,
41 unsigned int state,
42 float posX,
43 float posY,
44 float offsetX,
45 float offsetY,
46 float velocityX,
47 float velocityY,
48 const std::string& name)
49 : m_name(name)
51 m_id = actionID;
52 m_amount[0] = posX;
53 m_amount[1] = posY;
54 m_amount[2] = offsetX;
55 m_amount[3] = offsetY;
56 m_amount[4] = velocityX;
57 m_amount[5] = velocityY;
58 m_repeat = 0;
59 m_buttonCode = 0;
60 m_unicode = 0;
61 m_holdTime = state;
64 CAction::CAction(int actionID, wchar_t unicode)
66 m_id = actionID;
67 m_repeat = 0;
68 m_buttonCode = 0;
69 m_unicode = unicode;
70 m_holdTime = 0;
73 CAction::CAction(int actionID, const std::string& name, const CKey& key) : m_name(name)
75 m_id = actionID;
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)
116 m_id = actionID;
117 m_repeat = 0;
118 m_buttonCode = 0;
119 m_unicode = 0;
120 m_holdTime = 0;
123 CAction& CAction::operator=(const CAction& rhs)
125 if (this != &rhs)
127 m_id = rhs.m_id;
128 for (unsigned int i = 0; i < max_amounts; i++)
129 m_amount[i] = rhs.m_amount[i];
130 m_name = rhs.m_name;
131 m_repeat = rhs.m_repeat;
132 m_buttonCode = rhs.m_buttonCode;
133 m_unicode = rhs.m_unicode;
134 m_holdTime = rhs.m_holdTime;
135 m_text = rhs.m_text;
137 return *this;
140 void CAction::ClearAmount()
142 for (float& amount : m_amount)
143 amount = 0;
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);