| 1 |
/* |
| 2 |
* Copyright (C) 2005-2024 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "Action.h" |
| 10 |
|
| 11 |
#include "ActionIDs.h" |
| 12 |
#include "ActionTranslator.h" |
| 13 |
#include "input/keyboard/Key.h" |
| 14 |
#include "input/keyboard/KeyIDs.h" |
| 15 |
|
| 16 |
using namespace KODI; |
| 17 |
using namespace ACTION; |
| 18 |
|
| 19 |
CAction::CAction() : m_id(ACTION_NONE) |
| 20 |
{ |
| 21 |
} |
| 22 |
|
| 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) |
| 30 |
{ |
| 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; |
| 38 |
} |
| 39 |
|
| 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) |
| 50 |
{ |
| 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; |
| 62 |
} |
| 63 |
|
| 64 |
CAction::CAction(int actionID, wchar_t unicode) |
| 65 |
{ |
| 66 |
m_id = actionID; |
| 67 |
m_repeat = 0; |
| 68 |
m_buttonCode = 0; |
| 69 |
m_unicode = unicode; |
| 70 |
m_holdTime = 0; |
| 71 |
} |
| 72 |
|
| 73 |
CAction::CAction(int actionID, const std::string& name, const CKey& key) : m_name(name) |
| 74 |
{ |
| 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) |
| 87 |
{ |
| 88 |
m_amount[0] = key.GetLeftThumbX(); |
| 89 |
m_amount[1] = key.GetLeftThumbY(); |
| 90 |
} |
| 91 |
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK) |
| 92 |
{ |
| 93 |
m_amount[0] = key.GetRightThumbX(); |
| 94 |
m_amount[1] = key.GetRightThumbY(); |
| 95 |
} |
| 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(); |
| 112 |
} |
| 113 |
|
| 114 |
CAction::CAction(int actionID, const std::string& name) : m_name(name) |
| 115 |
{ |
| 116 |
m_id = actionID; |
| 117 |
m_repeat = 0; |
| 118 |
m_buttonCode = 0; |
| 119 |
m_unicode = 0; |
| 120 |
m_holdTime = 0; |
| 121 |
} |
| 122 |
|
| 123 |
CAction& CAction::operator=(const CAction& rhs) |
| 124 |
{ |
| 125 |
if (this != &rhs) |
| 126 |
{ |
| 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; |
| 136 |
} |
| 137 |
return *this; |
| 138 |
} |
| 139 |
|
| 140 |
void CAction::ClearAmount() |
| 141 |
{ |
| 142 |
for (float& amount : m_amount) |
| 143 |
amount = 0; |
| 144 |
} |
| 145 |
|
| 146 |
bool CAction::IsMouse() const |
| 147 |
{ |
| 148 |
return (m_id >= ACTION_MOUSE_START && m_id <= ACTION_MOUSE_END); |
| 149 |
} |
| 150 |
|
| 151 |
bool CAction::IsGesture() const |
| 152 |
{ |
| 153 |
return (m_id >= ACTION_GESTURE_NOTIFY && m_id <= ACTION_GESTURE_END); |
| 154 |
} |
| 155 |
|
| 156 |
bool CAction::IsAnalog() const |
| 157 |
{ |
| 158 |
return CActionTranslator::IsAnalog(m_id); |
| 159 |
} |