Skip to content

Commit

Permalink
[guilib] fix edit labels not being clipped
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Marshall committed Jul 1, 2012
1 parent 0b51902 commit 3b7d4b2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
8 changes: 6 additions & 2 deletions xbmc/guilib/GUIButtonControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ void CGUIButtonControl::Render()
m_imgFocus.Render();
m_imgNoFocus.Render();

RenderText();
CGUIControl::Render();
}

void CGUIButtonControl::RenderText()
{
m_label.Render();
m_label2.Render();

CGUIControl::Render();
}

CGUILabel::COLOR CGUIButtonControl::GetTextColor() const
Expand Down
1 change: 1 addition & 0 deletions xbmc/guilib/GUIButtonControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class CGUIButtonControl : public CGUIControl
void OnFocus();
void OnUnFocus();
virtual void ProcessText(unsigned int currentTime);
virtual void RenderText();
CGUILabel::COLOR GetTextColor() const;

CGUITexture m_imgFocus;
Expand Down
29 changes: 21 additions & 8 deletions xbmc/guilib/GUIEditControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,10 @@ void CGUIEditControl::ProcessText(unsigned int currentTime)

bool changed = false;

float posX = m_label.GetRenderRect().x1;
float maxTextWidth = m_label.GetMaxWidth();
m_clipRect.x1 = m_label.GetRenderRect().x1;
m_clipRect.x2 = m_clipRect.x1 + m_label.GetMaxWidth();
m_clipRect.y1 = m_posY;
m_clipRect.y2 = m_posY + m_height;

// start by rendering the normal text
float leftTextWidth = m_label.GetRenderRect().Width();
Expand All @@ -382,15 +384,14 @@ void CGUIEditControl::ProcessText(unsigned int currentTime)
// render the text on the left
changed |= m_label.SetColor(GetTextColor());
changed |= m_label.Process(currentTime);

posX += leftTextWidth + spaceWidth;
maxTextWidth -= leftTextWidth + spaceWidth;

m_clipRect.x1 += leftTextWidth + spaceWidth;
}

if (g_graphicsContext.SetClipRegion(posX, m_posY, maxTextWidth, m_height))
if (g_graphicsContext.SetClipRegion(m_clipRect.x1, m_clipRect.y1, m_clipRect.Width(), m_clipRect.Height()))
{
uint32_t align = m_label.GetLabelInfo().align & XBFONT_CENTER_Y; // start aligned left
if (m_label2.GetTextWidth() < maxTextWidth)
if (m_label2.GetTextWidth() < m_clipRect.Width())
{ // align text as our text fits
if (leftTextWidth > 0)
{ // right align as we have 2 labels
Expand All @@ -413,20 +414,32 @@ void CGUIEditControl::ProcessText(unsigned int currentTime)
text.Insert(m_cursorPos, col);
}

changed |= m_label2.SetMaxRect(posX + m_textOffset, m_posY, maxTextWidth - m_textOffset, m_height);
changed |= m_label2.SetMaxRect(m_clipRect.x1 + m_textOffset, m_posY, m_clipRect.Width() - m_textOffset, m_height);
if (text.IsEmpty())
changed |= m_label2.SetText(m_hintInfo.GetLabel(GetParentID()));
else
changed |= m_label2.SetTextW(text);
changed |= m_label2.SetAlign(align);
changed |= m_label2.SetColor(GetTextColor());
changed |= m_label2.SetOverflow(CGUILabel::OVER_FLOW_CLIP);
changed |= m_label2.Process(currentTime);
g_graphicsContext.RestoreClipRegion();
}
if (changed)
MarkDirtyRegion();
}

void CGUIEditControl::RenderText()
{
m_label.Render();

if (g_graphicsContext.SetClipRegion(m_clipRect.x1, m_clipRect.y1, m_clipRect.Width(), m_clipRect.Height()))
{
m_label2.Render();
g_graphicsContext.RestoreClipRegion();
}
}

void CGUIEditControl::SetHint(const CGUIInfoLabel& hint)
{
m_hintInfo = hint;
Expand Down
2 changes: 2 additions & 0 deletions xbmc/guilib/GUIEditControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CGUIEditControl : public CGUIButtonControl

protected:
virtual void ProcessText(unsigned int currentTime);
virtual void RenderText();
CStdStringW GetDisplayedText() const;
void RecalcLabelPosition();
void ValidateCursor();
Expand All @@ -98,6 +99,7 @@ class CGUIEditControl : public CGUIButtonControl
CGUIInfoLabel m_hintInfo;
float m_textOffset;
float m_textWidth;
CRect m_clipRect; ///< clipping rect for the second label

static const int spaceWidth = 5;

Expand Down

0 comments on commit 3b7d4b2

Please sign in to comment.