2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "GUISettingsSliderControl.h"
11 #include "input/actions/Action.h"
12 #include "input/actions/ActionIDs.h"
13 #include "input/mouse/MouseEvent.h"
17 CGUISettingsSliderControl::CGUISettingsSliderControl(int parentID
,
25 const CTextureInfo
& textureFocus
,
26 const CTextureInfo
& textureNoFocus
,
27 const CTextureInfo
& backGroundTexture
,
28 const CTextureInfo
& backGroundTextureDisabled
,
29 const CTextureInfo
& nibTexture
,
30 const CTextureInfo
& nibTextureFocus
,
31 const CTextureInfo
& nibTextureDisabled
,
32 const CLabelInfo
& labelInfo
,
34 : CGUISliderControl(parentID
,
41 backGroundTextureDisabled
,
48 parentID
, controlID
, posX
, posY
, width
, height
, textureFocus
, textureNoFocus
, labelInfo
),
49 m_label(posX
, posY
, width
, height
, labelInfo
)
51 m_label
.SetAlign((labelInfo
.align
& XBFONT_CENTER_Y
) | XBFONT_RIGHT
);
52 ControlType
= GUICONTROL_SETTINGS_SLIDER
;
56 CGUISettingsSliderControl::CGUISettingsSliderControl(const CGUISettingsSliderControl
& control
)
57 : CGUISliderControl(control
),
58 m_buttonControl(control
.m_buttonControl
),
59 m_label(control
.m_label
),
60 m_active(control
.m_active
)
64 void CGUISettingsSliderControl::Process(unsigned int currentTime
, CDirtyRegionList
&dirtyregions
)
68 float sliderPosX
= m_buttonControl
.GetXPosition() + m_buttonControl
.GetWidth() - m_width
- m_buttonControl
.GetLabelInfo().offsetX
;
69 float sliderPosY
= m_buttonControl
.GetYPosition() + (m_buttonControl
.GetHeight() - m_height
) * 0.5f
;
70 CGUISliderControl::SetPosition(sliderPosX
, sliderPosY
);
72 m_buttonControl
.SetFocus(HasFocus());
73 m_buttonControl
.SetPulseOnSelect(m_pulseOnSelect
);
74 m_buttonControl
.SetEnabled(m_enabled
);
75 m_buttonControl
.DoProcess(currentTime
, dirtyregions
);
77 CGUISliderControl::Process(currentTime
, dirtyregions
);
80 void CGUISettingsSliderControl::Render()
82 m_buttonControl
.Render();
83 CGUISliderControl::Render();
87 void CGUISettingsSliderControl::ProcessText()
91 changed
|= m_label
.SetMaxRect(m_buttonControl
.GetXPosition(), m_buttonControl
.GetYPosition(), m_posX
- m_buttonControl
.GetXPosition(), m_buttonControl
.GetHeight());
92 changed
|= m_label
.SetText(CGUISliderControl::GetDescription());
94 changed
|= m_label
.SetColor(CGUILabel::COLOR_DISABLED
);
96 changed
|= m_label
.SetColor(CGUILabel::COLOR_FOCUSED
);
98 changed
|= m_label
.SetColor(CGUILabel::COLOR_TEXT
);
104 bool CGUISettingsSliderControl::OnAction(const CAction
&action
)
106 // intercept ACTION_SELECT_ITEM because onclick functionality is different from base class
107 if (action
.GetID() == ACTION_SELECT_ITEM
)
111 // switch between the two sliders
112 else if (m_rangeSelection
&& m_currentSelector
== RangeSelectorLower
)
113 SwitchRangeSelector();
117 if (m_rangeSelection
)
118 SwitchRangeSelector();
122 return CGUISliderControl::OnAction(action
);
125 void CGUISettingsSliderControl::OnUnFocus()
130 EVENT_RESULT
CGUISettingsSliderControl::OnMouseEvent(const CPoint
& point
,
131 const MOUSE::CMouseEvent
& event
)
134 return CGUISliderControl::OnMouseEvent(point
, event
);
137 void CGUISettingsSliderControl::SetActive()
142 void CGUISettingsSliderControl::FreeResources(bool immediately
)
144 CGUISliderControl::FreeResources(immediately
);
145 m_buttonControl
.FreeResources(immediately
);
148 void CGUISettingsSliderControl::DynamicResourceAlloc(bool bOnOff
)
150 CGUISliderControl::DynamicResourceAlloc(bOnOff
);
151 m_buttonControl
.DynamicResourceAlloc(bOnOff
);
154 void CGUISettingsSliderControl::AllocResources()
156 CGUISliderControl::AllocResources();
157 m_buttonControl
.AllocResources();
160 void CGUISettingsSliderControl::SetInvalid()
162 CGUISliderControl::SetInvalid();
163 m_buttonControl
.SetInvalid();
166 void CGUISettingsSliderControl::SetPosition(float posX
, float posY
)
168 m_buttonControl
.SetPosition(posX
, posY
);
169 CGUISliderControl::SetInvalid();
172 void CGUISettingsSliderControl::SetWidth(float width
)
174 m_buttonControl
.SetWidth(width
);
175 CGUISliderControl::SetInvalid();
178 void CGUISettingsSliderControl::SetHeight(float height
)
180 m_buttonControl
.SetHeight(height
);
181 CGUISliderControl::SetInvalid();
184 void CGUISettingsSliderControl::SetEnabled(bool bEnable
)
186 CGUISliderControl::SetEnabled(bEnable
);
187 m_buttonControl
.SetEnabled(bEnable
);
190 std::string
CGUISettingsSliderControl::GetDescription() const
192 return m_buttonControl
.GetDescription() + " " + CGUISliderControl::GetDescription();
195 bool CGUISettingsSliderControl::UpdateColors(const CGUIListItem
* item
)
197 bool changed
= CGUISliderControl::UpdateColors(nullptr);
198 changed
|= m_buttonControl
.SetColorDiffuse(m_diffuseColor
);
199 changed
|= m_buttonControl
.UpdateColors(nullptr);
200 changed
|= m_label
.UpdateColors();