99 lines
2.5 KiB
C++
99 lines
2.5 KiB
C++
#include <print>
|
|
#include <thread>
|
|
#include <chrono>
|
|
#include <filesystem>
|
|
#include <iostream>
|
|
#include <RmlUi/Core.h>
|
|
#include <RmlUi/Debugger.h>
|
|
#include <RmlUi_Backend.h>
|
|
#include <RmlUi_Include_Windows.h>
|
|
|
|
void load_fonts(const std::filesystem::path& dir)
|
|
{
|
|
for (const auto& file : std::filesystem::directory_iterator(dir))
|
|
{
|
|
if (file.path().extension() == ".ttf")
|
|
{
|
|
Rml::LoadFontFace(file.path().string());
|
|
}
|
|
}
|
|
}
|
|
|
|
int main(const int argc, const char* argv[])
|
|
{
|
|
constexpr int window_width = 540;
|
|
constexpr int window_height = 960;
|
|
|
|
if (argc < 2)
|
|
{
|
|
std::println("Usage: mosis-designer file.rml");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
const std::filesystem::path file = argv[1];
|
|
if (!std::filesystem::exists(file))
|
|
{
|
|
std::println("File does not exist");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
if (!Backend::Initialize("Load Document Sample", window_width, window_height, true))
|
|
{
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
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 EXIT_FAILURE;
|
|
}
|
|
|
|
const std::filesystem::path assets_path = std::filesystem::absolute(file.parent_path());
|
|
load_fonts(assets_path);
|
|
|
|
Rml::ElementDocument* document = context->LoadDocument(file.string());
|
|
if (document)
|
|
{
|
|
document->Show();
|
|
}
|
|
|
|
const 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(file.string());
|
|
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;
|
|
}
|