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