tibia-client/src/framework/ui/uilabel.cpp

45 lines
1.0 KiB
C++
Raw Normal View History

2011-08-14 04:09:11 +02:00
#include "uilabel.h"
2011-08-15 16:06:15 +02:00
#include <framework/graphics/font.h>
#include <framework/otml/otmlnode.h>
2011-04-23 22:04:49 +02:00
2011-08-14 04:09:11 +02:00
UILabel::UILabel() : UIWidget(UITypeLabel)
2011-04-23 22:04:49 +02:00
{
2011-08-14 04:09:11 +02:00
m_align = AlignLeft;
}
UILabelPtr UILabel::create()
{
UILabelPtr label(new UILabel);
return label;
}
void UILabel::loadStyleFromOTML(const OTMLNodePtr& styleNode)
{
UIWidget::loadStyleFromOTML(styleNode);
m_text = styleNode->valueAt("text", m_text);
2011-08-14 04:09:11 +02:00
if(styleNode->hasChildAt("align"))
m_align = fw::translateAlignment(styleNode->valueAt("align"));
2011-08-14 04:09:11 +02:00
2011-08-20 22:30:41 +02:00
// auto resize if needed
if(!m_text.empty() && !m_rect.isValid()) {
Size textSize = m_font->calculateTextRectSize(m_text);
if(m_rect.width() <= 0)
m_rect.setWidth(textSize.width());
if(m_rect.height() <= 0)
m_rect.setHeight(textSize.height());
}
2011-08-14 04:09:11 +02:00
}
void UILabel::render()
{
2011-08-20 22:30:41 +02:00
UIWidget::render();
m_font->renderText(m_text, m_rect, m_align, m_foregroundColor);
2011-08-14 04:09:11 +02:00
}
void UILabel::resizeToText()
{
2011-08-20 22:30:41 +02:00
resize(m_font->calculateTextRectSize(m_text));
2011-04-23 22:04:49 +02:00
}