Skip to main content
GameDev.net gamedev.net
🔒 Locked

Direct2D and DirectWrite wrap text in layer

Started by gomidas Apr 18, 2020 at 4:14 PM 0 replies 4.3k views
Original Post
gomidas
gomidas

Hello, I am trying to wrap text inside a layer within client area. Is that possible to do that ?

...

m_d2dRenderTarget->CreateSolidColorBrush(ColorF(colorf), &m_Brush);
m_d2dRenderTarget->BeginDraw();
wstring textWstr = wstring(text.begin(), text.end());
const wchar_t* wcharText = textWstr.c_str();
// Create a layer.
ID2D1Layer* mainLayer = NULL;  
m_d2dRenderTarget->CreateLayer(NULL, &mainLayer);
m_d2dRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(0, 0));
 m_d2dRenderTarget->PushLayer(D2D1::LayerParameters(D2D1::RectF(0, 0, 200, m_screenSize.y)), mainLayer);
m_d2dRenderTarget->DrawTextW(wcharText, wcslen(wcharText), textFormat, RectF(posX, posY, m_screenSize.x, m_screenSize.y), m_Brush);
m_d2dRenderTarget->PopLayer();
m_d2dRenderTarget->EndDraw();

textFormat->Release();
mainLayer->Release();

...

I am trying to achieve something like in PAINT's Text drawing tool. Just like in this image.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.