Files
MosisDesigner/main.cpp
2026-01-06 23:44:42 +01:00

96 lines
2.5 KiB
C++

#include <print>
#include <thread>
#include <chrono>
#include <filesystem>
#include <RmlUi/Core.h>
#include <RmlUi/Debugger.h>
#include <RmlUi_Backend.h>
#include <RmlUi_Include_Windows.h>
void load_fonts()
{
const Rml::String directory = "assets/";
struct FontFace {
const char* filename;
bool fallback_face;
};
FontFace font_faces[] = {
{"LatoLatin-Regular.ttf", false},
{"LatoLatin-Italic.ttf", false},
{"LatoLatin-Bold.ttf", false},
{"LatoLatin-BoldItalic.ttf", false},
{"NotoEmoji-Regular.ttf", true},
};
for (const FontFace& face : font_faces)
Rml::LoadFontFace(directory + face.filename, face.fallback_face);
}
int main()
{
const int window_width = 1024;
const int window_height = 768;
if (!Backend::Initialize("Load Document Sample", window_width, window_height, true))
{
return -1;
}
Rml::SetSystemInterface(Backend::GetSystemInterface());
Rml::SetRenderInterface(Backend::GetRenderInterface());
Rml::Initialise();
Rml::Context* context = Rml::CreateContext("main", Rml::Vector2i(window_width, window_height));
if (!context)
{
Rml::Shutdown();
Backend::Shutdown();
return -1;
}
load_fonts();
Rml::ElementDocument* document = context->LoadDocument("assets/demo.rml");
if (document)
{
document->Show();
}
const std::wstring assets_path = std::filesystem::absolute(
std::filesystem::current_path() / "assets").wstring();
HANDLE hNotif = FindFirstChangeNotification(assets_path.c_str(),
TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE);
bool running = true;
while (running)
{
if (const DWORD wait_result = WaitForSingleObject(hNotif, 100);
wait_result == WAIT_OBJECT_0)
{
if (document)
context->UnloadDocument(document);
context->Update();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
document = context->LoadDocument("assets/demo.rml");
if (document)
{
document->ReloadStyleSheet();
document->Show();
}
FindNextChangeNotification(hNotif);
}
running = Backend::ProcessEvents(context);
context->Update();
Backend::BeginFrame();
context->Render();
Backend::PresentFrame();
}
Rml::Shutdown();
Backend::Shutdown();
return EXIT_SUCCESS;
}