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 17 /*! 18 \ingroup actionkeys 19 \brief class encapsulating information regarding a particular user action to be sent to windows 20 and controls 21 */ 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 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 CAction(const CAction & other)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 */ GetID()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 */ GetName()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 */ GetText()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 */ SetText(const std::string & text)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 */ GetUnicode()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 */ GetHoldTime()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 */ GetRepeat()100 float GetRepeat() const { return m_repeat; }; 101 102 /*! \brief Button code that triggered this action 103 \return button code 104 */ GetButtonCode()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 }; 122 123 #endif 124