Merge pull request #25922 from sarbes/shader-cleanup
[xbmc.git] / xbmc / guilib / GUIControlFactory.h
blobe6e01e162de0bac3039ce075bac15869fbeb0c5e
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 #pragma once
11 /*!
12 \file GUIControlFactory.h
13 \brief
16 #include "GUIControl.h"
17 #include "utils/ColorUtils.h"
18 #include "utils/MovingSpeed.h"
20 #include <string>
21 #include <vector>
23 class CTextureInfo; // forward
24 class CAspectRatio;
25 class TiXmlElement;
26 class TiXmlNode;
27 class CGUIAction;
29 namespace KODI
31 namespace GUILIB
33 namespace GUIINFO
35 class CGUIInfoLabel;
37 } // namespace GUILIB
38 } // namespace KODI
40 /*!
41 \ingroup controls
42 \brief
44 class CGUIControlFactory
46 public:
47 CGUIControlFactory(void);
48 virtual ~CGUIControlFactory(void);
49 CGUIControl* Create(int parentID,
50 const CRect& rect,
51 TiXmlElement* pControlNode,
52 bool insideContainer = false);
54 /*! \brief translate from control name to control type
55 \param type name of the control
56 \return type of control
58 static CGUIControl::GUICONTROLTYPES TranslateControlType(const std::string& type);
60 /*! \brief translate from control type to control name
61 \param type type of the control
62 \return name of control
64 static std::string TranslateControlType(CGUIControl::GUICONTROLTYPES type);
66 static bool GetAspectRatio(const TiXmlNode* pRootNode,
67 const char* strTag,
68 CAspectRatio& aspectRatio);
69 static bool GetInfoTexture(const TiXmlNode* pRootNode,
70 const char* strTag,
71 CTextureInfo& image,
72 KODI::GUILIB::GUIINFO::CGUIInfoLabel& info,
73 int parentID);
74 static bool GetTexture(const TiXmlNode* pRootNode, const char* strTag, CTextureInfo& image);
75 static bool GetAlignment(const TiXmlNode* pRootNode, const char* strTag, uint32_t& dwAlignment);
76 static bool GetAlignmentY(const TiXmlNode* pRootNode, const char* strTag, uint32_t& dwAlignment);
77 static bool GetAnimations(TiXmlNode* control,
78 const CRect& rect,
79 int context,
80 std::vector<CAnimation>& animation);
82 /*! \brief Create an info label from an XML element
83 Processes XML elements of the form
84 <xmltag fallback="fallback_value">info_value</xmltag>
85 where info_value may use $INFO[], $LOCALIZE[], $NUMBER[] etc.
86 If either the fallback_value or info_value are natural numbers they are interpreted
87 as ids for lookup in strings.po. The fallback attribute is optional.
88 \param element XML element to process
89 \param infoLabel Returned infoLabel
90 \param parentID The parent id
91 \return true if a valid info label was read, false otherwise
94 /*! \brief Parse a position string
95 Handles strings of the form
96 ### number of pixels
97 ###r number of pixels measured from the right
98 ###% percentage of parent size
99 \param pos the string to parse.
100 \param parentSize the size of the parent.
101 \sa GetPosition
103 static float ParsePosition(const char* pos, const float parentSize);
105 static bool GetInfoLabelFromElement(const TiXmlElement* element,
106 KODI::GUILIB::GUIINFO::CGUIInfoLabel& infoLabel,
107 int parentID);
108 static void GetInfoLabel(const TiXmlNode* pControlNode,
109 const std::string& labelTag,
110 KODI::GUILIB::GUIINFO::CGUIInfoLabel& infoLabel,
111 int parentID);
112 static void GetInfoLabels(const TiXmlNode* pControlNode,
113 const std::string& labelTag,
114 std::vector<KODI::GUILIB::GUIINFO::CGUIInfoLabel>& infoLabels,
115 int parentID);
116 static bool GetColor(const TiXmlNode* pRootNode,
117 const char* strTag,
118 KODI::UTILS::COLOR::Color& value);
119 static bool GetInfoColor(const TiXmlNode* pRootNode,
120 const char* strTag,
121 KODI::GUILIB::GUIINFO::CGUIInfoColor& value,
122 int parentID);
123 static std::string FilterLabel(const std::string& label);
124 static bool GetConditionalVisibility(const TiXmlNode* control, std::string& condition);
125 static bool GetActions(const TiXmlNode* pRootNode, const char* strTag, CGUIAction& actions);
126 static void GetRectFromString(const std::string& string, CRect& rect);
127 static bool GetHitRect(const TiXmlNode* pRootNode, CRect& rect, const CRect& parentRect);
128 static bool GetScroller(const TiXmlNode* pControlNode,
129 const std::string& scrollerTag,
130 CScroller& scroller);
132 protected:
133 static std::string GetType(const TiXmlElement* pControlNode);
134 static bool GetMovingSpeedConfig(const TiXmlNode* pRootNode,
135 const char* strTag,
136 KODI::UTILS::MOVING_SPEED::MapEventConfig& movingSpeedCfg);
137 static bool GetConditionalVisibility(const TiXmlNode* control,
138 std::string& condition,
139 std::string& allowHiddenFocus);
140 static bool GetString(const TiXmlNode* pRootNode, const char* strTag, std::string& strString);
141 static bool GetFloatRange(const TiXmlNode* pRootNode,
142 const char* strTag,
143 float& iMinValue,
144 float& iMaxValue,
145 float& iIntervalValue);
146 static bool GetIntRange(const TiXmlNode* pRootNode,
147 const char* strTag,
148 int& iMinValue,
149 int& iMaxValue,
150 int& iIntervalValue);
152 /*! \brief Get the value of a position tag from XML
153 Handles both absolute and relative values.
154 \param node the <control> XML node.
155 \param tag the XML node to parse.
156 \param parentSize the size of the parent, for relative positioning.
157 \param value [out] the returned value.
158 \sa ParsePosition, GetDimension, GetDimensions.
160 static bool GetPosition(const TiXmlNode* node,
161 const char* tag,
162 const float parentSize,
163 float& value);
165 /*! \brief grab a dimension out of the XML
167 Supports plain reading of a number (or constant) and, in addition allows "auto" as the value
168 for the dimension, whereby value is set to the max attribute (if it exists) and min is set the min
169 attribute (if it exists) or 1. Auto values are thus detected by min != 0.
171 \param node the <control> XML node to read
172 \param strTag tag within node to read
173 \param parentSize the size of the parent for relative sizing.
174 \param value value to set, or maximum value if using auto
175 \param min minimum value - set != 0 if auto is used.
176 \return true if we found and read the tag.
177 \sa GetPosition, GetDimensions, ParsePosition.
179 static bool GetDimension(
180 const TiXmlNode* node, const char* strTag, const float parentSize, float& value, float& min);
182 /*! \brief Retrieve the dimensions for a control.
184 Handles positioning based on at least 2 of left/right/center/width.
186 \param node the <control> node describing the control.
187 \param leftTag the tag that holds the left field.
188 \param rightTag the tag that holds the right field.
189 \param centerLeftTag the tag that holds the center left field.
190 \param centerRightTag the tag that holds the center right field.
191 \param widthTag the tag holding the width.
192 \param parentSize the size of the parent, for relative sizing.
193 \param pos [out] the discovered position.
194 \param width [out] the discovered width.
195 \param min_width [out] the discovered minimum width.
196 \return true if we can successfully derive the position and size, false otherwise.
197 \sa GetDimension, GetPosition, ParsePosition.
199 static bool GetDimensions(const TiXmlNode* node,
200 const char* leftTag,
201 const char* rightTag,
202 const char* centerLeftTag,
203 const char* centerRightTag,
204 const char* widthTag,
205 const float parentSize,
206 float& left,
207 float& width,
208 float& min_width);