[Test] Added tests for CUtil::SplitParams
[xbmc.git] / xbmc / guilib / GUISettingsSliderControl.cpp
blob1eb0e0e93ede0413155abe9f093fe6d6944d76a8
1 /*
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.
7 */
9 #include "GUISettingsSliderControl.h"
11 #include "input/actions/Action.h"
12 #include "input/actions/ActionIDs.h"
13 #include "input/mouse/MouseEvent.h"
15 using namespace KODI;
17 CGUISettingsSliderControl::CGUISettingsSliderControl(int parentID,
18 int controlID,
19 float posX,
20 float posY,
21 float width,
22 float height,
23 float sliderWidth,
24 float sliderHeight,
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,
33 int iType)
34 : CGUISliderControl(parentID,
35 controlID,
36 posX,
37 posY,
38 sliderWidth,
39 sliderHeight,
40 backGroundTexture,
41 backGroundTextureDisabled,
42 nibTexture,
43 nibTextureFocus,
44 nibTextureDisabled,
45 iType,
46 HORIZONTAL),
47 m_buttonControl(
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;
53 m_active = false;
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)
66 if (m_bInvalidated)
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);
76 ProcessText();
77 CGUISliderControl::Process(currentTime, dirtyregions);
80 void CGUISettingsSliderControl::Render()
82 m_buttonControl.Render();
83 CGUISliderControl::Render();
84 m_label.Render();
87 void CGUISettingsSliderControl::ProcessText()
89 bool changed = false;
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());
93 if (IsDisabled())
94 changed |= m_label.SetColor(CGUILabel::COLOR_DISABLED);
95 else if (HasFocus())
96 changed |= m_label.SetColor(CGUILabel::COLOR_FOCUSED);
97 else
98 changed |= m_label.SetColor(CGUILabel::COLOR_TEXT);
100 if (changed)
101 MarkDirtyRegion();
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)
109 if (!IsActive())
110 m_active = true;
111 // switch between the two sliders
112 else if (m_rangeSelection && m_currentSelector == RangeSelectorLower)
113 SwitchRangeSelector();
114 else
116 m_active = false;
117 if (m_rangeSelection)
118 SwitchRangeSelector();
120 return true;
122 return CGUISliderControl::OnAction(action);
125 void CGUISettingsSliderControl::OnUnFocus()
127 m_active = false;
130 EVENT_RESULT CGUISettingsSliderControl::OnMouseEvent(const CPoint& point,
131 const MOUSE::CMouseEvent& event)
133 SetActive();
134 return CGUISliderControl::OnMouseEvent(point, event);
137 void CGUISettingsSliderControl::SetActive()
139 m_active = true;
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();
202 return changed;