work in progress
This commit is contained in:
@@ -8,12 +8,17 @@
|
||||
#include <android/asset_manager.h>
|
||||
#include <RmlUi/Core.h>
|
||||
#include <RmlUi/Lua.h>
|
||||
#include <RmlUi/Lua/Interpreter.h>
|
||||
#include "RmlUi_Renderer_GL3.h"
|
||||
#include <span>
|
||||
#include <ranges>
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
|
||||
// Global state for Lua access
|
||||
static Rml::Context* g_context = nullptr;
|
||||
static Rml::ElementDocument* g_document = nullptr;
|
||||
|
||||
using namespace aidl::com::omixlab::mosis;
|
||||
using namespace aidl::android::hardware;
|
||||
|
||||
@@ -88,6 +93,62 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// Lua function to load a screen document
|
||||
static int LuaLoadScreen(lua_State* L)
|
||||
{
|
||||
if (!g_context)
|
||||
{
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* path = luaL_checkstring(L, 1);
|
||||
Logger::Log(std::format("Loading screen: {}", path));
|
||||
|
||||
// Check if asset exists
|
||||
AAssetManager* am = AssetsManager::Native();
|
||||
AAsset* asset = AAssetManager_open(am, path, AASSET_MODE_BUFFER);
|
||||
if (!asset)
|
||||
{
|
||||
Logger::Log(std::format("Screen not found: {}", path));
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
AAsset_close(asset);
|
||||
|
||||
// Unload current document
|
||||
if (g_document)
|
||||
{
|
||||
g_context->UnloadDocument(g_document);
|
||||
g_document = nullptr;
|
||||
}
|
||||
|
||||
// Load new document
|
||||
g_document = g_context->LoadDocument(path);
|
||||
if (g_document)
|
||||
{
|
||||
g_document->Show();
|
||||
Logger::Log(std::format("Loaded screen: {}", path));
|
||||
lua_pushboolean(L, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Log(std::format("Failed to load screen: {}", path));
|
||||
lua_pushboolean(L, false);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Register Lua functions for navigation
|
||||
static void RegisterLuaFunctions()
|
||||
{
|
||||
lua_State* L = Rml::Lua::Interpreter::GetLuaState();
|
||||
lua_pushcfunction(L, LuaLoadScreen);
|
||||
lua_setglobal(L, "loadScreen");
|
||||
Logger::Log("Registered Lua loadScreen function");
|
||||
}
|
||||
|
||||
void Kernel::main_loop()
|
||||
{
|
||||
m_egl_context = std::make_unique<egl::Context>();
|
||||
@@ -122,28 +183,35 @@ void Kernel::main_loop()
|
||||
Rml::Initialise();
|
||||
Rml::Lua::Initialise();
|
||||
Logger::Log("RmlUi Lua bindings initialized");
|
||||
Rml::Context* context = Rml::CreateContext("default", Rml::Vector2i(540, 960));
|
||||
if (!context)
|
||||
|
||||
// Register navigation functions with Lua
|
||||
RegisterLuaFunctions();
|
||||
|
||||
g_context = Rml::CreateContext("default", Rml::Vector2i(540, 960));
|
||||
if (!g_context)
|
||||
{
|
||||
Logger::Log("RMLUI failed to create a context");
|
||||
Rml::Shutdown();
|
||||
return;
|
||||
}
|
||||
Rml::LoadFontFace("Roboto/static/Roboto_Condensed-Regular.ttf");
|
||||
Rml::LoadFontFace("LatoLatin-Regular.ttf");
|
||||
Rml::LoadFontFace("NotoEmoji-Regular.ttf", true);
|
||||
// Load fonts from assets/fonts/
|
||||
Rml::LoadFontFace("fonts/LatoLatin-Bold.ttf");
|
||||
Rml::LoadFontFace("fonts/LatoLatin-BoldItalic.ttf");
|
||||
Rml::LoadFontFace("fonts/LatoLatin-Italic.ttf");
|
||||
Rml::LoadFontFace("fonts/LatoLatin-Regular.ttf");
|
||||
Rml::LoadFontFace("fonts/NotoEmoji-Regular.ttf", true);
|
||||
Rml::LoadFontFace("fonts/Roboto/Roboto-VariableFont_wdth,wght.ttf");
|
||||
Rml::LoadFontFace("fonts/Roboto/Roboto-Italic-VariableFont_wdth,wght.ttf");
|
||||
|
||||
std::string status_time = "0";
|
||||
Rml::DataModelHandle status_time_handle;
|
||||
if (Rml::DataModelConstructor status_data_ctor = context->CreateDataModel("status-data"))
|
||||
// Load home screen document
|
||||
g_document = g_context->LoadDocument("apps/home/home.rml");
|
||||
if (!g_document)
|
||||
{
|
||||
status_data_ctor.Bind("time", &status_time);
|
||||
status_time_handle = status_data_ctor.GetModelHandle();
|
||||
Logger::Log("Failed to load home.rml document");
|
||||
Rml::Shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
// Now we are ready to load our document.
|
||||
Rml::ElementDocument* document = context->LoadDocument("demo.rml");
|
||||
document->Show();
|
||||
g_document->Show();
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -151,7 +219,7 @@ void Kernel::main_loop()
|
||||
{
|
||||
std::lock_guard _lock(m_mutex);
|
||||
for (const auto &task: m_tasks)
|
||||
task(context);
|
||||
task(g_context);
|
||||
m_tasks.clear();
|
||||
}
|
||||
|
||||
@@ -160,14 +228,10 @@ void Kernel::main_loop()
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, 540, 960);
|
||||
|
||||
status_time = std::format("{:%H:%M:%S}",
|
||||
std::chrono::floor<std::chrono::seconds>(std::chrono::system_clock::now()));
|
||||
status_time_handle.DirtyAllVariables();
|
||||
|
||||
context->Update();
|
||||
g_context->Update();
|
||||
rmlui_render_interface.SetViewport(540, 960);
|
||||
rmlui_render_interface.BeginFrame();
|
||||
context->Render();
|
||||
g_context->Render();
|
||||
rmlui_render_interface.EndFrame(m_render_target->framebuffer());
|
||||
|
||||
glFinish();
|
||||
@@ -176,7 +240,7 @@ void Kernel::main_loop()
|
||||
for (const auto& [pid, l] : m_listeners)
|
||||
l->onFrameAvailable();
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(16)); // ~60 FPS
|
||||
}
|
||||
Rml::Shutdown();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user