| 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 |
#pragma once |
| 10 |
|
| 11 |
#include <string> |
| 12 |
|
| 13 |
class CKey; |
| 14 |
|
| 15 |
/*! |
| 16 |
* \ingroup action |
| 17 |
* |
| 18 |
* \brief Class encapsulating information regarding a particular user action to |
| 19 |
* be sent to windows and controls |
| 20 |
*/ |
| 21 |
class CAction |
| 22 |
{ |
| 23 |
public: |
| 24 |
CAction(); |
| 25 |
CAction(int actionID, |
| 26 |
float amount1 = 1.0f, |
| 27 |
float amount2 = 0.0f, |
| 28 |
const std::string& name = "", |
| 29 |
unsigned int holdTime = 0, |
| 30 |
unsigned int buttonCode = 0); |
| 31 |
CAction(int actionID, wchar_t unicode); |
| 32 |
CAction(int actionID, |
| 33 |
unsigned int state, |
| 34 |
float posX, |
| 35 |
float posY, |
| 36 |
float offsetX, |
| 37 |
float offsetY, |
| 38 |
float velocityX = 0.0f, |
| 39 |
float velocityY = 0.0f, |
| 40 |
const std::string& name = ""); |
| 41 |
CAction(int actionID, const std::string& name, const CKey& key); |
| 42 |
CAction(int actionID, const std::string& name); |
| 43 |
|
| 44 |
CAction(const CAction& other) { *this = other; } |
| 45 |
CAction& operator=(const CAction& rhs); |
| 46 |
|
| 47 |
/*! \brief Identifier of the action |
| 48 |
\return id of the action |
| 49 |
*/ |
| 50 |
int GetID() const { return m_id; } |
| 51 |
|
| 52 |
/*! \brief Is this an action from the mouse |
| 53 |
\return true if this is a mouse action, false otherwise |
| 54 |
*/ |
| 55 |
bool IsMouse() const; |
| 56 |
|
| 57 |
bool IsGesture() const; |
| 58 |
|
| 59 |
/*! \brief Human-readable name of the action |
| 60 |
\return name of the action |
| 61 |
*/ |
| 62 |
const std::string& GetName() const { return m_name; } |
| 63 |
|
| 64 |
/*! \brief Text of the action if any |
| 65 |
\return text payload of this action. |
| 66 |
*/ |
| 67 |
const std::string& GetText() const { return m_text; } |
| 68 |
|
| 69 |
/*! \brief Set the text payload of the action |
| 70 |
\param text to be set |
| 71 |
*/ |
| 72 |
void SetText(const std::string& text) { m_text = text; } |
| 73 |
|
| 74 |
/*! \brief Get an amount associated with this action |
| 75 |
\param zero-based index of amount to retrieve, defaults to 0 |
| 76 |
\return an amount associated with this action |
| 77 |
*/ |
| 78 |
float GetAmount(unsigned int index = 0) const |
| 79 |
{ |
| 80 |
return (index < max_amounts) ? m_amount[index] : 0; |
| 81 |
}; |
| 82 |
|
| 83 |
/*! \brief Reset all amount values to zero |
| 84 |
*/ |
| 85 |
void ClearAmount(); |
| 86 |
|
| 87 |
/*! \brief Unicode value associated with this action |
| 88 |
\return unicode value associated with this action, for keyboard input. |
| 89 |
*/ |
| 90 |
wchar_t GetUnicode() const { return m_unicode; } |
| 91 |
|
| 92 |
/*! \brief Time in ms that the key has been held |
| 93 |
\return time that the key has been held down in ms. |
| 94 |
*/ |
| 95 |
unsigned int GetHoldTime() const { return m_holdTime; } |
| 96 |
|
| 97 |
/*! \brief Time since last repeat in ms |
| 98 |
\return time since last repeat in ms. Returns 0 if unknown. |
| 99 |
*/ |
| 100 |
float GetRepeat() const { return m_repeat; } |
| 101 |
|
| 102 |
/*! \brief Button code that triggered this action |
| 103 |
\return button code |
| 104 |
*/ |
| 105 |
unsigned int GetButtonCode() const { return m_buttonCode; } |
| 106 |
|
| 107 |
bool IsAnalog() const; |
| 108 |
|
| 109 |
private: |
| 110 |
int m_id; |
| 111 |
std::string m_name; |
| 112 |
|
| 113 |
static const unsigned int max_amounts = 6; // Must be at least 6 |
| 114 |
float m_amount[max_amounts] = {}; |
| 115 |
|
| 116 |
float m_repeat = 0.0f; |
| 117 |
unsigned int m_holdTime = 0; |
| 118 |
unsigned int m_buttonCode = 0; |
| 119 |
wchar_t m_unicode = 0; |
| 120 |
std::string m_text; |
| 121 |
}; |