Files
Aerofoil/PortabilityLayer/PLLabelWidget.cpp

50 lines
1.2 KiB
C++
Raw Normal View History

#include "PLLabelWidget.h"
#include "PLQDraw.h"
#include "FontFamily.h"
#include "PLStandardColors.h"
2020-05-21 05:01:16 -04:00
#include "RenderedFont.h"
#include "RenderedFontMetrics.h"
2020-05-21 03:30:11 -04:00
#include "ResolveCachingColor.h"
#include <algorithm>
namespace PortabilityLayer
{
LabelWidget::LabelWidget(const WidgetBasicState &state)
: WidgetSpec<LabelWidget>(state)
, m_text(state.m_text)
{
}
2020-05-18 02:03:17 -04:00
bool LabelWidget::Init(const WidgetBasicState &state, const void *additionalData)
{
(void)state;
return true;
}
void LabelWidget::SetString(const PLPasStr &str)
{
m_text.Set(str.Length(), str.Chars());
}
PLPasStr LabelWidget::GetString() const
{
return m_text.ToShortStr();
}
void LabelWidget::DrawControl(DrawSurface *surface)
{
2020-05-21 03:30:11 -04:00
ResolveCachingColor whiteColor = StdColors::White();
ResolveCachingColor blackColor = StdColors::Black();
surface->FillRect(m_rect, whiteColor);
2020-02-05 00:22:55 -05:00
2020-05-21 05:01:16 -04:00
PortabilityLayer::RenderedFont *sysFont = GetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
const Point topLeftCorner = Point::Create(m_rect.left, m_rect.top);
2020-05-21 05:01:16 -04:00
const Point textStartPoint = topLeftCorner + Point::Create(0, sysFont->GetMetrics().m_ascent);
2020-05-21 05:01:16 -04:00
surface->DrawStringWrap(textStartPoint, m_rect, m_text.ToShortStr(), blackColor, sysFont);
}
}