[WASAPI] fix stream types and frequencies enumeration
[xbmc.git] / xbmc / guilib / GUISpinControlEx.cpp
blob709c2af29ec89afcc2ee085bb9e6b2169664f153
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 "GUISpinControlEx.h"
11 #include "utils/StringUtils.h"
13 CGUISpinControlEx::CGUISpinControlEx(int parentID, int controlID, float posX, float posY, float width, float height, float spinWidth, float spinHeight, const CLabelInfo& spinInfo, const CTextureInfo &textureFocus, const CTextureInfo &textureNoFocus, const CTextureInfo& textureUp, const CTextureInfo& textureDown, const CTextureInfo& textureUpFocus, const CTextureInfo& textureDownFocus, const CTextureInfo& textureUpDisabled, const CTextureInfo& textureDownDisabled, const CLabelInfo& labelInfo, int iType)
14 : CGUISpinControl(parentID, controlID, posX, posY, spinWidth, spinHeight, textureUp, textureDown, textureUpFocus, textureDownFocus, textureUpDisabled, textureDownDisabled, spinInfo, iType)
15 , m_buttonControl(parentID, controlID, posX, posY, width, height, textureFocus, textureNoFocus, labelInfo)
17 ControlType = GUICONTROL_SPINEX;
18 m_spinPosX = 0;
21 CGUISpinControlEx::~CGUISpinControlEx(void) = default;
23 void CGUISpinControlEx::AllocResources()
25 // Correct alignment - we always align the spincontrol on the right
26 m_label.GetLabelInfo().align = (m_label.GetLabelInfo().align & XBFONT_CENTER_Y) | XBFONT_RIGHT;
27 CGUISpinControl::AllocResources();
28 m_buttonControl.AllocResources();
29 if (m_height == 0)
30 m_height = GetSpinHeight();
33 void CGUISpinControlEx::FreeResources(bool immediately)
35 CGUISpinControl::FreeResources(immediately);
36 m_buttonControl.FreeResources(immediately);
39 void CGUISpinControlEx::DynamicResourceAlloc(bool bOnOff)
41 CGUISpinControl::DynamicResourceAlloc(bOnOff);
42 m_buttonControl.DynamicResourceAlloc(bOnOff);
46 void CGUISpinControlEx::SetInvalid()
48 CGUISpinControl::SetInvalid();
49 m_buttonControl.SetInvalid();
52 void CGUISpinControlEx::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
54 // make sure the button has focus if it should have...
55 m_buttonControl.SetFocus(HasFocus());
56 m_buttonControl.SetPulseOnSelect(m_pulseOnSelect);
57 m_buttonControl.SetEnabled(m_enabled);
58 if (m_bInvalidated)
60 float spinPosX = m_buttonControl.GetXPosition() + m_buttonControl.GetWidth() - GetSpinWidth() * 2 - (m_spinPosX ? m_spinPosX : m_buttonControl.GetLabelInfo().offsetX);
61 float spinPosY = m_buttonControl.GetYPosition() + (m_buttonControl.GetHeight() - GetSpinHeight()) * 0.5f;
62 CGUISpinControl::SetPosition(spinPosX, spinPosY);
64 m_buttonControl.DoProcess(currentTime, dirtyregions);
65 CGUISpinControl::Process(currentTime, dirtyregions);
68 void CGUISpinControlEx::Render()
70 CGUISpinControl::Render();
73 void CGUISpinControlEx::SetPosition(float posX, float posY)
75 m_buttonControl.SetPosition(posX, posY);
76 CGUISpinControl::SetInvalid();
79 void CGUISpinControlEx::SetWidth(float width)
81 m_buttonControl.SetWidth(width);
82 CGUISpinControl::SetInvalid();
85 void CGUISpinControlEx::SetHeight(float height)
87 m_buttonControl.SetHeight(height);
88 CGUISpinControl::SetInvalid();
91 bool CGUISpinControlEx::UpdateColors(const CGUIListItem* item)
93 bool changed = CGUISpinControl::UpdateColors(nullptr);
94 changed |= m_buttonControl.SetColorDiffuse(m_diffuseColor);
95 changed |= m_buttonControl.UpdateColors(nullptr);
97 return changed;
100 void CGUISpinControlEx::SetEnabled(bool bEnable)
102 m_buttonControl.SetEnabled(bEnable);
103 CGUISpinControl::SetEnabled(bEnable);
106 const std::string CGUISpinControlEx::GetCurrentLabel() const
108 return CGUISpinControl::GetLabel();
111 std::string CGUISpinControlEx::GetDescription() const
113 return StringUtils::Format("{} ({})", m_buttonControl.GetDescription(), GetLabel());
116 void CGUISpinControlEx::SetItemInvalid(bool invalid)
118 if (invalid)
120 m_label.GetLabelInfo().textColor = m_buttonControl.GetLabelInfo().disabledColor;
121 m_label.GetLabelInfo().focusedColor = m_buttonControl.GetLabelInfo().disabledColor;
123 else
125 m_label.GetLabelInfo().textColor = m_buttonControl.GetLabelInfo().textColor;
126 m_label.GetLabelInfo().focusedColor = m_buttonControl.GetLabelInfo().focusedColor;
130 void CGUISpinControlEx::SetSpinPosition(float spinPosX)
132 m_spinPosX = spinPosX;
133 SetPosition(m_buttonControl.GetXPosition(), m_buttonControl.GetYPosition());
136 void CGUISpinControlEx::RenderText(float posX, float posY, float width, float height)
138 const float freeSpaceWidth{m_buttonControl.GetWidth() - GetSpinWidth() * 2};
140 // Limit right label text width to max 50% of free space
141 // (will be slightly shifted due to offsetX padding)
142 const float rightTextMaxWidth{freeSpaceWidth * 0.5f};
144 float rightTextWidth{width};
145 if (rightTextWidth > rightTextMaxWidth)
147 rightTextWidth = rightTextMaxWidth - m_label.GetLabelInfo().offsetX;
150 m_label.SetScrolling(HasFocus());
151 // Replace posX by using our button position
152 posX = m_buttonControl.GetXPosition() + freeSpaceWidth - rightTextWidth -
153 m_label.GetLabelInfo().offsetX;
155 // Limit the max width for the left label to avoid text overlapping
156 m_buttonControl.SetMaxWidth(posX + m_label.GetLabelInfo().offsetX);
157 m_buttonControl.Render();
159 CGUISpinControl::RenderText(posX, m_buttonControl.GetYPosition(), rightTextWidth,
160 m_buttonControl.GetHeight());