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