2020-05-27 09:21:20 +02:00
|
|
|
#include "framework.h"
|
2021-12-22 16:23:57 +03:00
|
|
|
#include "Renderer/Renderer11.h"
|
2022-03-29 20:17:13 +11:00
|
|
|
|
2021-08-30 18:03:21 +03:00
|
|
|
namespace TEN::Renderer {
|
2022-05-05 06:28:43 +02:00
|
|
|
void Renderer11::DrawString(int x, int y, const char* string, D3DCOLOR color, int flags)
|
2022-03-29 20:17:13 +11:00
|
|
|
{
|
2022-06-07 03:59:02 +03:00
|
|
|
float factorX = ScreenWidth / REFERENCE_RES_WIDTH;
|
|
|
|
float factorY = ScreenHeight / REFERENCE_RES_HEIGHT;
|
2020-06-21 14:27:12 +02:00
|
|
|
|
|
|
|
RECT rect = { 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
// Convert the string to wstring
|
|
|
|
int sizeNeeded = MultiByteToWideChar(CP_UTF8, 0, string, strlen(string), NULL, 0);
|
|
|
|
std::wstring wstr(sizeNeeded, 0);
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, string, strlen(string), &wstr[0], sizeNeeded);
|
|
|
|
|
|
|
|
// Prepare the structure for the renderer
|
|
|
|
RendererStringToDraw str;
|
|
|
|
str.String = wstr;
|
|
|
|
str.Flags = flags;
|
|
|
|
str.X = 0;
|
|
|
|
str.Y = 0;
|
|
|
|
str.Color = Vector3((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF);
|
2022-06-06 14:16:25 +03:00
|
|
|
str.Scale = ScreenWidth > ScreenHeight ? factorY : factorX;
|
2020-06-21 14:27:12 +02:00
|
|
|
|
|
|
|
// Measure the string
|
|
|
|
Vector2 size = m_gameFont->MeasureString(wstr.c_str());
|
|
|
|
|
2022-03-29 20:17:13 +11:00
|
|
|
if (flags & PRINTSTRING_CENTER)
|
|
|
|
{
|
2022-06-06 14:16:25 +03:00
|
|
|
int width = size.x * str.Scale;
|
2020-06-21 14:27:12 +02:00
|
|
|
rect.left = x * factorX - width / 2;
|
|
|
|
rect.right = x * factorX + width / 2;
|
2022-06-06 14:16:25 +03:00
|
|
|
rect.top += y * str.Scale;
|
|
|
|
rect.bottom += y * str.Scale;
|
2022-05-05 06:28:43 +02:00
|
|
|
}
|
|
|
|
else
|
2022-03-29 20:17:13 +11:00
|
|
|
{
|
2020-06-21 14:27:12 +02:00
|
|
|
rect.left = x * factorX;
|
|
|
|
rect.right += x * factorX;
|
2022-06-06 14:16:25 +03:00
|
|
|
rect.top = y * str.Scale;
|
|
|
|
rect.bottom += y * str.Scale;
|
2020-06-21 14:27:12 +02:00
|
|
|
}
|
2020-01-08 20:57:33 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
str.X = rect.left;
|
|
|
|
str.Y = rect.top;
|
|
|
|
|
2022-03-29 20:17:13 +11:00
|
|
|
if (flags & PRINTSTRING_BLINK)
|
|
|
|
{
|
2022-06-07 03:59:02 +03:00
|
|
|
if (flags & PRINTSTRING_DONT_UPDATE_BLINK)
|
|
|
|
{
|
2022-06-07 04:17:43 +03:00
|
|
|
str.Color = Vector3(128);
|
2022-06-07 03:59:02 +03:00
|
|
|
}
|
2022-06-07 04:17:43 +03:00
|
|
|
else
|
2022-03-29 20:17:13 +11:00
|
|
|
{
|
2022-06-07 03:59:02 +03:00
|
|
|
str.Color = Vector3(m_blinkColorValue, m_blinkColorValue, m_blinkColorValue);
|
2022-03-29 20:17:13 +11:00
|
|
|
|
2022-06-07 04:17:43 +03:00
|
|
|
if (!m_blinkUpdated)
|
2022-03-29 20:17:13 +11:00
|
|
|
{
|
2022-06-07 04:17:43 +03:00
|
|
|
m_blinkColorValue += m_blinkColorDirection * 16;
|
|
|
|
m_blinkUpdated = true;
|
|
|
|
|
|
|
|
if (m_blinkColorValue < 0)
|
|
|
|
{
|
|
|
|
m_blinkColorValue = 0;
|
|
|
|
m_blinkColorDirection = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_blinkColorValue > 255)
|
|
|
|
{
|
|
|
|
m_blinkColorValue = 255;
|
|
|
|
m_blinkColorDirection = -1;
|
|
|
|
}
|
2020-06-21 14:27:12 +02:00
|
|
|
}
|
2020-01-08 20:57:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
m_strings.push_back(str);
|
|
|
|
}
|
2020-01-08 20:57:33 +01:00
|
|
|
|
2022-01-29 05:55:09 +01:00
|
|
|
void Renderer11::DrawAllStrings()
|
2022-05-05 06:28:43 +02:00
|
|
|
{
|
2020-06-21 14:27:12 +02:00
|
|
|
m_spriteBatch->Begin();
|
2020-01-08 20:57:33 +01:00
|
|
|
|
2022-03-29 20:17:13 +11:00
|
|
|
for (int i = 0; i < m_strings.size(); i++)
|
|
|
|
{
|
2020-06-21 14:27:12 +02:00
|
|
|
RendererStringToDraw* str = &m_strings[i];
|
2020-01-08 20:57:33 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
// Draw shadow if needed
|
|
|
|
if (str->Flags & PRINTSTRING_OUTLINE)
|
2022-06-06 14:16:25 +03:00
|
|
|
m_gameFont->DrawString(m_spriteBatch.get(), str->String.c_str(), Vector2(str->X + 2 * str->Scale, str->Y + 2 * str->Scale),
|
|
|
|
Vector4(0.0f, 0.0f, 0.0f, 1.0f) * ScreenFadeCurrent,
|
|
|
|
0.0f, Vector4::Zero, str->Scale);
|
2020-01-08 20:57:33 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
// Draw string
|
2020-08-09 22:15:32 +02:00
|
|
|
m_gameFont->DrawString(m_spriteBatch.get(), str->String.c_str(), Vector2(str->X, str->Y),
|
2022-06-06 14:16:25 +03:00
|
|
|
Vector4(str->Color.x / 255.0f, str->Color.y / 255.0f, str->Color.z / 255.0f, 1.0f) * ScreenFadeCurrent,
|
|
|
|
0.0f, Vector4::Zero, str->Scale);
|
2020-06-21 14:27:12 +02:00
|
|
|
}
|
2020-01-08 20:57:33 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
m_spriteBatch->End();
|
2022-06-07 03:59:02 +03:00
|
|
|
|
|
|
|
m_blinkUpdated = false;
|
|
|
|
m_strings.clear();
|
2020-01-08 20:57:33 +01:00
|
|
|
}
|
|
|
|
}
|