This commit is contained in:
Isuru Samarathunga
2025-09-22 22:58:44 +05:30
parent 8793554994
commit afaced62d4
2 changed files with 77 additions and 5 deletions

View File

@ -314,15 +314,26 @@ namespace ia::iae
namespace ia::iae
{
Rml::Context *g_context{};
BOOL g_debuggerEnabled{false};
struct MainDataModel
{
Rml::String InputValues[10];
} g_mainDataModel;
VOID UI::Initialize(IN INT32 width, IN INT32 height)
{
Rml::SetRenderInterface(&g_rmlUIRenderInterface);
Rml::Initialise();
g_context = Rml::CreateContext("main", Rml::Vector2i(width, height));
//Rml::Debugger::Initialise(g_context);
//Rml::Debugger::SetVisible(true);
//Rml::LoadFontFace("Roboto-Black.ttf");
Rml::Debugger::Initialise(g_context);
DisableDebugger();
if (auto dataModel = g_context->CreateDataModel("main"))
{
for (INT32 i = 0; i < ((sizeof(MainDataModel::InputValues) / sizeof(MainDataModel::InputValues[0]))); i++)
dataModel.Bind(BuildString("InputValue", i).c_str(), &g_mainDataModel.InputValues[i]);
}
}
VOID UI::Terminate()
@ -356,6 +367,13 @@ namespace ia::iae
g_context->ProcessMouseButtonDown(SDLMouseButtonToRml(event->button.button), keymods);
break;
case SDL_EventType::SDL_EVENT_KEY_DOWN:
if (event->key.key == SDLK_F8)
{
if (g_debuggerEnabled)
DisableDebugger();
else
EnableDebugger();
}
g_context->ProcessKeyDown(SDLKeyToRml(event->key.key), keymods);
break;
case SDL_EventType::SDL_EVENT_KEY_UP:
@ -369,6 +387,45 @@ namespace ia::iae
}
} // namespace ia::iae
namespace ia::iae
{
VOID UI::AddFontFromFile(IN CONST String &path)
{
Rml::LoadFontFace(path.c_str());
}
VOID UI::EnableDebugger()
{
Rml::Debugger::SetVisible(g_debuggerEnabled = true);
}
VOID UI::DisableDebugger()
{
Rml::Debugger::SetVisible(g_debuggerEnabled = false);
}
Handle UI::AddWindowFromFile(IN CONST String &path)
{
return (Handle) g_context->LoadDocument(path.c_str());
}
VOID UI::ShowWindow(IN Handle handle)
{
reinterpret_cast<Rml::ElementDocument *>(handle)->Show();
}
VOID UI::HideWindow(IN Handle handle)
{
reinterpret_cast<Rml::ElementDocument *>(handle)->Hide();
}
VOID UI::AddClickEvent(IN Handle handle, IN PCCHAR elementId, IN std::function<VOID()> callback)
{
const auto doc = reinterpret_cast<Rml::ElementDocument *>(handle);
}
} // namespace ia::iae
namespace ia::iae
{
Rml::CompiledGeometryHandle RmlUIRenderInterface::CompileGeometry(Rml::Span<const Rml::Vertex> vertices,

View File

@ -22,7 +22,20 @@ namespace ia::iae
{
class UI
{
public:
public:
STATIC VOID AddFontFromFile(IN CONST String &path);
STATIC Handle AddWindowFromFile(IN CONST String &path);
STATIC VOID ShowWindow(IN Handle handle);
STATIC VOID HideWindow(IN Handle handle);
STATIC VOID AddClickEvent(IN Handle handle, IN PCCHAR elementId, IN std::function<VOID()> callback);
STATIC VOID EnableDebugger();
STATIC VOID DisableDebugger();
private:
STATIC VOID Initialize(IN INT32 width, IN INT32 height);
STATIC VOID Terminate();
@ -31,5 +44,7 @@ namespace ia::iae
STATIC VOID OnEvent(IN PVOID event);
STATIC VOID OnResize(IN INT32 width, IN INT32 height);
friend class Engine;
};
}
} // namespace ia::iae