xbmc
GUISliderControl.h
Go to the documentation of this 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 
9 #pragma once
10 
16 #include "GUIControl.h"
17 #include "GUITexture.h"
18 
19 #include <array>
20 
21 #define SLIDER_CONTROL_TYPE_INT 1
22 #define SLIDER_CONTROL_TYPE_FLOAT 2
23 #define SLIDER_CONTROL_TYPE_PERCENTAGE 3
24 
25 typedef struct
26 {
27  const char *action;
28  const char *formatString;
29  int infoCode;
30  bool fireOnDrag;
31 } SliderAction;
32 
38  public CGUIControl
39 {
40 public:
41  typedef enum {
42  RangeSelectorLower = 0,
43  RangeSelectorUpper = 1
44  } RangeSelector;
45 
46  CGUISliderControl(int parentID,
47  int controlID,
48  float posX,
49  float posY,
50  float width,
51  float height,
52  const CTextureInfo& backGroundTexture,
53  const CTextureInfo& backGroundTextureDisabled,
54  const CTextureInfo& mibTexture,
55  const CTextureInfo& nibTextureFocus,
56  const CTextureInfo& nibTextureDisabled,
57  int iType,
58  ORIENTATION orientationconst);
59  ~CGUISliderControl() override = default;
60  CGUISliderControl* Clone() const override { return new CGUISliderControl(*this); }
61 
62  void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions) override;
63  void Render() override;
64  bool OnAction(const CAction &action) override;
65  virtual bool IsActive() const { return true; }
66  void AllocResources() override;
67  void FreeResources(bool immediately = false) override;
68  void DynamicResourceAlloc(bool bOnOff) override;
69  void SetInvalid() override;
70  virtual void SetRange(int iStart, int iEnd);
71  virtual void SetFloatRange(float fStart, float fEnd);
72  bool OnMessage(CGUIMessage& message) override;
73  bool ProcessSelector(CGUITexture* background,
74  CGUITexture* nib,
75  unsigned int currentTime,
76  float fScale,
77  RangeSelector selector);
78  void SetRangeSelection(bool rangeSelection);
79  bool GetRangeSelection() const { return m_rangeSelection; }
80  void SetRangeSelector(RangeSelector selector);
81  void SwitchRangeSelector();
82  void SetInfo(int iInfo);
83  void SetPercentage(float iPercent, RangeSelector selector = RangeSelectorLower, bool updateCurrent = false);
84  float GetPercentage(RangeSelector selector = RangeSelectorLower) const;
85  void SetIntValue(int iValue, RangeSelector selector = RangeSelectorLower, bool updateCurrent = false);
86  int GetIntValue(RangeSelector selector = RangeSelectorLower) const;
87  void SetFloatValue(float fValue, RangeSelector selector = RangeSelectorLower, bool updateCurrent = false);
88  float GetFloatValue(RangeSelector selector = RangeSelectorLower) const;
89  void SetIntInterval(int iInterval);
90  void SetFloatInterval(float fInterval);
91  void SetType(int iType) { m_iType = iType; }
92  int GetType() const { return m_iType; }
93  std::string GetDescription() const override;
94  void SetTextValue(const std::string& textValue) { m_textValue = textValue; }
95  void SetAction(const std::string &action);
96 
97 protected:
98  CGUISliderControl(const CGUISliderControl& control);
99 
100  bool HitTest(const CPoint &point) const override;
101  EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event) override;
102  bool UpdateColors(const CGUIListItem* item) override;
103  virtual void Move(int iNumSteps);
104  virtual void SetFromPosition(const CPoint &point, bool guessSelector = false);
108  float GetProportion(RangeSelector selector = RangeSelectorLower) const;
109 
112  void SendClick();
113 
114  std::unique_ptr<CGUITexture> m_guiBackground;
115  std::unique_ptr<CGUITexture> m_guiBackgroundDisabled;
116  std::unique_ptr<CGUITexture> m_guiSelectorLower;
117  std::unique_ptr<CGUITexture> m_guiSelectorUpper;
118  std::unique_ptr<CGUITexture> m_guiSelectorLowerFocus;
119  std::unique_ptr<CGUITexture> m_guiSelectorUpperFocus;
120  std::unique_ptr<CGUITexture> m_guiSelectorLowerDisabled;
121  std::unique_ptr<CGUITexture> m_guiSelectorUpperDisabled;
122  int m_iType;
123 
124  bool m_rangeSelection;
125  RangeSelector m_currentSelector;
126 
127  std::array<float, 2> m_percentValues;
128 
129  std::array<int, 2> m_intValues;
130  int m_iStart;
131  int m_iInterval;
132  int m_iEnd;
133 
134  std::array<float, 2> m_floatValues;
135  float m_fStart;
136  float m_fInterval;
137  float m_fEnd;
138 
139  int m_iInfoCode;
140  std::string m_textValue;
142  bool m_dragging;
143  ORIENTATION m_orientation;
144 };
145 
Definition: GUISliderControl.h:25
std::string m_textValue
Allows overriding of the text value to be displayed (parent must update when the slider updates) ...
Definition: GUISliderControl.h:140
Definition: GUIListItem.h:30
bool HitTest(const CPoint &point) const override
Used to test whether the point is inside a control.
Definition: GUISliderControl.cpp:620
EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event) override
Perform a mouse action.
Definition: GUISliderControl.cpp:679
Base class for controls.
Definition: GUIControl.h:75
EVENT_RESULT
Results of OnMouseEvent() Any value not equal to EVENT_RESULT_UNHANDLED indicates that the event was ...
Definition: GUIControl.h:60
bool m_dragging
Whether we&#39;re in a (mouse/touch) drag operation or not - some actions are sent only on release...
Definition: GUISliderControl.h:142
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
const SliderAction * m_action
Allows the skin to configure the action of a click on the slider.
Definition: GUISliderControl.h:141
Definition: GUITexture.h:51
Definition: GUITexture.h:73
Definition: GUIMessage.h:365
Definition: GUISliderControl.h:37
void SendClick()
Send a click message (and/or action) to the app in response to a slider move.
Definition: GUISliderControl.cpp:376
float GetProportion(RangeSelector selector=RangeSelectorLower) const
Get the current position of the slider as a proportion.
Definition: GUISliderControl.cpp:796
Simple class for mouse events.
Definition: Key.h:114