diff --git a/assets/demo.lua b/assets/demo.lua deleted file mode 100644 index 33056c0..0000000 --- a/assets/demo.lua +++ /dev/null @@ -1,9 +0,0 @@ --- Simple button click handler -click_count = 0 - -function onButtonClick(event) - click_count = click_count + 1 - local button = event.current_element - button.inner_rml = "Clicked " .. click_count .. " times!" - print("Button clicked! Count: " .. click_count) -end diff --git a/assets/demo.rml b/assets/demo.rml deleted file mode 100644 index 07c4c0e..0000000 --- a/assets/demo.rml +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - Virtual Smartphone - Home - - - - -
- 12:30 -
- * - + - | -
-
- - -
-
- -
-
P
- Phone -
-
-
M
- Messages -
-
-
C
- Contacts -
-
-
B
- Browser -
- - -
-
G
- Gallery -
-
-
C
- Camera -
-
-
S
- Settings -
-
-
M
- Music -
- - -
-
C
- Calendar -
-
-
C
- Clock -
-
-
N
- Notes -
-
-
M
- Maps -
- - -
-
S
- Store -
-
-
F
- Files -
-
-
C
- Calculator -
-
-
W
- Weather -
-
-
- - -
-
P
-
M
-
C
-
B
-
- -
diff --git a/assets/LatoLatin-Bold.ttf b/assets/fonts/LatoLatin-Bold.ttf similarity index 100% rename from assets/LatoLatin-Bold.ttf rename to assets/fonts/LatoLatin-Bold.ttf diff --git a/assets/LatoLatin-BoldItalic.ttf b/assets/fonts/LatoLatin-BoldItalic.ttf similarity index 100% rename from assets/LatoLatin-BoldItalic.ttf rename to assets/fonts/LatoLatin-BoldItalic.ttf diff --git a/assets/LatoLatin-Italic.ttf b/assets/fonts/LatoLatin-Italic.ttf similarity index 100% rename from assets/LatoLatin-Italic.ttf rename to assets/fonts/LatoLatin-Italic.ttf diff --git a/assets/LatoLatin-Regular.ttf b/assets/fonts/LatoLatin-Regular.ttf similarity index 100% rename from assets/LatoLatin-Regular.ttf rename to assets/fonts/LatoLatin-Regular.ttf diff --git a/assets/NotoEmoji-Regular.ttf b/assets/fonts/NotoEmoji-Regular.ttf similarity index 100% rename from assets/NotoEmoji-Regular.ttf rename to assets/fonts/NotoEmoji-Regular.ttf diff --git a/assets/icons/add.tga b/assets/icons/add.tga new file mode 100644 index 0000000..0115e11 Binary files /dev/null and b/assets/icons/add.tga differ diff --git a/assets/icons/back.tga b/assets/icons/back.tga new file mode 100644 index 0000000..3bc3512 Binary files /dev/null and b/assets/icons/back.tga differ diff --git a/assets/icons/backspace.tga b/assets/icons/backspace.tga new file mode 100644 index 0000000..f706582 Binary files /dev/null and b/assets/icons/backspace.tga differ diff --git a/assets/icons/battery.tga b/assets/icons/battery.tga new file mode 100644 index 0000000..838aaae Binary files /dev/null and b/assets/icons/battery.tga differ diff --git a/assets/icons/browser.tga b/assets/icons/browser.tga new file mode 100644 index 0000000..3ce232c Binary files /dev/null and b/assets/icons/browser.tga differ diff --git a/assets/icons/calculator.tga b/assets/icons/calculator.tga new file mode 100644 index 0000000..2a9db6c Binary files /dev/null and b/assets/icons/calculator.tga differ diff --git a/assets/icons/calendar.tga b/assets/icons/calendar.tga new file mode 100644 index 0000000..4f624c1 Binary files /dev/null and b/assets/icons/calendar.tga differ diff --git a/assets/icons/call_small.tga b/assets/icons/call_small.tga new file mode 100644 index 0000000..da6a556 Binary files /dev/null and b/assets/icons/call_small.tga differ diff --git a/assets/icons/camera.tga b/assets/icons/camera.tga new file mode 100644 index 0000000..c73e7a9 Binary files /dev/null and b/assets/icons/camera.tga differ diff --git a/assets/icons/clock.tga b/assets/icons/clock.tga new file mode 100644 index 0000000..c10b891 Binary files /dev/null and b/assets/icons/clock.tga differ diff --git a/assets/icons/close.tga b/assets/icons/close.tga new file mode 100644 index 0000000..d5a136a Binary files /dev/null and b/assets/icons/close.tga differ diff --git a/assets/icons/contact_phone.tga b/assets/icons/contact_phone.tga new file mode 100644 index 0000000..2b0f344 Binary files /dev/null and b/assets/icons/contact_phone.tga differ diff --git a/assets/icons/contacts.tga b/assets/icons/contacts.tga new file mode 100644 index 0000000..2257d3a Binary files /dev/null and b/assets/icons/contacts.tga differ diff --git a/assets/icons/dialpad.tga b/assets/icons/dialpad.tga new file mode 100644 index 0000000..cf901e9 Binary files /dev/null and b/assets/icons/dialpad.tga differ diff --git a/assets/icons/files.tga b/assets/icons/files.tga new file mode 100644 index 0000000..d0a3abc Binary files /dev/null and b/assets/icons/files.tga differ diff --git a/assets/icons/forward.tga b/assets/icons/forward.tga new file mode 100644 index 0000000..d9b954f Binary files /dev/null and b/assets/icons/forward.tga differ diff --git a/assets/icons/gallery.tga b/assets/icons/gallery.tga new file mode 100644 index 0000000..05140d3 Binary files /dev/null and b/assets/icons/gallery.tga differ diff --git a/assets/icons/history.tga b/assets/icons/history.tga new file mode 100644 index 0000000..6a98b68 Binary files /dev/null and b/assets/icons/history.tga differ diff --git a/assets/icons/home.tga b/assets/icons/home.tga new file mode 100644 index 0000000..af2b89d Binary files /dev/null and b/assets/icons/home.tga differ diff --git a/assets/icons/maps.tga b/assets/icons/maps.tga new file mode 100644 index 0000000..390b193 Binary files /dev/null and b/assets/icons/maps.tga differ diff --git a/assets/icons/menu.tga b/assets/icons/menu.tga new file mode 100644 index 0000000..6e984ce Binary files /dev/null and b/assets/icons/menu.tga differ diff --git a/assets/icons/message.tga b/assets/icons/message.tga new file mode 100644 index 0000000..717b202 Binary files /dev/null and b/assets/icons/message.tga differ diff --git a/assets/icons/more.tga b/assets/icons/more.tga new file mode 100644 index 0000000..73c1d5d Binary files /dev/null and b/assets/icons/more.tga differ diff --git a/assets/icons/music.tga b/assets/icons/music.tga new file mode 100644 index 0000000..81336f4 Binary files /dev/null and b/assets/icons/music.tga differ diff --git a/assets/icons/notes.tga b/assets/icons/notes.tga new file mode 100644 index 0000000..1e63cb7 Binary files /dev/null and b/assets/icons/notes.tga differ diff --git a/assets/icons/phone.tga b/assets/icons/phone.tga new file mode 100644 index 0000000..34c7289 Binary files /dev/null and b/assets/icons/phone.tga differ diff --git a/assets/icons/refresh.tga b/assets/icons/refresh.tga new file mode 100644 index 0000000..83e340f Binary files /dev/null and b/assets/icons/refresh.tga differ diff --git a/assets/icons/search.tga b/assets/icons/search.tga new file mode 100644 index 0000000..5f4c062 Binary files /dev/null and b/assets/icons/search.tga differ diff --git a/assets/icons/send.tga b/assets/icons/send.tga new file mode 100644 index 0000000..cf12b5c Binary files /dev/null and b/assets/icons/send.tga differ diff --git a/assets/icons/settings.tga b/assets/icons/settings.tga new file mode 100644 index 0000000..f348ad3 Binary files /dev/null and b/assets/icons/settings.tga differ diff --git a/assets/icons/signal.tga b/assets/icons/signal.tga new file mode 100644 index 0000000..909096a Binary files /dev/null and b/assets/icons/signal.tga differ diff --git a/assets/icons/store.tga b/assets/icons/store.tga new file mode 100644 index 0000000..7a5dbcf Binary files /dev/null and b/assets/icons/store.tga differ diff --git a/assets/icons/weather.tga b/assets/icons/weather.tga new file mode 100644 index 0000000..2c8f2ad Binary files /dev/null and b/assets/icons/weather.tga differ diff --git a/assets/icons/wifi.tga b/assets/icons/wifi.tga new file mode 100644 index 0000000..c2ba0a3 Binary files /dev/null and b/assets/icons/wifi.tga differ diff --git a/assets/phone.rcss b/assets/phone.rcss deleted file mode 100644 index 62ff982..0000000 --- a/assets/phone.rcss +++ /dev/null @@ -1,137 +0,0 @@ -/* Ensure the body fills the entire window */ -body { - font-family: LatoLatin; - width: 100%; - height: 100%; - margin: 0; - padding: 0; - background: #0f0f12; - color: white; -} - -/* Status Bar pinned to top */ -#status-bar { - display: block; - height: 140px; - padding: 10px 20px 0; - background-color: rgba(255, 0, 0, 0.2); -} - -.time { - float: left; - font-weight: bold; - font-size: 2em; -} - -.status-icons { - float: right; - font-size: 2em; -} - -.icon { - margin-left: 10px; -} - -/* Content area grows to fill space */ -#content { - padding: 20px; - /* Leaves room for status and nav bars */ - height: 80%; - align: center; -} - -.header-section { - margin-bottom: 30px; - text-align: center; -} - -h1 { - font-size: 2.5em; - font-weight: bold; -} - -/* Mobile-style cards */ -.card { - background: #1e1e24; - border-radius: 20px; - padding: 20px; - margin-bottom: 15px; - border: 1px solid #333; -} - -.card-title { - font-size: 1.2em; - margin-bottom: 10px; - color: #3498db; -} - -.progress-bar { - height: 8px; - background: #333; - border-radius: 4px; - margin: 10px 0; -} - -.progress-fill { - width: 84%; - height: 100%; - background: #3498db; - border-radius: 4px; -} - -/* Navigation Bar pinned to bottom */ -#nav-bar { - position: absolute; - bottom: 0; - width: 100%; - height: 65px; - background-color: #16161a; - display: flex; - justify-content: space-around; - align-items: center; - border-top: 1px solid #333; -} - -.nav-item { - font-size: 1.9em; - color: #888; - background-color: red; - width: 100px; - height: 100px; - text-align: center; - vertical-align: middle; - line-height: 90px; - border-radius: 10px; -} - -.nav-item:hover { - color: #3498db; - background-color: blue; -} - -/* Button container for centering */ -.button-container { - display: block; - text-align: center; - margin-top: 50px; -} - -/* Styled button */ -button { - padding: 20px 60px; - font-size: 1.5em; - font-family: LatoLatin; - font-weight: bold; - color: white; - background-color: #3498db; - border-radius: 12px; - cursor: pointer; -} - -button:hover { - background-color: #2980b9; -} - -button:active { - background-color: #1c5a85; -} \ No newline at end of file diff --git a/assets/screens/browser.rml b/assets/screens/browser.rml index eaac1c6..3287716 100644 --- a/assets/screens/browser.rml +++ b/assets/screens/browser.rml @@ -1,5 +1,6 @@ + @@ -173,14 +174,13 @@
-
-
+
+
- L
-
R
-
:
+
+
@@ -213,7 +213,7 @@
- H + Home
@@ -221,11 +221,11 @@ Tabs
- + + New Tab
- : + Menu
diff --git a/assets/screens/contacts.rml b/assets/screens/contacts.rml index 27b5a80..0d86905 100644 --- a/assets/screens/contacts.rml +++ b/assets/screens/contacts.rml @@ -1,5 +1,6 @@ + @@ -71,14 +72,14 @@
-
+
Contacts -
+
+
@@ -177,20 +178,20 @@ -
+
+
- * + Keypad
- O + Recent
- @ + Contacts
diff --git a/assets/screens/dialer.rml b/assets/screens/dialer.rml index 7eaee37..044aca8 100644 --- a/assets/screens/dialer.rml +++ b/assets/screens/dialer.rml @@ -1,5 +1,6 @@ + @@ -107,7 +108,7 @@
-
+
Phone
@@ -175,21 +176,21 @@
-
C
+
- * + Keypad
- O + Recent
- @ + Contacts
diff --git a/assets/screens/home.rml b/assets/screens/home.rml index 04076f7..64b1136 100644 --- a/assets/screens/home.rml +++ b/assets/screens/home.rml @@ -1,8 +1,10 @@ + - Home + + Virtual Smartphone - Home @@ -32,9 +41,9 @@
12:30
- * - + - | + + +
@@ -42,74 +51,74 @@
-
-
P
+
+
Phone
-
-
M
+
+
Messages
-
-
C
+
+
Contacts
-
-
B
+
+
Browser
-
G
+
Gallery
-
C
+
Camera
-
-
S
+
+
Settings
-
M
+
Music
-
C
+
Calendar
-
C
+
Clock
-
N
+
Notes
-
M
+
Maps
-
S
+
Store
-
F
+
Files
-
C
+
Calculator
-
W
+
Weather
@@ -117,10 +126,10 @@
-
P
-
M
-
C
-
B
+
+
+
+
diff --git a/assets/screens/lock.rml b/assets/screens/lock.rml index 91a5f9e..967e298 100644 --- a/assets/screens/lock.rml +++ b/assets/screens/lock.rml @@ -1,5 +1,6 @@ + @@ -168,8 +169,8 @@
-
P
-
C
+
+
diff --git a/assets/screens/messages.rml b/assets/screens/messages.rml index c900e1c..dbfd303 100644 --- a/assets/screens/messages.rml +++ b/assets/screens/messages.rml @@ -1,5 +1,6 @@ + @@ -131,9 +132,9 @@
-
+
Messages -
Q
+
@@ -218,6 +219,6 @@
-
+
+
diff --git a/assets/screens/settings.rml b/assets/screens/settings.rml index 3eb0551..98e489d 100644 --- a/assets/screens/settings.rml +++ b/assets/screens/settings.rml @@ -1,5 +1,6 @@ + @@ -149,9 +150,9 @@
-
+
Settings -
Q
+
diff --git a/assets/scripts/navigation.lua b/assets/scripts/navigation.lua index a78460c..ade3c60 100644 --- a/assets/scripts/navigation.lua +++ b/assets/scripts/navigation.lua @@ -3,7 +3,7 @@ -- Screen registry - maps screen names to RML file paths local screens = { - home = "demo.rml", + home = "screens/home.rml", lock = "screens/lock.rml", dialer = "screens/dialer.rml", contacts = "screens/contacts.rml", @@ -12,27 +12,36 @@ local screens = { browser = "screens/browser.rml" } --- Navigation history stack -local history = {} +-- Use global state to persist across document loads +-- Initialize only if not already set +if not _G.nav_state then + _G.nav_state = { + history = {}, + current_screen = "home" + } +end --- Current screen name -local current_screen = "home" +-- Local references for convenience +local history = _G.nav_state.history +local function get_current() return _G.nav_state.current_screen end +local function set_current(s) _G.nav_state.current_screen = s end -- Navigate to a screen by name function navigateTo(screen_name) + print("navigateTo called with: " .. tostring(screen_name)) local path = screens[screen_name] if path then -- Push current screen to history before navigating - table.insert(history, current_screen) - current_screen = screen_name + table.insert(history, get_current()) + set_current(screen_name) -- Load the new screen using C++ function local success = loadScreen(path) if success then - print("Navigated to: " .. screen_name) + print("Navigated to: " .. screen_name .. " (history depth: " .. #history .. ")") else -- Restore previous state on failure - current_screen = table.remove(history) + set_current(table.remove(history)) print("Failed to navigate to: " .. screen_name) end return success @@ -44,11 +53,12 @@ end -- Go back to previous screen function goBack() + print("goBack called (history depth: " .. #history .. ")") if #history > 0 then local previous = table.remove(history) local path = screens[previous] if path then - current_screen = previous + set_current(previous) loadScreen(path) print("Back to: " .. previous) return true @@ -61,15 +71,18 @@ end -- Go to home screen (clear history) function goHome() - history = {} - current_screen = "home" + -- Clear the history table + for i = #history, 1, -1 do + history[i] = nil + end + set_current("home") loadScreen(screens.home) print("Navigated to home") end -- Get current screen name function getCurrentScreen() - return current_screen + return get_current() end -- Check if we can go back @@ -79,7 +92,9 @@ end -- Clear navigation history function clearHistory() - history = {} + for i = #history, 1, -1 do + history[i] = nil + end end -- Get history depth @@ -87,4 +102,4 @@ function getHistoryDepth() return #history end -print("Navigation system initialized") +print("Navigation system initialized (current: " .. get_current() .. ", history: " .. #history .. ")") diff --git a/assets/html.rcss b/assets/ui/html.rcss similarity index 100% rename from assets/html.rcss rename to assets/ui/html.rcss diff --git a/main.cpp b/main.cpp index 523b44a..eab380a 100644 --- a/main.cpp +++ b/main.cpp @@ -29,6 +29,86 @@ struct AppState { std::filesystem::path assets_path; } g_app; +// Custom system interface to enable logging +class LoggingSystemInterface : public Rml::SystemInterface { +public: + LoggingSystemInterface(Rml::SystemInterface* backend) : backend_(backend) {} + + double GetElapsedTime() override { return backend_->GetElapsedTime(); } + + bool LogMessage(Rml::Log::Type type, const Rml::String& message) override { + const char* type_str = ""; + switch (type) { + case Rml::Log::LT_ERROR: type_str = "ERROR"; break; + case Rml::Log::LT_WARNING: type_str = "WARNING"; break; + case Rml::Log::LT_INFO: type_str = "INFO"; break; + case Rml::Log::LT_DEBUG: type_str = "DEBUG"; break; + default: type_str = "LOG"; break; + } + std::println("[RmlUi {}] {}", type_str, message); + return true; + } + + // Forward JoinPath to fix Windows path issues + void JoinPath(Rml::String& translated_path, const Rml::String& document_path, const Rml::String& path) override { + // Fix paths where colon was converted to pipe (D| -> D:) + std::string fixed_path = path; + if (fixed_path.length() >= 2 && fixed_path[1] == '|') { + fixed_path[1] = ':'; + } + + std::string fixed_doc = document_path; + if (fixed_doc.length() >= 2 && fixed_doc[1] == '|') { + fixed_doc[1] = ':'; + } + + // Use std::filesystem to join paths properly and normalize (resolve ..) + std::filesystem::path doc_dir = std::filesystem::path(fixed_doc).parent_path(); + std::filesystem::path result = (doc_dir / fixed_path).lexically_normal(); + translated_path = result.generic_string(); + std::println("JoinPath: {} + {} -> {}", fixed_doc, fixed_path, translated_path); + } + +private: + Rml::SystemInterface* backend_; +}; + +static LoggingSystemInterface* g_logging_interface = nullptr; + +// Custom file interface to fix Windows path issues (D| -> D:) +class WindowsFileInterface : public Rml::FileInterface { +public: + Rml::FileHandle Open(const Rml::String& path) override { + // Fix paths where colon was converted to pipe (D| -> D:) + std::string fixed_path = path; + if (fixed_path.length() >= 2 && fixed_path[1] == '|') { + fixed_path[1] = ':'; + } + std::println("FileInterface::Open: {} -> {}", path, fixed_path); + + FILE* fp = fopen(fixed_path.c_str(), "rb"); + return reinterpret_cast(fp); + } + + void Close(Rml::FileHandle file) override { + fclose(reinterpret_cast(file)); + } + + size_t Read(void* buffer, size_t size, Rml::FileHandle file) override { + return fread(buffer, 1, size, reinterpret_cast(file)); + } + + bool Seek(Rml::FileHandle file, long offset, int origin) override { + return fseek(reinterpret_cast(file), offset, origin) == 0; + } + + size_t Tell(Rml::FileHandle file) override { + return ftell(reinterpret_cast(file)); + } +}; + +static WindowsFileInterface* g_file_interface = nullptr; + void load_fonts(const std::filesystem::path& dir) { for (const auto& file : std::filesystem::directory_iterator(dir)) @@ -44,13 +124,15 @@ void load_fonts(const std::filesystem::path& dir) // Path is relative to assets folder int lua_loadScreen(lua_State* L) { + std::println("lua_loadScreen called!"); const char* path = luaL_checkstring(L, 1); + std::println("Loading: {}", path); std::filesystem::path full_path = g_app.assets_path / path; if (!std::filesystem::exists(full_path)) { - std::println("Screen not found: {}", full_path.string()); + std::println("Screen not found: {}", full_path.generic_string()); lua_pushboolean(L, false); return 1; } @@ -62,8 +144,10 @@ int lua_loadScreen(lua_State* L) g_app.document = nullptr; } - // Load new document - g_app.document = g_app.context->LoadDocument(full_path.string()); + // Load new document with absolute path + std::string full_path_str = full_path.generic_string(); + std::println("Full path: {}", full_path_str); + g_app.document = g_app.context->LoadDocument(full_path_str); if (g_app.document) { g_app.document->Show(); @@ -233,10 +317,15 @@ int main(const int argc, const char* argv[]) return EXIT_FAILURE; } - Rml::SetSystemInterface(Backend::GetSystemInterface()); + // Use custom interfaces + g_logging_interface = new LoggingSystemInterface(Backend::GetSystemInterface()); + g_file_interface = new WindowsFileInterface(); + Rml::SetSystemInterface(g_logging_interface); + Rml::SetFileInterface(g_file_interface); Rml::SetRenderInterface(Backend::GetRenderInterface()); Rml::Initialise(); Rml::Lua::Initialise(); + std::println("RmlUi and Lua initialized"); g_app.context = Rml::CreateContext("main", Rml::Vector2i(window_width, window_height)); if (!g_app.context) @@ -249,31 +338,46 @@ int main(const int argc, const char* argv[]) // Register custom Lua functions registerLuaFunctions(); - // Find the assets folder by checking for fonts + // Find the assets folder by checking for fonts/ subdirectory g_app.assets_path = std::filesystem::absolute(file.parent_path()); - // Walk up the directory tree to find a folder containing .ttf fonts + // Walk up the directory tree to find a folder containing a fonts/ subdirectory with .ttf files + std::filesystem::path fonts_path; while (!g_app.assets_path.empty() && g_app.assets_path.has_parent_path()) { - bool has_fonts = false; - for (const auto& entry : std::filesystem::directory_iterator(g_app.assets_path)) + fonts_path = g_app.assets_path / "fonts"; + if (std::filesystem::exists(fonts_path) && std::filesystem::is_directory(fonts_path)) { - if (entry.path().extension() == ".ttf") + bool has_fonts = false; + for (const auto& entry : std::filesystem::directory_iterator(fonts_path)) { - has_fonts = true; - break; + if (entry.path().extension() == ".ttf") + { + has_fonts = true; + break; + } } + if (has_fonts) break; } - if (has_fonts) break; g_app.assets_path = g_app.assets_path.parent_path(); } - load_fonts(g_app.assets_path); + load_fonts(fonts_path); - g_app.document = g_app.context->LoadDocument(file.string()); + // Load document with absolute path + std::filesystem::path abs_file = std::filesystem::absolute(file); + std::string abs_file_str = abs_file.generic_string(); + std::println("Loading document: {}", abs_file_str); + std::println("Assets path: {}", g_app.assets_path.generic_string()); + g_app.document = g_app.context->LoadDocument(abs_file_str); if (g_app.document) { g_app.document->Show(); + std::println("Document loaded successfully"); + } + else + { + std::println("Failed to load document!"); } // Dump mode: render and capture screenshot @@ -350,7 +454,7 @@ int main(const int argc, const char* argv[]) g_app.context->UnloadDocument(g_app.document); g_app.context->Update(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); - g_app.document = g_app.context->LoadDocument(file.string()); + g_app.document = g_app.context->LoadDocument(abs_file_str); if (g_app.document) { g_app.document->ReloadStyleSheet(); diff --git a/run.bat b/run.bat new file mode 100644 index 0000000..9993053 --- /dev/null +++ b/run.bat @@ -0,0 +1,6 @@ +@echo off +cd /d "%~dp0" +echo Current directory: %CD% +echo Running: build_lua\Debug\mosis-designer.exe assets\screens\home.rml +build_lua\Debug\mosis-designer.exe assets\screens\home.rml +pause