[Windows] Fix driver version detection of AMD RDNA+ GPU on Windows 10
[xbmc.git] / xbmc / guilib / GUIColorButtonControl.cpp
blob1e40667cfcb18f693069b65d7811df6359e7a0ab
1 /*
2 * Copyright (C) 2005-2021 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 "GUIColorButtonControl.h"
11 #include "GUIInfoManager.h"
12 #include "LocalizeStrings.h"
13 #include "input/keyboard/Key.h"
14 #include "utils/ColorUtils.h"
15 #include "utils/StringUtils.h"
17 using namespace KODI;
18 using namespace GUILIB;
20 CGUIColorButtonControl::CGUIColorButtonControl(int parentID,
21 int controlID,
22 float posX,
23 float posY,
24 float width,
25 float height,
26 const CTextureInfo& textureFocus,
27 const CTextureInfo& textureNoFocus,
28 const CLabelInfo& labelInfo,
29 const CTextureInfo& colorMask,
30 const CTextureInfo& colorDisabledMask)
31 : CGUIButtonControl(
32 parentID, controlID, posX, posY, width, height, textureFocus, textureNoFocus, labelInfo),
33 m_imgColorMask(CGUITexture::CreateTexture(posX, posY, 16, 16, colorMask)),
34 m_imgColorDisabledMask(CGUITexture::CreateTexture(posX, posY, 16, 16, colorDisabledMask)),
35 m_labelInfo(posX, posY, width, height, labelInfo, CGUILabel::OVER_FLOW_SCROLL)
37 m_colorPosX = 0;
38 m_colorPosY = 0;
39 m_imgColorMask->SetAspectRatio(CAspectRatio::AR_KEEP);
40 m_imgColorDisabledMask->SetAspectRatio(CAspectRatio::AR_KEEP);
41 m_imgBoxColor = GUIINFO::CGUIInfoColor(UTILS::COLOR::NONE);
42 ControlType = GUICONTROL_COLORBUTTON;
43 // offsetX is like a left/right padding, "hex" label does not require high values
44 m_labelInfo.GetLabelInfo().offsetX = 2;
47 CGUIColorButtonControl::CGUIColorButtonControl(const CGUIColorButtonControl& control)
48 : CGUIButtonControl(control),
49 m_imgColorMask(control.m_imgColorMask->Clone()),
50 m_imgColorDisabledMask(control.m_imgColorDisabledMask->Clone()),
51 m_colorPosX(control.m_colorPosX),
52 m_colorPosY(control.m_colorPosY),
53 m_labelInfo(control.m_labelInfo)
57 void CGUIColorButtonControl::Render()
59 CGUIButtonControl::Render();
60 RenderInfoText();
61 if (IsDisabled())
62 m_imgColorDisabledMask->Render();
63 else
64 m_imgColorMask->Render();
67 void CGUIColorButtonControl::Process(unsigned int currentTime, CDirtyRegionList& dirtyregions)
69 ProcessInfoText(currentTime);
70 m_imgColorMask->Process(currentTime);
71 m_imgColorDisabledMask->Process(currentTime);
72 CGUIButtonControl::Process(currentTime, dirtyregions);
75 bool CGUIColorButtonControl::OnAction(const CAction& action)
77 return CGUIButtonControl::OnAction(action);
80 bool CGUIColorButtonControl::OnMessage(CGUIMessage& message)
82 return CGUIButtonControl::OnMessage(message);
85 void CGUIColorButtonControl::AllocResources()
87 CGUIButtonControl::AllocResources();
88 m_imgColorMask->AllocResources();
89 m_imgColorDisabledMask->AllocResources();
90 SetPosition(m_posX, m_posY);
93 void CGUIColorButtonControl::FreeResources(bool immediately)
95 CGUIButtonControl::FreeResources(immediately);
96 m_imgColorMask->FreeResources(immediately);
97 m_imgColorDisabledMask->FreeResources(immediately);
100 void CGUIColorButtonControl::DynamicResourceAlloc(bool bOnOff)
102 CGUIControl::DynamicResourceAlloc(bOnOff);
103 m_imgColorMask->DynamicResourceAlloc(bOnOff);
104 m_imgColorDisabledMask->DynamicResourceAlloc(bOnOff);
107 void CGUIColorButtonControl::SetInvalid()
109 CGUIButtonControl::SetInvalid();
110 m_imgColorMask->SetInvalid();
111 m_imgColorDisabledMask->SetInvalid();
112 m_labelInfo.SetInvalid();
115 void CGUIColorButtonControl::SetPosition(float posX, float posY)
117 CGUIButtonControl::SetPosition(posX, posY);
118 float colorPosX =
119 m_colorPosX ? m_posX + m_colorPosX : (m_posX + m_width) - m_imgColorMask->GetWidth();
120 float colorPosY =
121 m_colorPosY ? m_posY + m_colorPosY : m_posY + (m_height - m_imgColorMask->GetHeight()) / 2;
122 m_imgColorMask->SetPosition(colorPosX, colorPosY);
123 m_imgColorDisabledMask->SetPosition(colorPosX, colorPosY);
126 void CGUIColorButtonControl::SetColorDimensions(float posX, float posY, float width, float height)
128 m_colorPosX = posX;
129 m_colorPosY = posY;
130 if (width)
132 m_imgColorMask->SetWidth(width);
133 m_imgColorDisabledMask->SetWidth(width);
135 if (height)
137 m_imgColorMask->SetHeight(height);
138 m_imgColorDisabledMask->SetHeight(height);
140 SetPosition(GetXPosition(), GetYPosition());
143 void CGUIColorButtonControl::SetWidth(float width)
145 CGUIButtonControl::SetWidth(width);
146 SetPosition(GetXPosition(), GetYPosition());
149 void CGUIColorButtonControl::SetHeight(float height)
151 CGUIButtonControl::SetHeight(height);
152 SetPosition(GetXPosition(), GetYPosition());
155 std::string CGUIColorButtonControl::GetDescription() const
157 return CGUIButtonControl::GetDescription();
160 void CGUIColorButtonControl::SetImageBoxColor(GUIINFO::CGUIInfoColor color)
162 m_imgBoxColor = color;
165 void CGUIColorButtonControl::SetImageBoxColor(const std::string& hexColor)
167 if (hexColor.empty())
168 m_imgBoxColor = GUIINFO::CGUIInfoColor(UTILS::COLOR::NONE);
169 else
170 m_imgBoxColor = GUIINFO::CGUIInfoColor(UTILS::COLOR::ConvertHexToColor(hexColor));
173 bool CGUIColorButtonControl::UpdateColors(const CGUIListItem* item)
175 bool changed = CGUIButtonControl::UpdateColors(nullptr);
176 changed |= m_imgBoxColor.Update();
177 changed |= m_imgColorMask->SetDiffuseColor(m_imgBoxColor, item);
178 changed |= m_imgColorDisabledMask->SetDiffuseColor(m_diffuseColor);
179 changed |= m_labelInfo.UpdateColors();
180 return changed;
183 void CGUIColorButtonControl::RenderInfoText()
185 m_labelInfo.Render();
188 void CGUIColorButtonControl::ProcessInfoText(unsigned int currentTime)
190 CRect labelRenderRect = m_labelInfo.GetRenderRect();
191 bool changed = m_labelInfo.SetText(
192 StringUtils::Format("#{:08X}", static_cast<UTILS::COLOR::Color>(m_imgBoxColor)));
193 // Set Label X position based on image mask control position
194 float textWidth = m_labelInfo.GetTextWidth() + 2 * m_labelInfo.GetLabelInfo().offsetX;
195 float textPosX = m_imgColorMask->GetXPosition() - textWidth;
196 changed = m_labelInfo.SetMaxRect(textPosX, m_posY, textWidth, m_height);
197 // Limit the width for the left label to avoid text overlapping
198 SetMaxWidth(textPosX);
200 // text changed - images need resizing
201 if (m_minWidth && (m_labelInfo.GetRenderRect() != labelRenderRect))
202 SetInvalid();
204 changed |= m_labelInfo.SetColor(GetTextColor());
205 changed |= m_labelInfo.Process(currentTime);
206 if (changed)
207 MarkDirtyRegion();
210 CGUILabel::COLOR CGUIColorButtonControl::GetTextColor() const
212 if (IsDisabled())
213 return CGUILabel::COLOR_DISABLED;
214 if (HasFocus())
215 return CGUILabel::COLOR_FOCUSED;
216 return CGUILabel::COLOR_TEXT;