130 lines
3.2 KiB
C++
130 lines
3.2 KiB
C++
#include <GLFW/glfw3.h>
|
|
#include <RmlUi/Core/ElementDocument.h>
|
|
#include <RmlUi/Core/Event.h>
|
|
#include <RmlUi/Debugger/Debugger.h>
|
|
#include <RmlUi/Lua/Interpreter.h>
|
|
#include <iostream>
|
|
#include <RmlUi/Core/Context.h>
|
|
#include <RmlUi/Core/Math.h>
|
|
#include <RmlUi/Core.h>
|
|
#include <RmlUi_Backend.h>
|
|
#include <RmlUi/Debugger.h>
|
|
#include <RmlUi/Lua/Lua.h>
|
|
#include "app.hpp"
|
|
#include "element_registry.hpp"
|
|
#include "ButtonClickListener.hpp"
|
|
#include "lui_app_api.hpp"
|
|
#include <sqlite3.h>
|
|
|
|
static bool is_initalized = false;
|
|
static bool is_running = false;
|
|
static Rml::Context *ctx;
|
|
static App *app;
|
|
static ElementRegistry elementRegistry;
|
|
|
|
void RegisterElements() {
|
|
|
|
}
|
|
|
|
bool InitalizeApplication() {
|
|
if (!Backend::Initialize("RmlUi App Template", 800, 600, true)) {
|
|
std::cout << "[ERROR] backend was not initalized successfully.\n";
|
|
return false;
|
|
}
|
|
|
|
Rml::SetSystemInterface(Backend::GetSystemInterface());
|
|
Rml::SetRenderInterface(Backend::GetRenderInterface());
|
|
Rml::Initialise();
|
|
Rml::Lua::Initialise();
|
|
|
|
ctx = Rml::CreateContext("main", Rml::Vector2i(800,600));
|
|
if (!ctx) {
|
|
std::cout << "[ERROR] context was null.\n";
|
|
Rml::Shutdown();
|
|
Backend::Shutdown();
|
|
return false;
|
|
}
|
|
|
|
Rml::Debugger::Initialise(ctx);
|
|
|
|
app = new App(ctx, nullptr);
|
|
if (!app) {
|
|
std::cout << "[ERROR] app was null.\n";
|
|
Rml::Shutdown();
|
|
Backend::Shutdown();
|
|
return false;
|
|
}
|
|
|
|
std::string assets_dir = App::GetAssetsPath();
|
|
Rml::LoadFontFace(assets_dir + "/fonts/PTSerif-Regular.ttf");
|
|
|
|
lua_State* L = Rml::Lua::Interpreter::GetLuaState();
|
|
AppLuaApi *lua_app_api = new AppLuaApi(app, L);
|
|
lua_app_api->RegisterLuaBindings();
|
|
|
|
RegisterElements();
|
|
|
|
std::cout << "Application initalized...\n";
|
|
|
|
return true;
|
|
}
|
|
|
|
bool f5_was_pressed = false;
|
|
bool f8_was_pressed = false;
|
|
|
|
void handle_input() {
|
|
GLFWwindow *window = glfwGetCurrentContext();
|
|
if(window) {
|
|
// Reload ui
|
|
bool f5_state = glfwGetKey(window, GLFW_KEY_F5);
|
|
if (f5_state == GLFW_PRESS && !f5_was_pressed) {
|
|
f5_was_pressed = true;
|
|
app->Reload();
|
|
} else if (f5_state == GLFW_RELEASE) {
|
|
f5_was_pressed = false;
|
|
}
|
|
|
|
// Toggle debugger window
|
|
bool f8_state = glfwGetKey(window, GLFW_KEY_F8);
|
|
if (f8_state == GLFW_PRESS && !f8_was_pressed) {
|
|
f8_was_pressed = true;
|
|
bool is_visible = Rml::Debugger::IsVisible();
|
|
Rml::Debugger::SetVisible(!is_visible);
|
|
} else if (f8_state == GLFW_RELEASE) {
|
|
f8_was_pressed = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
std::cout << "Application starting...\n";
|
|
is_initalized = InitalizeApplication();
|
|
if (!is_initalized) return 1;
|
|
|
|
is_running = true;
|
|
|
|
std::cout << "Loading UI...\n";
|
|
|
|
app->LoadUi();
|
|
app->NavigateTo("home");
|
|
std::cout << "UI Loaded\n";
|
|
|
|
while (is_running) {
|
|
is_running = Backend::ProcessEvents(ctx);
|
|
|
|
handle_input();
|
|
|
|
ctx->Update();
|
|
Backend::BeginFrame();
|
|
ctx->Render();
|
|
Backend::PresentFrame();
|
|
}
|
|
|
|
app->Shutdown();
|
|
Rml::Shutdown();
|
|
delete app;
|
|
Backend::Shutdown();
|
|
|
|
return 0;
|
|
}
|