Skip to content

Commit

Permalink
guicontrolfactory: allow using percentage values for <posx/left>, <po…
Browse files Browse the repository at this point in the history
…sy/top>, <width>, <height>, <right>, <bottom>

concrete value will be calculated based on parent group width or height
  • Loading branch information
pieh committed Jul 23, 2012
1 parent af91417 commit cbdf43f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions xbmc/guilib/GUIControlFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,13 @@ float CGUIControlFactory::ParsePosition(const char* pos, float parentSize)
{
char* end;
float value = (float)strtod(pos, &end);
if (end && *end == 'r')
value = parentSize - value;
if (end)
{
if (*end == 'r')
value = parentSize - value;
else if (*end == '%')
value = value * parentSize / 100.0f;
}
return value;
}

Expand All @@ -192,18 +197,18 @@ bool CGUIControlFactory::GetPosition(const TiXmlElement *pControlNode, const cha
return true;
}

bool CGUIControlFactory::GetDimension(const TiXmlNode *pRootNode, const char* strTag, float &value, float &min)
bool CGUIControlFactory::GetDimension(const TiXmlNode *pRootNode, const char* strTag, float &value, float &min, float parentSize)
{
const TiXmlElement* pNode = pRootNode->FirstChildElement(strTag);
if (!pNode || !pNode->FirstChild()) return false;
if (0 == strnicmp("auto", pNode->FirstChild()->Value(), 4))
{ // auto-width - at least min must be set
pNode->QueryFloatAttribute("max", &value);
pNode->QueryFloatAttribute("min", &min);
value = ParsePosition(pNode->Attribute("max"), parentSize);
min = ParsePosition(pNode->Attribute("min"), parentSize);
if (!min) min = 1;
return true;
}
value = (float)atof(pNode->FirstChild()->Value());
value = ParsePosition(pNode->FirstChild()->Value(), parentSize);
return true;
}

Expand Down Expand Up @@ -719,7 +724,7 @@ CGUIControl* CGUIControlFactory::Create(int parentID, const CRect &rect, TiXmlEl
GetPosition(pControlNode, "posx", posX, rect.Width()))
hasLeft = true;

if (GetDimension(pControlNode, "width", width, minWidth))
if (GetDimension(pControlNode, "width", width, minWidth, rect.Width()))
hasWidth = true;

if (hasLeft != hasWidth) // poor man xor, we have to have at least 1 to continue
Expand All @@ -743,7 +748,7 @@ CGUIControl* CGUIControlFactory::Create(int parentID, const CRect &rect, TiXmlEl
GetPosition(pControlNode, "posy", posY, rect.Height()))
hasTop = true;

if (GetDimension(pControlNode, "height", height, minHeight))
if (GetDimension(pControlNode, "height", height, minHeight, rect.Height()))
hasHeight = true;

if (hasTop != hasHeight) // poor man xor, we have to have at least 1 to continue
Expand Down
2 changes: 1 addition & 1 deletion xbmc/guilib/GUIControlFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CGUIControlFactory
\param min minimum value - set != 0 if auto is used.
\return true if we found and read the tag.
*/
static bool GetDimension(const TiXmlNode* pRootNode, const char* strTag, float &value, float &min);
static bool GetDimension(const TiXmlNode* pRootNode, const char* strTag, float &value, float &min, float parentSize);
static bool GetAspectRatio(const TiXmlNode* pRootNode, const char* strTag, CAspectRatio &aspectRatio);
static bool GetInfoTexture(const TiXmlNode* pRootNode, const char* strTag, CTextureInfo &image, CGUIInfoLabel &info, int parentID);
static bool GetTexture(const TiXmlNode* pRootNode, const char* strTag, CTextureInfo &image);
Expand Down

0 comments on commit cbdf43f

Please sign in to comment.