Add offscreen text rendering.
This commit is contained in:
parent
c63138c455
commit
076e32b1d6
17 changed files with 156 additions and 101 deletions
|
@ -29,27 +29,18 @@ DirectXTextPainter::DirectXTextPainter()
|
|||
void DirectXTextPainter::setD2dInterface(DirectX2dInterface* d2dIterface)
|
||||
{
|
||||
mD2dInterface = d2dIterface;
|
||||
mD2dInterface->getRenderTarget()->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &mTextBrush);
|
||||
}
|
||||
|
||||
void DirectXTextPainter::initialize()
|
||||
{
|
||||
initializeBrush();
|
||||
}
|
||||
|
||||
void DirectXTextPainter::initializeBrush()
|
||||
{
|
||||
mD2dInterface->getContext()->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &mTextBrush);
|
||||
}
|
||||
|
||||
void DirectXTextPainter::updateTextFormat(float fontSize)
|
||||
void DirectXTextPainter::updateTextFormat(const FontItem& font)
|
||||
{
|
||||
mD2dInterface->getDirectWriteFactory()->CreateTextFormat(
|
||||
L"Verdana",
|
||||
NULL,
|
||||
StringUtils::convert(font.getFaceName()).c_str(),
|
||||
nullptr,
|
||||
DWRITE_FONT_WEIGHT_NORMAL,
|
||||
DWRITE_FONT_STYLE_NORMAL,
|
||||
DWRITE_FONT_STRETCH_NORMAL,
|
||||
fontSize,
|
||||
static_cast<float>(font.getSize()),
|
||||
L"en-us",
|
||||
&mTextFormat
|
||||
);
|
||||
|
@ -62,14 +53,11 @@ void DirectXTextPainter::paint(SceneText* text, DrawingContext* context)
|
|||
const auto location = text->getTransform().getLocation();
|
||||
D2D1_RECT_F textRect = D2D1::RectF(static_cast<float>(location.getX()), static_cast<float>(location.getY()), static_cast<float>(location.getX() + 200), static_cast<float>(location.getY() + 100));
|
||||
|
||||
updateTextFormat(static_cast<float>(text->getTextData().mFont.getSize()));
|
||||
updateTextFormat(text->getTextData().mFont);
|
||||
|
||||
auto content = StringUtils::convert(text->getTextData().mContent);
|
||||
|
||||
mD2dInterface->getContext()->BeginDraw();
|
||||
mD2dInterface->getContext()->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||
mD2dInterface->getContext()->DrawText(content.c_str(), static_cast<UINT32>(content.size()), mTextFormat.Get(), &textRect, mTextBrush.Get());
|
||||
mD2dInterface->getContext()->EndDraw();
|
||||
mD2dInterface->getRenderTarget()->DrawText(content.c_str(), static_cast<UINT32>(content.size()), mTextFormat.Get(), &textRect, mTextBrush.Get());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue