Text Rendering
This commit is contained in:
@ -391,16 +391,29 @@ namespace ia::iae
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
INT64 UI::s_numericVariables[MAX_VARIABLE_COUNT];
|
||||
std::string UI::s_stringVariables[MAX_VARIABLE_COUNT];
|
||||
|
||||
Rml::DataModelConstructor g_dataModel;
|
||||
|
||||
VOID UI::Initialize()
|
||||
{
|
||||
Rml::SetRenderInterface(&g_rmlUIRenderInterface);
|
||||
Rml::Initialise();
|
||||
|
||||
Rml::LoadFontFace("Resources/Fonts/Roboto-Black.ttf");
|
||||
|
||||
const auto displayExtent = Engine::GetDisplayExtent();
|
||||
g_context = Rml::CreateContext("main", Rml::Vector2i(displayExtent.x, displayExtent.y));
|
||||
Rml::Debugger::Initialise(g_context);
|
||||
Rml::Debugger::SetVisible(false);
|
||||
g_document = g_context->CreateDocument();
|
||||
|
||||
g_dataModel = g_context->CreateDataModel("ui_data");
|
||||
for (INT32 i = 0; i < MAX_VARIABLE_COUNT; i++)
|
||||
g_dataModel.Bind(BuildString("NumVar", i).c_str(), &s_numericVariables[i]);
|
||||
for (INT32 i = 0; i < MAX_VARIABLE_COUNT; i++)
|
||||
g_dataModel.Bind(BuildString("StrVar", i).c_str(), &s_stringVariables[i]);
|
||||
}
|
||||
|
||||
VOID UI::Terminate()
|
||||
@ -410,7 +423,7 @@ namespace ia::iae
|
||||
|
||||
VOID UI::Update()
|
||||
{
|
||||
if (Engine::WasInputKeyPressed(InputKey::F8))
|
||||
if (Engine::Input_WasKeyPressed(InputKey::F8))
|
||||
Rml::Debugger::SetVisible(g_debuggerEnabled = !g_debuggerEnabled);
|
||||
|
||||
g_context->Update();
|
||||
@ -483,7 +496,9 @@ namespace ia::iae
|
||||
VOID UI::SetMarkup(IN CONST String &markup, IN CONST String &styles)
|
||||
{
|
||||
g_styleSheetContainer = Rml::Factory::InstanceStyleSheetString(styles.c_str());
|
||||
g_markup = BuildString("<body style=\"display: block; width: 100vw; height: 100vh;\">", markup, "</body>");
|
||||
g_markup = BuildString("<body><div style=\"font-family: Roboto; display: block; width: 100vw; height: 100vh;\" "
|
||||
"data-model=\"ui_data\">",
|
||||
markup, "</div></body>");
|
||||
g_document->SetStyleSheetContainer(g_styleSheetContainer);
|
||||
g_document->SetInnerRML(g_markup.c_str());
|
||||
}
|
||||
@ -512,6 +527,46 @@ namespace ia::iae
|
||||
{
|
||||
g_eventListener.AddPointerEnterListener(g_document->GetElementById(elementId), callback);
|
||||
}
|
||||
|
||||
VOID UI::SetNumericVariable(IN UINT8 index, IN INT64 value)
|
||||
{
|
||||
s_numericVariables[index] = value;
|
||||
}
|
||||
|
||||
VOID UI::SetStringVariable(IN UINT8 index, IN CONST String &value)
|
||||
{
|
||||
s_stringVariables[index] = value.c_str();
|
||||
}
|
||||
|
||||
INT64 UI::GetNumericVariable(IN UINT8 index)
|
||||
{
|
||||
return s_numericVariables[index];
|
||||
}
|
||||
|
||||
String UI::GetStringVariable(IN UINT8 index)
|
||||
{
|
||||
return s_stringVariables[index].c_str();
|
||||
}
|
||||
|
||||
VOID UI::SetElementWidth(IN CONST String &elementId, IN INT32 value)
|
||||
{
|
||||
g_document->GetElementById(elementId.c_str())->SetProperty("width", BuildString(value, "px").c_str());
|
||||
}
|
||||
|
||||
INT32 UI::GetElementWidth(IN CONST String &elementId)
|
||||
{
|
||||
return g_document->GetElementById(elementId.c_str())->GetClientWidth();
|
||||
}
|
||||
|
||||
VOID UI::SetElementHeight(IN CONST String &elementId, IN INT32 value)
|
||||
{
|
||||
g_document->GetElementById(elementId.c_str())->SetProperty("height", BuildString(value, "px").c_str());
|
||||
}
|
||||
|
||||
INT32 UI::GetElementHeight(IN CONST String &elementId)
|
||||
{
|
||||
return g_document->GetElementById(elementId.c_str())->GetClientHeight();
|
||||
}
|
||||
} // namespace ia::iae
|
||||
|
||||
namespace ia::iae
|
||||
@ -540,7 +595,7 @@ namespace ia::iae
|
||||
Engine::SetRenderState_ColorOverlay({255, 255, 255, 255});
|
||||
Engine::SetRenderState_TextureOffset({0, 0});
|
||||
Engine::SetRenderState_CameraRelative(false);
|
||||
Engine::SetRenderState_TransformUI({translation.x, translation.y}, {1.0f, 1.0f}, 0);
|
||||
Engine::SetRenderState_Transform({translation.x, translation.y}, {1.0f, 1.0f}, 0);
|
||||
|
||||
Engine::DrawGeometry((Handle) geometry, 0xFF, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user