r5sdk/r5dev/thirdparty/cppnet/cppkore/TextRenderer.cpp
Kawe Mazidjatari 04bee896be Fix string/wstring type conflict
cppkore uses string/wstring as StringBase while we use std::string/std::wstring as string/wstring. Changed all types in cppkore to String/WString instead.
2022-05-21 21:51:35 +02:00

33 lines
1003 B
C++

#include "stdafx.h"
#include "TextRenderer.h"
namespace Drawing
{
void TextRenderer::DrawText(HDC hDC, const String& Text, Font& Font, Rectangle Bounds, Color ForeColor, TextFormatFlags Flags)
{
SelectObject(hDC, Font.GetFontHandle());
SetBkMode(hDC, TRANSPARENT); // Default text rendering doesn't have a background.
// just draw text.
SetTextColor(hDC, ForeColor.ToCOLORREF());
RECT RcDraw{};
RcDraw.top = Bounds.Y;
RcDraw.left = Bounds.X;
RcDraw.right = Bounds.X + Bounds.Width;
RcDraw.bottom = Bounds.Y + Bounds.Height;
DRAWTEXTPARAMS Params{};
Params.cbSize = sizeof(Params);
DrawTextExA(hDC, (LPSTR)Text.ToCString(), Text.Length(), &RcDraw, (UINT)Flags, &Params);
}
void TextRenderer::DrawText(std::unique_ptr<Drawing::Graphics>& Graphics, const String& Text, Font& Font, Rectangle Bounds, Color ForeColor, TextFormatFlags Flags)
{
auto hDC = Graphics->GetHDC();
DrawText(hDC, Text, Font, Bounds, ForeColor, Flags);
Graphics->ReleaseHDC(hDC);
}
}