/xbmc/guilib/GUISliderControl.h

http://github.com/xbmc/xbmc · C Header · 121 lines · 85 code · 16 blank · 20 comment · 0 complexity · d030cc3eae8866bfdf71d543cdc169cd MD5 · raw file

  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. #pragma once
  9. /*!
  10. \file GUISliderControl.h
  11. \brief
  12. */
  13. #include "GUIControl.h"
  14. #include "GUITexture.h"
  15. #define SLIDER_CONTROL_TYPE_INT 1
  16. #define SLIDER_CONTROL_TYPE_FLOAT 2
  17. #define SLIDER_CONTROL_TYPE_PERCENTAGE 3
  18. typedef struct
  19. {
  20. const char *action;
  21. const char *formatString;
  22. int infoCode;
  23. bool fireOnDrag;
  24. } SliderAction;
  25. /*!
  26. \ingroup controls
  27. \brief
  28. */
  29. class CGUISliderControl :
  30. public CGUIControl
  31. {
  32. public:
  33. typedef enum {
  34. RangeSelectorLower = 0,
  35. RangeSelectorUpper = 1
  36. } RangeSelector;
  37. CGUISliderControl(int parentID, int controlID, float posX, float posY, float width, float height, const CTextureInfo& backGroundTexture, const CTextureInfo& mibTexture, const CTextureInfo& nibTextureFocus, int iType, ORIENTATION orientation);
  38. ~CGUISliderControl(void) override;
  39. CGUISliderControl *Clone() const override { return new CGUISliderControl(*this); };
  40. void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions) override;
  41. void Render() override;
  42. bool OnAction(const CAction &action) override;
  43. virtual bool IsActive() const { return true; };
  44. void AllocResources() override;
  45. void FreeResources(bool immediately = false) override;
  46. void DynamicResourceAlloc(bool bOnOff) override;
  47. void SetInvalid() override;
  48. virtual void SetRange(int iStart, int iEnd);
  49. virtual void SetFloatRange(float fStart, float fEnd);
  50. bool OnMessage(CGUIMessage& message) override;
  51. bool ProcessSelector(CGUITexture &nib, unsigned int currentTime, float fScale, RangeSelector selector);
  52. void SetRangeSelection(bool rangeSelection);
  53. bool GetRangeSelection() const { return m_rangeSelection; }
  54. void SetRangeSelector(RangeSelector selector);
  55. void SwitchRangeSelector();
  56. void SetInfo(int iInfo);
  57. void SetPercentage(float iPercent, RangeSelector selector = RangeSelectorLower, bool updateCurrent = false);
  58. float GetPercentage(RangeSelector selector = RangeSelectorLower) const;
  59. void SetIntValue(int iValue, RangeSelector selector = RangeSelectorLower, bool updateCurrent = false);
  60. int GetIntValue(RangeSelector selector = RangeSelectorLower) const;
  61. void SetFloatValue(float fValue, RangeSelector selector = RangeSelectorLower, bool updateCurrent = false);
  62. float GetFloatValue(RangeSelector selector = RangeSelectorLower) const;
  63. void SetIntInterval(int iInterval);
  64. void SetFloatInterval(float fInterval);
  65. void SetType(int iType) { m_iType = iType; };
  66. int GetType() const { return m_iType; }
  67. std::string GetDescription() const override;
  68. void SetTextValue(const std::string &textValue) { m_textValue = textValue; };
  69. void SetAction(const std::string &action);
  70. protected:
  71. bool HitTest(const CPoint &point) const override;
  72. EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event) override;
  73. bool UpdateColors() override;
  74. virtual void Move(int iNumSteps);
  75. virtual void SetFromPosition(const CPoint &point, bool guessSelector = false);
  76. /*! \brief Get the current position of the slider as a proportion
  77. \return slider position in the range [0,1]
  78. */
  79. float GetProportion(RangeSelector selector = RangeSelectorLower) const;
  80. /*! \brief Send a click message (and/or action) to the app in response to a slider move
  81. */
  82. void SendClick();
  83. CGUITexture m_guiBackground;
  84. CGUITexture m_guiSelectorLower;
  85. CGUITexture m_guiSelectorUpper;
  86. CGUITexture m_guiSelectorLowerFocus;
  87. CGUITexture m_guiSelectorUpperFocus;
  88. int m_iType;
  89. bool m_rangeSelection;
  90. RangeSelector m_currentSelector;
  91. float m_percentValues[2];
  92. int m_intValues[2];
  93. int m_iStart;
  94. int m_iInterval;
  95. int m_iEnd;
  96. float m_floatValues[2];
  97. float m_fStart;
  98. float m_fInterval;
  99. float m_fEnd;
  100. int m_iInfoCode;
  101. std::string m_textValue; ///< Allows overriding of the text value to be displayed (parent must update when the slider updates)
  102. const SliderAction *m_action; ///< Allows the skin to configure the action of a click on the slider \sa SendClick
  103. bool m_dragging; ///< Whether we're in a (mouse/touch) drag operation or not - some actions are sent only on release.
  104. ORIENTATION m_orientation;
  105. };