xbmc
Action.h
1 /*
2  * Copyright (C) 2005-2018 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 #ifndef SWIG
14 
15 class CKey;
16 
22 class CAction
23 {
24 public:
25  CAction();
26  CAction(int actionID,
27  float amount1 = 1.0f,
28  float amount2 = 0.0f,
29  const std::string& name = "",
30  unsigned int holdTime = 0,
31  unsigned int buttonCode = 0);
32  CAction(int actionID, wchar_t unicode);
33  CAction(int actionID,
34  unsigned int state,
35  float posX,
36  float posY,
37  float offsetX,
38  float offsetY,
39  float velocityX = 0.0f,
40  float velocityY = 0.0f,
41  const std::string& name = "");
42  CAction(int actionID, const std::string& name, const CKey& key);
43  CAction(int actionID, const std::string& name);
44 
45  CAction(const CAction& other) { *this = other; }
46  CAction& operator=(const CAction& rhs);
47 
51  int GetID() const { return m_id; }
52 
56  bool IsMouse() const;
57 
58  bool IsGesture() const;
59 
63  const std::string& GetName() const { return m_name; }
64 
68  const std::string& GetText() const { return m_text; }
69 
73  void SetText(const std::string& text) { m_text = text; }
74 
79  float GetAmount(unsigned int index = 0) const
80  {
81  return (index < max_amounts) ? m_amount[index] : 0;
82  };
83 
86  void ClearAmount();
87 
91  wchar_t GetUnicode() const { return m_unicode; }
92 
96  unsigned int GetHoldTime() const { return m_holdTime; }
97 
101  float GetRepeat() const { return m_repeat; }
102 
106  unsigned int GetButtonCode() const { return m_buttonCode; }
107 
108  bool IsAnalog() const;
109 
110 private:
111  int m_id;
112  std::string m_name;
113 
114  static const unsigned int max_amounts = 6; // Must be at least 6
115  float m_amount[max_amounts] = {};
116 
117  float m_repeat = 0.0f;
118  unsigned int m_holdTime = 0;
119  unsigned int m_buttonCode = 0;
120  wchar_t m_unicode = 0;
121  std::string m_text;
122 };
123 
124 #endif
float GetRepeat() const
Time since last repeat in ms.
Definition: Action.h:101
void ClearAmount()
Reset all amount values to zero.
Definition: Action.cpp:136
int GetID() const
Identifier of the action.
Definition: Action.h:51
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
unsigned int GetHoldTime() const
Time in ms that the key has been held.
Definition: Action.h:96
unsigned int GetButtonCode() const
Button code that triggered this action.
Definition: Action.h:106
void SetText(const std::string &text)
Set the text payload of the action.
Definition: Action.h:73
wchar_t GetUnicode() const
Unicode value associated with this action.
Definition: Action.h:91
float GetAmount(unsigned int index=0) const
Get an amount associated with this action.
Definition: Action.h:79
bool IsMouse() const
Is this an action from the mouse.
Definition: Action.cpp:142
Definition: Key.h:135
const std::string & GetText() const
Text of the action if any.
Definition: Action.h:68
const std::string & GetName() const
Human-readable name of the action.
Definition: Action.h:63