TombEngine/TR5Main/Renderer/Renderer11String.cpp
TokyoSU 29f0724693 New project format (#206)
* Starting Reformat the project

- New Import Method, no more "../../" in import,
- New Entity Folder Structure, less compile time

* Refactoring the Project

- added precompiled header with default import like microsoft or directx.
- fix many double import.
- fix math.h confliting math.h from
microsoft.
- fix effects.h confliting Effects.h from DirectX.
- refactored TR4 entity folder and how it's loaded.

* Update Some Code Before Switching to Master

* Finished the NewProjectFormat Template

- need to finish entity in the master later.

* Added Monty NewFileFormat

* Fixed Monty NewFileFormat Include

* Revert "Fixed Monty NewFileFormat Include"

This reverts commit ebf0afca10.

* Trying to fix conflits for NewFileFormat

* Fixed .filters

* Last Commit in NewProjectFormat
2020-05-27 09:21:20 +02:00

98 lines
2.2 KiB
C++

#include "framework.h"
#include "Renderer11.h"
bool Renderer11::PrintString(int x, int y, char* string, D3DCOLOR color, int flags)
{
int realX = x;
int realY = y;
float factorX = ScreenWidth / 800.0f;
float factorY = ScreenHeight / 600.0f;
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);
// Measure the string
Vector2 size = m_gameFont->MeasureString(wstr.c_str());
if (flags & PRINTSTRING_CENTER)
{
int width = size.x;
rect.left = x * factorX - width / 2;
rect.right = x * factorX + width / 2;
rect.top += y * factorY;
rect.bottom += y * factorY;
}
else
{
rect.left = x * factorX;
rect.right += x * factorX;
rect.top = y * factorY;
rect.bottom += y * factorY;
}
str.X = rect.left;
str.Y = rect.top;
if (flags & PRINTSTRING_BLINK)
{
str.Color = Vector3(m_blinkColorValue, m_blinkColorValue, m_blinkColorValue);
if (!(flags & PRINTSTRING_DONT_UPDATE_BLINK))
{
m_blinkColorValue += m_blinkColorDirection * 16;
if (m_blinkColorValue < 0)
{
m_blinkColorValue = 0;
m_blinkColorDirection = 1;
}
if (m_blinkColorValue > 255)
{
m_blinkColorValue = 255;
m_blinkColorDirection = -1;
}
}
}
m_strings.push_back(str);
return true;
}
bool Renderer11::drawAllStrings()
{
m_spriteBatch->Begin();
for (int i = 0; i < m_strings.size(); i++)
{
RendererStringToDraw* str = &m_strings[i];
// Draw shadow if needed
if (str->Flags & PRINTSTRING_OUTLINE)
m_gameFont->DrawString(m_spriteBatch, str->String.c_str(), Vector2(str->X + 1, str->Y + 1),
Vector4(0.0f, 0.0f, 0.0f, 1.0f));
// Draw string
m_gameFont->DrawString(m_spriteBatch, str->String.c_str(), Vector2(str->X, str->Y),
Vector4(str->Color.x / 255.0f, str->Color.y / 255.0f, str->Color.z / 255.0f, 1.0f));
}
m_spriteBatch->End();
return true;
}