@@ -1,22 +1,24 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <wtypes.h>
|
#include <wtypes.h>
|
||||||
|
|
||||||
namespace render {
|
namespace render
|
||||||
|
{
|
||||||
void DrawBorderBox(HDC hdc, int x, int y, int w, int h, COLORREF borderColor)
|
void DrawBorderBox(HDC hdc, int x, int y, int w, int h, COLORREF borderColor)
|
||||||
{
|
{
|
||||||
HBRUSH hBorderBrush = CreateSolidBrush(borderColor);
|
HBRUSH hBorderBrush = CreateSolidBrush(borderColor);
|
||||||
HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc, hBorderBrush);
|
HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc, hBorderBrush);
|
||||||
|
|
||||||
RECT rect = { x, y, x + w, y + h };
|
RECT rect = {x, y, x + w, y + h};
|
||||||
FrameRect(hdc, &rect, hBorderBrush);
|
FrameRect(hdc, &rect, hBorderBrush);
|
||||||
|
|
||||||
SelectObject(hdc, hOldBrush); // Restore the original brush
|
SelectObject(hdc, hOldBrush); // Restore the original brush
|
||||||
DeleteObject(hBorderBrush); // Delete the temporary brush
|
DeleteObject(hBorderBrush); // Delete the temporary brush
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawFilledBox(HDC hdc, int x, int y, int width, int height, COLORREF color) {
|
void DrawFilledBox(HDC hdc, int x, int y, int width, int height, COLORREF color)
|
||||||
|
{
|
||||||
HBRUSH hBrush = CreateSolidBrush(color);
|
HBRUSH hBrush = CreateSolidBrush(color);
|
||||||
RECT rect = { x, y, x + width, y + height };
|
RECT rect = {x, y, x + width, y + height};
|
||||||
FillRect(hdc, &rect, hBrush);
|
FillRect(hdc, &rect, hBrush);
|
||||||
DeleteObject(hBrush);
|
DeleteObject(hBrush);
|
||||||
}
|
}
|
||||||
@@ -28,9 +30,9 @@ namespace render {
|
|||||||
|
|
||||||
// Initialize the LOGFONT structure
|
// Initialize the LOGFONT structure
|
||||||
ZeroMemory(&lf, sizeof(LOGFONT));
|
ZeroMemory(&lf, sizeof(LOGFONT));
|
||||||
lf.lfHeight = -textSize; // Set the desired text height (negative for height)
|
lf.lfHeight = -textSize; // Set the desired text height (negative for height)
|
||||||
lf.lfWeight = FW_NORMAL; // Set the font weight (e.g., FW_NORMAL for normal)
|
lf.lfWeight = FW_NORMAL; // Set the font weight (e.g., FW_NORMAL for normal)
|
||||||
lf.lfQuality = ANTIALIASED_QUALITY; // Enable anti-aliasing
|
lf.lfQuality = ANTIALIASED_QUALITY; // Enable anti-aliasing
|
||||||
|
|
||||||
// Create a new font based on the LOGFONT structure
|
// Create a new font based on the LOGFONT structure
|
||||||
hFont = CreateFontIndirect(&lf);
|
hFont = CreateFontIndirect(&lf);
|
||||||
@@ -42,10 +44,17 @@ namespace render {
|
|||||||
DeleteObject(hOldFont);
|
DeleteObject(hOldFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderText(HDC hdc, int x, int y, const char* text, COLORREF textColor, int textSize)
|
void RenderText(HDC hdc, int x, int y, const char *text, COLORREF textColor, int textSize)
|
||||||
{
|
{
|
||||||
SetTextSize(hdc, textSize); // Set the desired text size
|
SetTextSize(hdc, textSize);
|
||||||
SetTextColor(hdc, textColor);
|
SetTextColor(hdc, textColor);
|
||||||
TextOutA(hdc, x, y, text, strlen(text));
|
|
||||||
|
int len = MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
|
||||||
|
wchar_t *wide_text = new wchar_t[len];
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, text, -1, wide_text, len);
|
||||||
|
|
||||||
|
TextOutW(hdc, x, y, wide_text, len - 1);
|
||||||
|
|
||||||
|
delete[] wide_text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user