From 72a84479baab56bfe1b97d5d9acacb69fb6cbeb2 Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Sat, 21 Oct 2023 18:29:38 -0700 Subject: [PATCH] Format GUIControlFactory.cpp/h --- xbmc/guilib/GUIControlFactory.cpp | 612 +++++++++++++++++------------- xbmc/guilib/GUIControlFactory.h | 104 +++-- 2 files changed, 420 insertions(+), 296 deletions(-) diff --git a/xbmc/guilib/GUIControlFactory.cpp b/xbmc/guilib/GUIControlFactory.cpp index 5b81a57677e65..20ab02cda8f98 100644 --- a/xbmc/guilib/GUIControlFactory.cpp +++ b/xbmc/guilib/GUIControlFactory.cpp @@ -106,7 +106,7 @@ static const ControlMapping controls[] = { {"wraplist", CGUIControl::GUICONTAINER_WRAPLIST}, }; -CGUIControl::GUICONTROLTYPES CGUIControlFactory::TranslateControlType(const std::string &type) +CGUIControl::GUICONTROLTYPES CGUIControlFactory::TranslateControlType(const std::string& type) { for (const ControlMapping& control : controls) if (StringUtils::EqualsNoCase(type, control.name)) @@ -126,10 +126,15 @@ CGUIControlFactory::CGUIControlFactory(void) = default; CGUIControlFactory::~CGUIControlFactory(void) = default; -bool CGUIControlFactory::GetIntRange(const TiXmlNode* pRootNode, const char* strTag, int& iMinValue, int& iMaxValue, int& iIntervalValue) +bool CGUIControlFactory::GetIntRange(const TiXmlNode* pRootNode, + const char* strTag, + int& iMinValue, + int& iMaxValue, + int& iIntervalValue) { const TiXmlNode* pNode = pRootNode->FirstChild(strTag); - if (!pNode || !pNode->FirstChild()) return false; + if (!pNode || !pNode->FirstChild()) + return false; iMinValue = atoi(pNode->FirstChild()->Value()); const char* maxValue = strchr(pNode->FirstChild()->Value(), ','); if (maxValue) @@ -148,10 +153,15 @@ bool CGUIControlFactory::GetIntRange(const TiXmlNode* pRootNode, const char* str return true; } -bool CGUIControlFactory::GetFloatRange(const TiXmlNode* pRootNode, const char* strTag, float& fMinValue, float& fMaxValue, float& fIntervalValue) +bool CGUIControlFactory::GetFloatRange(const TiXmlNode* pRootNode, + const char* strTag, + float& fMinValue, + float& fMaxValue, + float& fIntervalValue) { const TiXmlNode* pNode = pRootNode->FirstChild(strTag); - if (!pNode || !pNode->FirstChild()) return false; + if (!pNode || !pNode->FirstChild()) + return false; fMinValue = (float)atof(pNode->FirstChild()->Value()); const char* maxValue = strchr(pNode->FirstChild()->Value(), ','); if (maxValue) @@ -184,33 +194,50 @@ float CGUIControlFactory::ParsePosition(const char* pos, const float parentSize) return value; } -bool CGUIControlFactory::GetPosition(const TiXmlNode *node, const char* strTag, const float parentSize, float& value) +bool CGUIControlFactory::GetPosition(const TiXmlNode* node, + const char* strTag, + const float parentSize, + float& value) { const TiXmlElement* pNode = node->FirstChildElement(strTag); - if (!pNode || !pNode->FirstChild()) return false; + if (!pNode || !pNode->FirstChild()) + return false; value = ParsePosition(pNode->FirstChild()->Value(), parentSize); return true; } -bool CGUIControlFactory::GetDimension(const TiXmlNode *pRootNode, const char* strTag, const float parentSize, float &value, float &min) +bool CGUIControlFactory::GetDimension(const TiXmlNode* pRootNode, + const char* strTag, + const float parentSize, + float& value, + float& min) { const TiXmlElement* pNode = pRootNode->FirstChildElement(strTag); - if (!pNode || !pNode->FirstChild()) return false; + if (!pNode || !pNode->FirstChild()) + return false; if (0 == StringUtils::CompareNoCase("auto", pNode->FirstChild()->Value(), 4)) { // auto-width - at least min must be set value = ParsePosition(pNode->Attribute("max"), parentSize); min = ParsePosition(pNode->Attribute("min"), parentSize); - if (!min) min = 1; + if (!min) + min = 1; return true; } value = ParsePosition(pNode->FirstChild()->Value(), parentSize); return true; } -bool CGUIControlFactory::GetDimensions(const TiXmlNode *node, const char *leftTag, const char *rightTag, const char *centerLeftTag, - const char *centerRightTag, const char *widthTag, const float parentSize, float &left, - float &width, float &min_width) +bool CGUIControlFactory::GetDimensions(const TiXmlNode* node, + const char* leftTag, + const char* rightTag, + const char* centerLeftTag, + const char* centerRightTag, + const char* widthTag, + const float parentSize, + float& left, + float& width, + float& min_width) { float center = 0, right = 0; @@ -236,7 +263,7 @@ bool CGUIControlFactory::GetDimensions(const TiXmlNode *node, const char *leftTa { if (hasWidth) { - left = center - width/2; + left = center - width / 2; hasLeft = true; } else @@ -276,7 +303,7 @@ bool CGUIControlFactory::GetDimensions(const TiXmlNode *node, const char *leftTa else if (center > 0 && center < parentSize) { // centre given, so fill to edge of parent width = std::max(0.0f, std::min(parentSize - center, center) * 2); - left = center - width/2; + left = center - width / 2; hasLeft = true; hasWidth = true; } @@ -290,34 +317,46 @@ bool CGUIControlFactory::GetDimensions(const TiXmlNode *node, const char *leftTa return hasLeft && hasWidth; } -bool CGUIControlFactory::GetAspectRatio(const TiXmlNode* pRootNode, const char* strTag, CAspectRatio &aspect) +bool CGUIControlFactory::GetAspectRatio(const TiXmlNode* pRootNode, + const char* strTag, + CAspectRatio& aspect) { std::string ratio; - const TiXmlElement *node = pRootNode->FirstChildElement(strTag); + const TiXmlElement* node = pRootNode->FirstChildElement(strTag); if (!node || !node->FirstChild()) return false; ratio = node->FirstChild()->Value(); - if (StringUtils::EqualsNoCase(ratio, "keep")) aspect.ratio = CAspectRatio::AR_KEEP; - else if (StringUtils::EqualsNoCase(ratio, "scale")) aspect.ratio = CAspectRatio::AR_SCALE; - else if (StringUtils::EqualsNoCase(ratio, "center")) aspect.ratio = CAspectRatio::AR_CENTER; - else if (StringUtils::EqualsNoCase(ratio, "stretch")) aspect.ratio = CAspectRatio::AR_STRETCH; - - const char *attribute = node->Attribute("align"); + if (StringUtils::EqualsNoCase(ratio, "keep")) + aspect.ratio = CAspectRatio::AR_KEEP; + else if (StringUtils::EqualsNoCase(ratio, "scale")) + aspect.ratio = CAspectRatio::AR_SCALE; + else if (StringUtils::EqualsNoCase(ratio, "center")) + aspect.ratio = CAspectRatio::AR_CENTER; + else if (StringUtils::EqualsNoCase(ratio, "stretch")) + aspect.ratio = CAspectRatio::AR_STRETCH; + + const char* attribute = node->Attribute("align"); if (attribute) { std::string align(attribute); - if (StringUtils::EqualsNoCase(align, "center")) aspect.align = ASPECT_ALIGN_CENTER | (aspect.align & ASPECT_ALIGNY_MASK); - else if (StringUtils::EqualsNoCase(align, "right")) aspect.align = ASPECT_ALIGN_RIGHT | (aspect.align & ASPECT_ALIGNY_MASK); - else if (StringUtils::EqualsNoCase(align, "left")) aspect.align = ASPECT_ALIGN_LEFT | (aspect.align & ASPECT_ALIGNY_MASK); + if (StringUtils::EqualsNoCase(align, "center")) + aspect.align = ASPECT_ALIGN_CENTER | (aspect.align & ASPECT_ALIGNY_MASK); + else if (StringUtils::EqualsNoCase(align, "right")) + aspect.align = ASPECT_ALIGN_RIGHT | (aspect.align & ASPECT_ALIGNY_MASK); + else if (StringUtils::EqualsNoCase(align, "left")) + aspect.align = ASPECT_ALIGN_LEFT | (aspect.align & ASPECT_ALIGNY_MASK); } attribute = node->Attribute("aligny"); if (attribute) { std::string align(attribute); - if (StringUtils::EqualsNoCase(align, "center")) aspect.align = ASPECT_ALIGNY_CENTER | (aspect.align & ASPECT_ALIGN_MASK); - else if (StringUtils::EqualsNoCase(align, "bottom")) aspect.align = ASPECT_ALIGNY_BOTTOM | (aspect.align & ASPECT_ALIGN_MASK); - else if (StringUtils::EqualsNoCase(align, "top")) aspect.align = ASPECT_ALIGNY_TOP | (aspect.align & ASPECT_ALIGN_MASK); + if (StringUtils::EqualsNoCase(align, "center")) + aspect.align = ASPECT_ALIGNY_CENTER | (aspect.align & ASPECT_ALIGN_MASK); + else if (StringUtils::EqualsNoCase(align, "bottom")) + aspect.align = ASPECT_ALIGNY_BOTTOM | (aspect.align & ASPECT_ALIGN_MASK); + else if (StringUtils::EqualsNoCase(align, "top")) + aspect.align = ASPECT_ALIGNY_TOP | (aspect.align & ASPECT_ALIGN_MASK); } attribute = node->Attribute("scalediffuse"); if (attribute) @@ -331,7 +370,11 @@ bool CGUIControlFactory::GetAspectRatio(const TiXmlNode* pRootNode, const char* return true; } -bool CGUIControlFactory::GetInfoTexture(const TiXmlNode* pRootNode, const char* strTag, CTextureInfo &image, GUIINFO::CGUIInfoLabel &info, int parentID) +bool CGUIControlFactory::GetInfoTexture(const TiXmlNode* pRootNode, + const char* strTag, + CTextureInfo& image, + GUIINFO::CGUIInfoLabel& info, + int parentID) { GetTexture(pRootNode, strTag, image); image.filename = ""; @@ -339,11 +382,14 @@ bool CGUIControlFactory::GetInfoTexture(const TiXmlNode* pRootNode, const char* return true; } -bool CGUIControlFactory::GetTexture(const TiXmlNode* pRootNode, const char* strTag, CTextureInfo &image) +bool CGUIControlFactory::GetTexture(const TiXmlNode* pRootNode, + const char* strTag, + CTextureInfo& image) { const TiXmlElement* pNode = pRootNode->FirstChildElement(strTag); - if (!pNode) return false; - const char *border = pNode->Attribute("border"); + if (!pNode) + return false; + const char* border = pNode->Attribute("border"); if (border) { GetRectFromString(border, image.border); @@ -351,22 +397,22 @@ bool CGUIControlFactory::GetTexture(const TiXmlNode* pRootNode, const char* strT image.m_infill = (!borderinfill || !StringUtils::EqualsNoCase(borderinfill, "false")); } image.orientation = 0; - const char *flipX = pNode->Attribute("flipx"); + const char* flipX = pNode->Attribute("flipx"); if (flipX && StringUtils::CompareNoCase(flipX, "true") == 0) image.orientation = 1; - const char *flipY = pNode->Attribute("flipy"); + const char* flipY = pNode->Attribute("flipy"); if (flipY && StringUtils::CompareNoCase(flipY, "true") == 0) image.orientation = 3 - image.orientation; // either 3 or 2 image.diffuse = XMLUtils::GetAttribute(pNode, "diffuse"); image.diffuseColor.Parse(XMLUtils::GetAttribute(pNode, "colordiffuse"), 0); - const char *background = pNode->Attribute("background"); + const char* background = pNode->Attribute("background"); if (background && StringUtils::CompareNoCase(background, "true", 4) == 0) image.useLarge = true; image.filename = pNode->FirstChild() ? pNode->FirstChild()->Value() : ""; return true; } -void CGUIControlFactory::GetRectFromString(const std::string &string, CRect &rect) +void CGUIControlFactory::GetRectFromString(const std::string& string, CRect& rect) { // format is rect="left[,top,right,bottom]" std::vector strRect = StringUtils::Split(string, ','); @@ -386,22 +432,31 @@ void CGUIControlFactory::GetRectFromString(const std::string &string, CRect &rec } } -bool CGUIControlFactory::GetAlignment(const TiXmlNode* pRootNode, const char* strTag, uint32_t& alignment) +bool CGUIControlFactory::GetAlignment(const TiXmlNode* pRootNode, + const char* strTag, + uint32_t& alignment) { const TiXmlNode* pNode = pRootNode->FirstChild(strTag); - if (!pNode || !pNode->FirstChild()) return false; + if (!pNode || !pNode->FirstChild()) + return false; std::string strAlign = pNode->FirstChild()->Value(); - if (strAlign == "right" || strAlign == "bottom") alignment = XBFONT_RIGHT; - else if (strAlign == "center") alignment = XBFONT_CENTER_X; - else if (strAlign == "justify") alignment = XBFONT_JUSTIFIED; - else alignment = XBFONT_LEFT; + if (strAlign == "right" || strAlign == "bottom") + alignment = XBFONT_RIGHT; + else if (strAlign == "center") + alignment = XBFONT_CENTER_X; + else if (strAlign == "justify") + alignment = XBFONT_JUSTIFIED; + else + alignment = XBFONT_LEFT; return true; } -bool CGUIControlFactory::GetAlignmentY(const TiXmlNode* pRootNode, const char* strTag, uint32_t& alignment) +bool CGUIControlFactory::GetAlignmentY(const TiXmlNode* pRootNode, + const char* strTag, + uint32_t& alignment) { - const TiXmlNode* pNode = pRootNode->FirstChild(strTag ); + const TiXmlNode* pNode = pRootNode->FirstChild(strTag); if (!pNode || !pNode->FirstChild()) { return false; @@ -418,14 +473,17 @@ bool CGUIControlFactory::GetAlignmentY(const TiXmlNode* pRootNode, const char* s return true; } -bool CGUIControlFactory::GetConditionalVisibility(const TiXmlNode* control, std::string &condition, std::string &allowHiddenFocus) +bool CGUIControlFactory::GetConditionalVisibility(const TiXmlNode* control, + std::string& condition, + std::string& allowHiddenFocus) { const TiXmlElement* node = control->FirstChildElement("visible"); - if (!node) return false; + if (!node) + return false; std::vector conditions; while (node) { - const char *hidden = node->Attribute("allowhiddenfocus"); + const char* hidden = node->Attribute("allowhiddenfocus"); if (hidden) allowHiddenFocus = hidden; // add to our condition string @@ -447,13 +505,16 @@ bool CGUIControlFactory::GetConditionalVisibility(const TiXmlNode* control, std: return true; } -bool CGUIControlFactory::GetConditionalVisibility(const TiXmlNode *control, std::string &condition) +bool CGUIControlFactory::GetConditionalVisibility(const TiXmlNode* control, std::string& condition) { std::string allowHiddenFocus; return GetConditionalVisibility(control, condition, allowHiddenFocus); } -bool CGUIControlFactory::GetAnimations(TiXmlNode *control, const CRect &rect, int context, std::vector &animations) +bool CGUIControlFactory::GetAnimations(TiXmlNode* control, + const CRect& rect, + int context, + std::vector& animations) { TiXmlElement* node = control->FirstChildElement("animation"); bool ret = false; @@ -471,8 +532,8 @@ bool CGUIControlFactory::GetAnimations(TiXmlNode *control, const CRect &rect, in { // add the hidden one as well TiXmlElement hidden(*node); hidden.FirstChild()->SetValue("hidden"); - const char *start = hidden.Attribute("start"); - const char *end = hidden.Attribute("end"); + const char* start = hidden.Attribute("start"); + const char* end = hidden.Attribute("end"); if (start && end) { std::string temp = end; @@ -511,7 +572,7 @@ bool CGUIControlFactory::GetActions(const TiXmlNode* pRootNode, return actions.HasAnyActions(); } -bool CGUIControlFactory::GetHitRect(const TiXmlNode *control, CRect &rect, const CRect &parentRect) +bool CGUIControlFactory::GetHitRect(const TiXmlNode* control, CRect& rect, const CRect& parentRect) { const TiXmlElement* node = control->FirstChildElement("hitrect"); if (node) @@ -531,7 +592,9 @@ bool CGUIControlFactory::GetHitRect(const TiXmlNode *control, CRect &rect, const return false; } -bool CGUIControlFactory::GetScroller(const TiXmlNode *control, const std::string &scrollerTag, CScroller& scroller) +bool CGUIControlFactory::GetScroller(const TiXmlNode* control, + const std::string& scrollerTag, + CScroller& scroller) { const TiXmlElement* node = control->FirstChildElement(scrollerTag); if (node) @@ -559,7 +622,10 @@ bool CGUIControlFactory::GetColor(const TiXmlNode* control, return false; } -bool CGUIControlFactory::GetInfoColor(const TiXmlNode *control, const char *strTag, GUIINFO::CGUIInfoColor &value,int parentID) +bool CGUIControlFactory::GetInfoColor(const TiXmlNode* control, + const char* strTag, + GUIINFO::CGUIInfoColor& value, + int parentID) { const TiXmlElement* node = control->FirstChildElement(strTag); if (node && node->FirstChild()) @@ -570,7 +636,10 @@ bool CGUIControlFactory::GetInfoColor(const TiXmlNode *control, const char *strT return false; } -void CGUIControlFactory::GetInfoLabel(const TiXmlNode *pControlNode, const std::string &labelTag, GUIINFO::CGUIInfoLabel &infoLabel, int parentID) +void CGUIControlFactory::GetInfoLabel(const TiXmlNode* pControlNode, + const std::string& labelTag, + GUIINFO::CGUIInfoLabel& infoLabel, + int parentID) { std::vector labels; GetInfoLabels(pControlNode, labelTag, labels, parentID); @@ -578,7 +647,9 @@ void CGUIControlFactory::GetInfoLabel(const TiXmlNode *pControlNode, const std:: infoLabel = labels[0]; } -bool CGUIControlFactory::GetInfoLabelFromElement(const TiXmlElement *element, GUIINFO::CGUIInfoLabel &infoLabel, int parentID) +bool CGUIControlFactory::GetInfoLabelFromElement(const TiXmlElement* element, + GUIINFO::CGUIInfoLabel& infoLabel, + int parentID) { if (!element || !element->FirstChild()) return false; @@ -598,7 +669,10 @@ bool CGUIControlFactory::GetInfoLabelFromElement(const TiXmlElement *element, GU return true; } -void CGUIControlFactory::GetInfoLabels(const TiXmlNode *pControlNode, const std::string &labelTag, std::vector &infoLabels, int parentID) +void CGUIControlFactory::GetInfoLabels(const TiXmlNode* pControlNode, + const std::string& labelTag, + std::vector& infoLabels, + int parentID) { // we can have the following infolabels: // 1. 1234 -> direct number @@ -612,7 +686,7 @@ void CGUIControlFactory::GetInfoLabels(const TiXmlNode *pControlNode, const std: infoLabels.emplace_back(label); return; // done } - const TiXmlElement *labelNode = pControlNode->FirstChildElement(labelTag); + const TiXmlElement* labelNode = pControlNode->FirstChildElement(labelTag); while (labelNode) { GUIINFO::CGUIInfoLabel label; @@ -620,7 +694,7 @@ void CGUIControlFactory::GetInfoLabels(const TiXmlNode *pControlNode, const std: infoLabels.push_back(label); labelNode = labelNode->NextSiblingElement(labelTag); } - const TiXmlNode *infoNode = pControlNode->FirstChild("info"); + const TiXmlNode* infoNode = pControlNode->FirstChild("info"); if (infoNode) { // nodes override