aboutsummaryrefslogtreecommitdiff
path: root/guilib/GUILabelControl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'guilib/GUILabelControl.cpp')
-rw-r--r--guilib/GUILabelControl.cpp84
1 files changed, 20 insertions, 64 deletions
diff --git a/guilib/GUILabelControl.cpp b/guilib/GUILabelControl.cpp
index 51d03f7740..7dfa8af69d 100644
--- a/guilib/GUILabelControl.cpp
+++ b/guilib/GUILabelControl.cpp
@@ -25,17 +25,18 @@
using namespace std;
CGUILabelControl::CGUILabelControl(int parentID, int controlID, float posX, float posY, float width, float height, const CLabelInfo& labelInfo, bool wrapMultiLine, bool bHasPath)
- : CGUIControl(parentID, controlID, posX, posY, width, height), m_textLayout(labelInfo.font, wrapMultiLine, height)
+ : CGUIControl(parentID, controlID, posX, posY, width, height)
+ , m_label(posX, posY, width, height, labelInfo, wrapMultiLine ? CGUILabel::OVER_FLOW_WRAP : CGUILabel::OVER_FLOW_TRUNCATE)
{
m_bHasPath = bHasPath;
m_iCursorPos = 0;
- m_label = labelInfo;
m_bShowCursor = false;
m_dwCounter = 0;
ControlType = GUICONTROL_LABEL;
- m_ScrollInsteadOfTruncate = false;
m_startHighlight = m_endHighlight = 0;
m_minWidth = 0;
+ if ((labelInfo.align & XBFONT_RIGHT) && m_width)
+ m_posX -= m_width;
}
CGUILabelControl::~CGUILabelControl(void)
@@ -86,53 +87,20 @@ void CGUILabelControl::UpdateInfo(const CGUIListItem *item)
else if (m_startHighlight || m_endHighlight)
{ // this is only used for times/dates, so working in ascii (utf8) is fine
CStdString colorLabel;
- colorLabel.Format("[COLOR %x]%s[/COLOR]%s[COLOR %x]%s[/COLOR]", (color_t)m_label.disabledColor, label.Left(m_startHighlight),
- label.Mid(m_startHighlight, m_endHighlight - m_startHighlight), (color_t)m_label.disabledColor, label.Mid(m_endHighlight));
+ colorLabel.Format("[COLOR %x]%s[/COLOR]%s[COLOR %x]%s[/COLOR]", (color_t)m_label.GetLabelInfo().disabledColor, label.Left(m_startHighlight),
+ label.Mid(m_startHighlight, m_endHighlight - m_startHighlight), (color_t)m_label.GetLabelInfo().disabledColor, label.Mid(m_endHighlight));
label = colorLabel;
}
- if (m_textLayout.Update(label, m_width))
- { // reset the scrolling as we have a new label
- m_ScrollInfo.Reset();
- }
+ m_label.SetMaxRect(m_posX, m_posY, m_width, m_height);
+ m_label.SetText(label);
}
void CGUILabelControl::Render()
{
- // check for scrolling
- bool bNormalDraw = true;
- if (m_ScrollInsteadOfTruncate && m_width > 0 && !IsDisabled())
- { // ignore align center - just use align left/right
- float width, height;
- m_textLayout.GetTextExtent(width, height);
- if (width > m_width)
- { // need to scroll - set the viewport. Should be set just using the height of the text
- bNormalDraw = false;
- float fPosX = m_posX;
- if (m_label.align & XBFONT_RIGHT)
- fPosX -= m_width;
- float fPosY = m_posY;
- if (m_label.align & XBFONT_CENTER_Y)
- fPosY += m_height * 0.5f;
-
- m_textLayout.RenderScrolling(fPosX, fPosY, m_label.angle, m_label.textColor, m_label.shadowColor, (m_label.align & ~3), m_width, m_ScrollInfo);
- }
- }
- if (bNormalDraw)
- {
- float fPosX = m_posX;
- if (m_label.align & XBFONT_CENTER_X)
- fPosX += m_width * 0.5f;
-
- float fPosY = m_posY;
- if (m_label.align & XBFONT_CENTER_Y)
- fPosY += m_height * 0.5f;
-
- if (IsDisabled())
- m_textLayout.Render(fPosX, fPosY, m_label.angle, m_label.disabledColor, m_label.shadowColor, m_label.align | XBFONT_TRUNCATED, m_width, true);
- else
- m_textLayout.Render(fPosX, fPosY, m_label.angle, m_label.textColor, m_label.shadowColor, m_label.align | XBFONT_TRUNCATED, m_width);
- }
+ m_label.SetColor(IsDisabled() ? CGUILabel::COLOR_DISABLED : CGUILabel::COLOR_TEXT);
+ m_label.SetMaxRect(m_posX, m_posY, m_width, m_height);
+ m_label.Render();
CGUIControl::Render();
}
@@ -149,7 +117,6 @@ void CGUILabelControl::SetLabel(const string &strLabel)
m_infoLabel.SetLabel(ShortenPath(strLabel), "");
else // parse the label for info tags
m_infoLabel.SetLabel(strLabel, "");
- m_ScrollInfo.Reset();
if (m_iCursorPos > (int)strLabel.size())
m_iCursorPos = strLabel.size();
}
@@ -157,14 +124,12 @@ void CGUILabelControl::SetLabel(const string &strLabel)
void CGUILabelControl::SetWidthControl(float minWidth, bool bScroll, int scrollSpeed)
{
m_minWidth = minWidth;
- m_ScrollInsteadOfTruncate = bScroll;
- m_ScrollInfo.SetSpeed(scrollSpeed);
- m_ScrollInfo.Reset();
+ m_label.SetScrolling(bScroll, scrollSpeed);
}
void CGUILabelControl::SetAlignment(uint32_t align)
{
- m_label.align = align;
+ m_label.GetLabelInfo().align = align;
}
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
@@ -172,7 +137,7 @@ void CGUILabelControl::SetAlignment(uint32_t align)
float CGUILabelControl::GetWidth() const
{
if (m_minWidth && m_minWidth != m_width)
- return CLAMP(m_textLayout.GetTextWidth(), m_minWidth, m_width);
+ return CLAMP(m_label.GetTextWidth(), m_minWidth, m_width);
return m_width;
}
@@ -192,7 +157,7 @@ bool CGUILabelControl::OnMessage(CGUIMessage& message)
CStdString CGUILabelControl::ShortenPath(const CStdString &path)
{
- if (!m_label.font || m_width == 0 || path.IsEmpty())
+ if (m_width == 0 || path.IsEmpty())
return path;
char cDelim = '\0';
@@ -220,11 +185,10 @@ CStdString CGUILabelControl::ShortenPath(const CStdString &path)
nPos = workPath.find_last_of( cDelim );
}
- float fTextHeight, fTextWidth;
- m_textLayout.Update(workPath);
- m_textLayout.GetTextExtent(fTextWidth, fTextHeight);
+ m_label.SetText(workPath);
+ float textWidth = m_label.GetTextWidth();
- while ( fTextWidth > m_width )
+ while ( textWidth > m_width )
{
size_t nGreaterDelim = workPath.find_last_of( cDelim, nPos );
if (nGreaterDelim == std::string::npos)
@@ -236,20 +200,12 @@ CStdString CGUILabelControl::ShortenPath(const CStdString &path)
workPath.replace( nPos + 1, nGreaterDelim - nPos - 1, "..." );
- m_textLayout.Update(workPath);
- m_textLayout.GetTextExtent(fTextWidth, fTextHeight);
+ m_label.SetText(workPath);
+ textWidth = m_label.GetTextWidth();
}
return workPath;
}
-void CGUILabelControl::SetTruncate(bool bTruncate)
-{
- if (bTruncate)
- m_label.align |= XBFONT_TRUNCATED;
- else
- m_label.align &= ~XBFONT_TRUNCATED;
-}
-
void CGUILabelControl::SetHighlight(unsigned int start, unsigned int end)
{
m_startHighlight = start;