save state
This commit is contained in:
70
AGENTS.md
Normal file
70
AGENTS.md
Normal file
@@ -0,0 +1,70 @@
|
||||
# MosisService Agent Guidelines
|
||||
|
||||
## Build, Lint, and Test Commands
|
||||
|
||||
### Build Commands
|
||||
- `./gradlew build` - Build the entire project
|
||||
- `./gradlew assembleDebug` - Build debug version
|
||||
- `./gradlew assembleRelease` - Build release version
|
||||
- `./gradlew clean` - Clean build outputs
|
||||
- `./gradlew :app:build` - Build specific module (if needed)
|
||||
|
||||
### Lint Commands
|
||||
- `./gradlew lint` - Run lint checks
|
||||
- `./gradlew lintDebug` - Run lint for debug build
|
||||
- `./gradlew lintRelease` - Run lint for release build
|
||||
|
||||
### Test Commands
|
||||
- `./gradlew test` - Run unit tests
|
||||
- `./gradlew connectedAndroidTest` - Run connected device tests
|
||||
- `./gradlew testDebugUnitTest` - Run debug unit tests
|
||||
- `./gradlew testReleaseUnitTest` - Run release unit tests
|
||||
- `./gradlew :app:test` - Run tests for specific module
|
||||
- `./gradlew :app:testDebugUnitTest` - Test specific module debug unit tests
|
||||
|
||||
**Important Note:** The project contains C++ native code that uses CMake with both `mosis-service` and `mosis-test` libraries defined in `CMakeLists.txt`. Tests are built as shared libraries with the suffix `.so`.
|
||||
|
||||
## Code Style Guidelines
|
||||
|
||||
### Naming Conventions
|
||||
- `PascalCase` for class and function names (e.g., `MosisService`, `RenderTexture`)
|
||||
- `camelCase` for variables and parameters (e.g., `renderTarget`, `inputData`)
|
||||
- `UPPER_CASE` for constants (e.g., `MAX_BUFFER_SIZE`, `DEFAULT_TIMEOUT`)
|
||||
- Class names should be descriptive and follow Android naming conventions (e.g., `MosisService`)
|
||||
- Files should use meaningful names that match their content
|
||||
|
||||
### Imports & Formatting
|
||||
- Import statements are grouped logically: Android imports, third-party imports, first-party imports
|
||||
- Imports are sorted alphabetically within each group
|
||||
- Use of fully qualified names is allowed for clarity when needed
|
||||
|
||||
### Types & Variables
|
||||
- Use primitive types when possible
|
||||
- Use `final` keyword for constants
|
||||
- Prefer `val` over `var` in Kotlin
|
||||
- Use `final` for native C++ variables that don't change
|
||||
- Use appropriate data types (int, long, float, double) based on precision requirements
|
||||
|
||||
### Error Handling
|
||||
- C++ code uses standard C++ exception handling
|
||||
- Android code leverages standard Android error handling patterns
|
||||
- Use try-catch blocks appropriately in Kotlin code
|
||||
- Log errors via Android's logging framework in Kotlin
|
||||
- C++ logging via `logger.cpp` component
|
||||
|
||||
### Coding Standards
|
||||
- Follow Android development best practices
|
||||
- C++ code should follow modern C++23 conventions (including use of std::span, std::format, etc.)
|
||||
- Use RAII (Resource Acquisition Is Initialization) principles in C++
|
||||
- Ensure memory management is handled properly in native code
|
||||
- Avoid magic numbers in C++ code - use constants instead
|
||||
- Use smart pointers like `std::unique_ptr` and `std::shared_ptr` where appropriate
|
||||
- Proper resource cleanup in destructors
|
||||
- Avoid memory leaks in C++ components
|
||||
|
||||
### Structure
|
||||
- Kotlin code following Android project structures
|
||||
- C++ code organized in separate files within `src/main/cpp/`
|
||||
- Clear separation between platform-specific code and shared logic
|
||||
- Use Android build system capabilities for multi-architecture support
|
||||
- Follow Gradle conventions for dependency management
|
||||
96
ARCHITECTURE.md
Normal file
96
ARCHITECTURE.md
Normal file
@@ -0,0 +1,96 @@
|
||||
# MosisService Architecture
|
||||
|
||||
## Overview
|
||||
MosisService is an Android application that combines Kotlin UI components with native C++ libraries for UI rendering and system interaction. The architecture is built around a service-oriented design using Android's Binder system and integrates with RmlUi for rich UI rendering.
|
||||
|
||||
## Core Components
|
||||
|
||||
### 1. Service Layer (mosis-service)
|
||||
- **Purpose**: Main Android Binder service implementation
|
||||
- **Interface**: Implements `IMosisService.aidl`
|
||||
- **Functionality**:
|
||||
- Touch event processing (onTouchDown, onTouchMove, onTouchUp)
|
||||
- Service initialization and listener management
|
||||
- Integration with kernel-based rendering system
|
||||
- Asset loading through Android AssetManager
|
||||
|
||||
### 2. Rendering Layer (mosis-test)
|
||||
- **Purpose**: UI rendering and testing infrastructure
|
||||
- **Interface**: Implements `IMosisListener.aidl`
|
||||
- **Functionality**:
|
||||
- OpenGL ES 2.0 rendering pipeline using GLAD
|
||||
- Multi-threaded rendering with EGL context management
|
||||
- Surface and buffer handling for Android native windows
|
||||
- Task queue management for asynchronous rendering operations
|
||||
- Hardware buffer management and processing
|
||||
|
||||
### 3. Core Engine (Kernel)
|
||||
- **Purpose**: Central rendering and event processing engine
|
||||
- **Components**:
|
||||
- RmlUi-based UI rendering engine
|
||||
- EGL context creation and management
|
||||
- Render target handling
|
||||
- Touch event processing and UI updates
|
||||
- Multi-threaded execution using std::thread
|
||||
|
||||
### 4. Supporting Libraries
|
||||
- **AssetsManager**: Asset loading from Android AssetManager
|
||||
- **Logger**: Cross-platform logging system
|
||||
- **EGL Context**: OpenGL ES context management
|
||||
- **Render Target**: Framebuffer and buffer management
|
||||
- **Shader**: OpenGL shader program handling
|
||||
- **External Texture**: Hardware buffer texture creation
|
||||
|
||||
## System Architecture
|
||||
|
||||
### Android Binder Integration
|
||||
- Uses AIDL (Android Interface Definition Language) for cross-process communication
|
||||
- Service exposes `IMosisService` interface for touch events and initialization
|
||||
- Listener pattern with `IMosisListener` for rendering callbacks
|
||||
- Binds to Java/Kotlin components through JNI
|
||||
|
||||
### Multi-threading Model
|
||||
- Service layer runs in main thread for event handling
|
||||
- Rendering loop runs in dedicated thread managed by Kernel
|
||||
- Async task processing for UI updates
|
||||
- Thread-safe communication between components
|
||||
|
||||
### Rendering Pipeline
|
||||
1. **Initialization**: Service connects to test layer, creates EGL context
|
||||
2. **Buffer Management**: Hardware buffers allocated and shared between layers
|
||||
3. **Event Processing**: Touch events processed and forwarded to Kernel
|
||||
4. **Rendering Loop**: Continuous rendering with frame synchronization
|
||||
5. **UI Updates**: RmlUi engine updates UI based on events and data
|
||||
|
||||
### Data Flow
|
||||
```
|
||||
User Touch Events → IMosisService.onTouch* → Kernel.process → RmlUi UI Updates
|
||||
Service Initialized → IMosisListener.onServiceInitialized → Rendering Setup
|
||||
Buffer Available → IMosisListener.onBufferAvailable → Texture Creation
|
||||
Frame Available → IMosisListener.onFrameAvailable → Frame Rendering
|
||||
```
|
||||
|
||||
## Key Technologies
|
||||
- **Android NDK**: Native development with C++23
|
||||
- **CMake**: Build system for native libraries
|
||||
- **RmlUi**: UI rendering engine with HTML/CSS-like markup
|
||||
- **OpenGL ES 2.0**: Graphics rendering
|
||||
- **GLAD**: OpenGL loader library
|
||||
- **AIDL**: Inter-process communication
|
||||
- **Binder**: Android's IPC mechanism
|
||||
|
||||
## File Structure
|
||||
- `mosis-service.cpp`: Main service implementation
|
||||
- `mosis-test.cpp`: Test/rendering implementation
|
||||
- `kernel.cpp`: Core rendering engine and event processing
|
||||
- `assets_manager.cpp`: Asset loading utilities
|
||||
- `egl_context.cpp`: EGL context management
|
||||
- `render_target.cpp`: Framebuffer handling
|
||||
- `logger.cpp`: Cross-platform logging
|
||||
|
||||
## Code Standards
|
||||
- Modern C++23 with smart pointers and RAII
|
||||
- Thread-safe operations using std::mutex
|
||||
- Resource management with proper cleanup
|
||||
- Use of std::span, std::format for modern features
|
||||
- Cross-platform compatibility through Android NDK
|
||||
210
BUILD.md
Normal file
210
BUILD.md
Normal file
@@ -0,0 +1,210 @@
|
||||
# MosisService Build Configuration
|
||||
|
||||
## Overview
|
||||
This document outlines the build configuration and toolchain information for the MosisService project, optimized for maximum compiler feedback and debugging capabilities on Windows.
|
||||
|
||||
## Gradle Build Configuration
|
||||
|
||||
### Build Flags and Options
|
||||
The project uses Gradle with Android build system that includes the following optimization flags:
|
||||
|
||||
### Android Build Configuration
|
||||
In `build.gradle.kts`:
|
||||
- Compile SDK: API level 36 (Android 14)
|
||||
- Target SDK: API level 36
|
||||
- Min SDK: API level 34 (Android 14)
|
||||
- ndkVersion: 29.0.14206865
|
||||
- ABI: arm64-v8a only
|
||||
|
||||
### Optimization and Debug Flags
|
||||
- JVM target: JDK 11
|
||||
- C++ standard: C++23
|
||||
- Debug builds include full symbol information
|
||||
- Release builds include optimization flags (-O2)
|
||||
|
||||
## CMake Build Configuration
|
||||
|
||||
### CMake Flags for Maximum Feedback
|
||||
In `CMakeLists.txt`:
|
||||
```
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
```
|
||||
|
||||
### Compiler Flags for Windows
|
||||
```
|
||||
# Debug flags for maximum feedback
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wextra -Wpedantic -Werror")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||
|
||||
# Enable all warnings
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-unused-variable")
|
||||
```
|
||||
|
||||
### C++23 Features and Debugging
|
||||
- Enabled C++23 standard with std::span, std::format
|
||||
- Debug build includes full debug symbols
|
||||
- Address Sanitizer enabled in debug builds
|
||||
- Undefined Behavior Sanitizer enabled in debug builds
|
||||
|
||||
## Windows Build Toolchain
|
||||
|
||||
### Required Tools
|
||||
1. **Android Studio with Android NDK**
|
||||
- Android SDK
|
||||
- Android NDK (version 29.0.14206865)
|
||||
- CMake (version 3.22.1 or higher)
|
||||
|
||||
2. **Visual Studio 2022**
|
||||
- C++ development tools
|
||||
- Windows SDK
|
||||
- CMake tools for Visual Studio
|
||||
|
||||
3. **vcpkg**
|
||||
- Package manager for dependencies
|
||||
- RmlUi with Lua support (if available)
|
||||
|
||||
### Environment Variables
|
||||
```
|
||||
ANDROID_HOME=C:\Users\%USERNAME%\AppData\Local\Android\Sdk
|
||||
ANDROID_NDK_HOME=C:\Users\%USERNAME%\AppData\Local\Android\Sdk\ndk\29.0.14206865
|
||||
VCPKG_ROOT=C:\Tools\vcpkg
|
||||
```
|
||||
|
||||
### Build Commands
|
||||
For maximum feedback:
|
||||
|
||||
#### Debug Build with All Warnings
|
||||
```
|
||||
./gradlew assembleDebug -Pandroid.jetifier.enable=true -Pandroid.build.legacyBundleTool=false
|
||||
```
|
||||
|
||||
#### Release Build with Optimization
|
||||
```
|
||||
./gradlew assembleRelease -Pandroid.jetifier.enable=true -Pandroid.build.legacyBundleTool=false
|
||||
```
|
||||
|
||||
## Build Process Steps
|
||||
|
||||
### 1. Prerequisites Setup
|
||||
- Install Android Studio with NDK
|
||||
- Install Visual Studio 2022 with C++ tools
|
||||
- Set up vcpkg and install required dependencies
|
||||
- Configure environment variables
|
||||
|
||||
### 2. Build Configuration
|
||||
```
|
||||
# Clean previous builds
|
||||
./gradlew clean
|
||||
|
||||
# Build with verbose output for maximum feedback
|
||||
./gradlew build --info --stacktrace --configure-on-demand
|
||||
|
||||
# Build with all warnings enabled
|
||||
./gradlew compileDebugKotlin --warning-mode all
|
||||
```
|
||||
|
||||
### 3. CMake Configuration
|
||||
To enable full compiler feedback in CMake:
|
||||
```
|
||||
# Debug configuration with all warnings
|
||||
cmake -DCMAKE_BUILD_TYPE=Debug
|
||||
-DCMAKE_CXX_FLAGS_DEBUG="-g -O0 -Wall -Wextra -Wpedantic -Werror -fsanitize=address,undefined"
|
||||
-DCMAKE_CXX_STANDARD=23
|
||||
-DCMAKE_CXX_STANDARD_REQUIRED=ON
|
||||
.
|
||||
|
||||
# Release configuration
|
||||
cmake -DCMAKE_BUILD_TYPE=Release
|
||||
-DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG -flto=full"
|
||||
.
|
||||
```
|
||||
|
||||
## Output Locations
|
||||
|
||||
### Android APKs
|
||||
```
|
||||
build\outputs\apk\debug\app-debug.apk
|
||||
build\outputs\apk\release\app-release-unsigned.apk
|
||||
```
|
||||
|
||||
### Native Libraries
|
||||
```
|
||||
build\intermediates\cmake\debug\obj\arm64-v8a\libmosis-service.so
|
||||
build\intermediates\cmake\debug\obj\arm64-v8a\libmosis-test.so
|
||||
```
|
||||
|
||||
### Build Artifacts
|
||||
```
|
||||
build\intermediates\cxx\Debug\1r2562ic\arm64-v8a\
|
||||
build\intermediates\cmake\debug\output\lib\arm64-v8a\
|
||||
```
|
||||
|
||||
## Troubleshooting Build Issues
|
||||
|
||||
### Common Debug Flags
|
||||
```
|
||||
# Enable verbose C++ compilation
|
||||
./gradlew compileDebugCpp --info
|
||||
|
||||
# Enable all warnings and stop on first error
|
||||
./gradlew build -PcompileDebugCpp.warningMode=all
|
||||
|
||||
# Show compiler output
|
||||
./gradlew build --console=plain
|
||||
```
|
||||
|
||||
### Debugging Symbols
|
||||
To include debugging symbols:
|
||||
```
|
||||
# In CMakeLists.txt
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3 -ggdb")
|
||||
```
|
||||
|
||||
### Compiler-Specific Flags
|
||||
```
|
||||
# For MSVC (if using Visual Studio)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 /WX /Od /Zi")
|
||||
|
||||
# For Clang (if building with clang)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fstandalone-debug -fexceptions -frtti")
|
||||
```
|
||||
|
||||
## Toolchain Locations
|
||||
|
||||
### Android SDK
|
||||
```
|
||||
C:\Users\%USERNAME%\AppData\Local\Android\Sdk
|
||||
```
|
||||
|
||||
### Android NDK
|
||||
```
|
||||
C:\Users\%USERNAME%\AppData\Local\Android\Sdk\ndk\29.0.14206865
|
||||
```
|
||||
|
||||
### Visual Studio Tools
|
||||
```
|
||||
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64\
|
||||
```
|
||||
|
||||
### CMake Location
|
||||
```
|
||||
C:\Program Files\CMake\bin\cmake.exe
|
||||
```
|
||||
|
||||
## Recommended Build Commands
|
||||
|
||||
### For Development with Maximum Feedback
|
||||
```
|
||||
# Clean and build with maximum warnings
|
||||
./gradlew clean && ./gradlew build --warning-mode all --info --stacktrace
|
||||
|
||||
# Debug build with sanitizer
|
||||
./gradlew assembleDebug -Pandroid.jetifier.enable=true
|
||||
```
|
||||
|
||||
### For Release Builds
|
||||
```
|
||||
# Release build with optimization
|
||||
./gradlew assembleRelease -Pandroid.jetifier.enable=true
|
||||
```
|
||||
94
CLAUDE.md
Normal file
94
CLAUDE.md
Normal file
@@ -0,0 +1,94 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Build Commands
|
||||
|
||||
```bash
|
||||
# Build entire project
|
||||
./gradlew build
|
||||
|
||||
# Build debug APK
|
||||
./gradlew assembleDebug
|
||||
|
||||
# Build release APK
|
||||
./gradlew assembleRelease
|
||||
|
||||
# Clean build outputs
|
||||
./gradlew clean
|
||||
|
||||
# Build with verbose output
|
||||
./gradlew build --info --stacktrace
|
||||
|
||||
# Run lint checks
|
||||
./gradlew lint
|
||||
|
||||
# Run unit tests
|
||||
./gradlew test
|
||||
|
||||
# Run connected device tests
|
||||
./gradlew connectedAndroidTest
|
||||
```
|
||||
|
||||
## Environment Requirements
|
||||
|
||||
Required environment variables:
|
||||
- `ANDROID_HOME` - Android SDK path
|
||||
- `ANDROID_NDK_HOME` - Android NDK path (version 29.0.14206865)
|
||||
- `VCPKG_ROOT` - vcpkg package manager root
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
MosisService is an Android application combining Kotlin UI with native C++ libraries for UI rendering via Android's Binder IPC system.
|
||||
|
||||
### Two Native Libraries
|
||||
|
||||
**mosis-service** (`libmosis-service.so`):
|
||||
- Main Android Binder service implementation
|
||||
- Implements `IMosisService.aidl` interface for touch events and initialization
|
||||
- Contains the Kernel rendering engine with RmlUi integration
|
||||
- Links against RmlUi for HTML/CSS-like UI rendering
|
||||
|
||||
**mosis-test** (`libmosis-test.so`):
|
||||
- Test/rendering client implementation
|
||||
- Implements `IMosisListener.aidl` for receiving callbacks
|
||||
- OpenGL ES 2.0 rendering pipeline using GLAD
|
||||
|
||||
### IPC Flow
|
||||
|
||||
```
|
||||
Kotlin NativeService → JNI → mosis-service (IMosisService)
|
||||
↓
|
||||
IMosisListener callbacks
|
||||
↓
|
||||
mosis-test (rendering client)
|
||||
```
|
||||
|
||||
### Key Interfaces (AIDL)
|
||||
|
||||
`IMosisService`: `initOS()`, `onTouchDown()`, `onTouchMove()`, `onTouchUp()`
|
||||
|
||||
`IMosisListener` (oneway/async): `onServiceInitialized()`, `onBufferAvailable()`, `onFrameAvailable()`
|
||||
|
||||
### Native Code Structure (src/main/cpp/)
|
||||
|
||||
- `kernel.cpp` - Core rendering engine, RmlUi integration, event processing
|
||||
- `mosis-service.cpp` - Binder service implementation, JNI entry points
|
||||
- `mosis-test.cpp` - Test client implementation
|
||||
- `egl_context.cpp` - OpenGL ES context management
|
||||
- `render_target.cpp` - Framebuffer and buffer management
|
||||
- `RmlUi_Renderer_GL3.cpp` - RmlUi OpenGL renderer backend
|
||||
- `assets_manager.cpp` - Android AssetManager integration
|
||||
|
||||
## Code Style
|
||||
|
||||
- C++23 standard with modern features (std::span, std::format)
|
||||
- PascalCase for classes/functions, camelCase for variables
|
||||
- RAII principles with smart pointers
|
||||
- Kotlin code follows Android conventions
|
||||
|
||||
## Dependencies
|
||||
|
||||
- vcpkg manages native dependencies (RmlUi)
|
||||
- CMake build system with vcpkg toolchain integration
|
||||
- Target architecture: arm64-v8a only
|
||||
165
PLAN.md
Normal file
165
PLAN.md
Normal file
@@ -0,0 +1,165 @@
|
||||
# MosisService Implementation Plan
|
||||
|
||||
## Overview
|
||||
This document outlines the implementation plan for adding Lua scripting support to the MosisService project, enabling interactive UI elements that can execute Lua code.
|
||||
|
||||
## Project Analysis
|
||||
|
||||
### Current Architecture
|
||||
The project consists of:
|
||||
1. Kotlin-based Android UI components
|
||||
2. Two native C++ libraries (`mosis-service` and `mosis-test`)
|
||||
3. RmlUi-based UI rendering engine
|
||||
4. Android Binder service integration
|
||||
5. OpenGL ES 2.0 rendering pipeline
|
||||
|
||||
### Build System
|
||||
- Android Studio with Gradle
|
||||
- CMake build system
|
||||
- Android NDK (version 29.0.14206865)
|
||||
- vcpkg for dependency management
|
||||
|
||||
## Implementation Steps
|
||||
|
||||
### Phase 1: Enable Lua Support in Build System
|
||||
1. **Update vcpkg.json**
|
||||
- Verify RmlUi package includes Lua support
|
||||
- Add necessary Lua dependency if not included
|
||||
|
||||
2. **Modify CMakeLists.txt**
|
||||
- Add RmlUi Lua binding options
|
||||
- Configure proper linking with Lua libraries
|
||||
- Set compiler flags for maximum feedback
|
||||
|
||||
### Phase 2: Integrate Lua in Core Engine
|
||||
1. **Update kernel.cpp**
|
||||
- Include RmlUi/Lua.h header
|
||||
- Add Lua initialization call after main RmlUi initialization
|
||||
- Register C++ functions accessible from Lua scripts
|
||||
|
||||
2. **Configure Build with Debug Flags**
|
||||
- Enable all compiler warnings
|
||||
- Add debugging symbols
|
||||
- Enable sanitizers for memory and undefined behavior checks
|
||||
|
||||
### Phase 3: UI Integration
|
||||
1. **Modify demo.rml**
|
||||
- Add center button element
|
||||
- Position button using CSS transforms
|
||||
- Implement onclick handler that calls registered Lua function
|
||||
|
||||
2. **Add CSS Styles**
|
||||
- Create centered positioning for UI elements
|
||||
- Style the button appropriately
|
||||
- Ensure proper z-index for overlay elements
|
||||
|
||||
### Phase 4: Script Execution
|
||||
1. **Create Lua Function Registration**
|
||||
- Register C++ functions that interact with Android services
|
||||
- Implement callback mechanisms for UI events
|
||||
- Handle error cases in script execution
|
||||
|
||||
### Phase 5: Testing and Validation
|
||||
1. **Verify Build with Debug Feedback**
|
||||
- Compile with all warnings enabled
|
||||
- Test compilation with sanitizers
|
||||
- Validate debug symbol generation
|
||||
|
||||
2. **Functional Testing**
|
||||
- Test button click functionality
|
||||
- Verify Lua script execution
|
||||
- Validate UI updates from script execution
|
||||
|
||||
## Specific Technical Requirements
|
||||
|
||||
### CMake Configuration Changes
|
||||
In `CMakeLists.txt`:
|
||||
```
|
||||
# Enable Lua bindings for RmlUi
|
||||
# Add after find_package(RmlUi CONFIG REQUIRED)
|
||||
set(RMLUI_LUA_BINDINGS ON)
|
||||
set(RML_LUA_BINDINGS_LIBRARY lua_as_cxx)
|
||||
|
||||
# Link with Lua libraries if needed
|
||||
# target_link_libraries(mosis-service RmlUi::RmlUi RmlUi::Lua)
|
||||
```
|
||||
|
||||
### Kernel Integration
|
||||
In `kernel.cpp`:
|
||||
```cpp
|
||||
#include <RmlUi/Lua.h>
|
||||
|
||||
// In main_loop() after Rml::Initialise():
|
||||
Rml::Lua::Initialise();
|
||||
|
||||
// Register functions that can be called from RML
|
||||
// Example of registering a basic callback
|
||||
Rml::Lua::RegisterGlobalFunction("handleButtonClick", []() {
|
||||
Logger::Log("Button clicked via Lua!");
|
||||
// Add actual implementation
|
||||
});
|
||||
```
|
||||
|
||||
### RML Button Implementation
|
||||
In `demo.rml`:
|
||||
```xml
|
||||
<div id="center-button-container">
|
||||
<button id="trigger-button" onclick="handleButtonClick()">Execute Script</button>
|
||||
</div>
|
||||
```
|
||||
|
||||
### CSS Styling
|
||||
Add to CSS:
|
||||
```css
|
||||
#center-button-container {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
#trigger-button {
|
||||
font-size: 2em;
|
||||
padding: 20px 40px;
|
||||
background-color: #3498db;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
}
|
||||
```
|
||||
|
||||
## Build Commands for Maximum Feedback
|
||||
|
||||
### Debug Build with All Warnings
|
||||
```
|
||||
./gradlew clean && ./gradlew assembleDebug
|
||||
--warning-mode all
|
||||
--info
|
||||
--stacktrace
|
||||
-Pandroid.jetifier.enable=true
|
||||
```
|
||||
|
||||
### Compilation with Sanitizers
|
||||
```
|
||||
cmake -DCMAKE_BUILD_TYPE=Debug
|
||||
-DCMAKE_CXX_FLAGS_DEBUG="-g -O0 -Wall -Wextra -Wpedantic -Werror -fsanitize=address,undefined"
|
||||
.
|
||||
```
|
||||
|
||||
## Expected Outcome
|
||||
After implementation, the UI will:
|
||||
1. Display a center button in the demo interface
|
||||
2. Allow button clicks to trigger Lua scripts
|
||||
3. Execute registered C++ functions through Lua
|
||||
4. Provide full build feedback with debug symbols
|
||||
5. Support all compiler warnings and sanitization
|
||||
|
||||
## Validation Steps
|
||||
1. Successful compilation with no errors or warnings
|
||||
2. UI renders with centered button
|
||||
3. Button click executes Lua script successfully
|
||||
4. Debug symbols present in native libraries
|
||||
5. No memory leaks detected by sanitizers
|
||||
@@ -2,6 +2,7 @@
|
||||
<head>
|
||||
<link type="text/rcss" href="html.rcss"/>
|
||||
<link type="text/rcss" href="phone.rcss"/>
|
||||
<script src="scripts.lua"></script>
|
||||
<title>Fullscreen Mobile UI</title>
|
||||
</head>
|
||||
<body>
|
||||
@@ -15,7 +16,12 @@
|
||||
|
||||
<div id="content">
|
||||
<div class="header-section">
|
||||
<h1>Hello omar 3 hello! and hello LEO 2 Hello!</h1>
|
||||
<h1>Mosis Service</h1>
|
||||
</div>
|
||||
|
||||
<div class="button-section">
|
||||
<button id="action-button" class="primary-button" onclick="onButtonClick()">Click Me!</button>
|
||||
<button id="reset-button" class="secondary-button" onclick="onResetClick()">Reset</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -105,4 +105,55 @@ h1 {
|
||||
|
||||
.nav-item:hover {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
/* Button Section */
|
||||
.button-section {
|
||||
display: block;
|
||||
text-align: center;
|
||||
margin-top: 50px;
|
||||
}
|
||||
|
||||
/* Primary Button Style */
|
||||
.primary-button {
|
||||
font-family: LatoLatin;
|
||||
font-size: 4em;
|
||||
padding: 30px 60px;
|
||||
margin: 20px;
|
||||
background-color: #3498db;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 15px;
|
||||
cursor: pointer;
|
||||
min-width: 300px;
|
||||
}
|
||||
|
||||
.primary-button:hover {
|
||||
background-color: #2980b9;
|
||||
}
|
||||
|
||||
.primary-button:active {
|
||||
background-color: #1c5a85;
|
||||
}
|
||||
|
||||
/* Secondary Button Style */
|
||||
.secondary-button {
|
||||
font-family: LatoLatin;
|
||||
font-size: 3em;
|
||||
padding: 20px 40px;
|
||||
margin: 20px;
|
||||
background-color: #7f8c8d;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 15px;
|
||||
cursor: pointer;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
.secondary-button:hover {
|
||||
background-color: #95a5a6;
|
||||
}
|
||||
|
||||
.secondary-button:active {
|
||||
background-color: #5d6d6e;
|
||||
}
|
||||
36
src/main/assets/scripts.lua
Normal file
36
src/main/assets/scripts.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
-- MosisService Lua Scripts
|
||||
-- Button click handlers and UI logic
|
||||
|
||||
-- Counter to track button clicks
|
||||
click_count = 0
|
||||
|
||||
-- Button click handler
|
||||
function onButtonClick()
|
||||
click_count = click_count + 1
|
||||
print("Button clicked! Count: " .. click_count)
|
||||
|
||||
-- Update the button text to show click count
|
||||
local document = rmlui.contexts["default"].documents[1]
|
||||
if document then
|
||||
local button = document:GetElementById("action-button")
|
||||
if button then
|
||||
button.inner_rml = "Clicked " .. click_count .. " times"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Reset counter function
|
||||
function onResetClick()
|
||||
click_count = 0
|
||||
print("Counter reset!")
|
||||
|
||||
local document = rmlui.contexts["default"].documents[1]
|
||||
if document then
|
||||
local button = document:GetElementById("action-button")
|
||||
if button then
|
||||
button.inner_rml = "Click Me!"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
print("Lua scripts loaded successfully!")
|
||||
@@ -8,7 +8,23 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(BINDER_DIR "${ANDROID_SDK}/platforms/android-36/optional/libbinder_ndk_cpp")
|
||||
set(AIDL_EXE "${ANDROID_SDK}/build-tools/36.1.0/aidl.exe")
|
||||
|
||||
find_package(RmlUi CONFIG REQUIRED)
|
||||
# Find Lua from vcpkg
|
||||
find_package(Lua REQUIRED)
|
||||
|
||||
# Fetch RmlUi from GitHub with Lua bindings enabled
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
rmlui
|
||||
GIT_REPOSITORY https://github.com/mikke89/RmlUi.git
|
||||
GIT_TAG master
|
||||
)
|
||||
set(RMLUI_LUA_BINDINGS ON CACHE BOOL "" FORCE)
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
|
||||
set(RMLUI_SAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(RMLUI_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(RMLUI_FONT_ENGINE "freetype" CACHE STRING "" FORCE)
|
||||
set(RMLUI_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(rmlui)
|
||||
|
||||
#get_cmake_property(_variableNames VARIABLES)
|
||||
#list(SORT _variableNames)
|
||||
@@ -60,7 +76,7 @@ target_include_directories(mosis-service PUBLIC
|
||||
)
|
||||
target_link_libraries(mosis-service
|
||||
android log binder_ndk EGL GLESv2 nativewindow
|
||||
RmlUi::RmlUi
|
||||
rmlui rmlui_lua
|
||||
)
|
||||
|
||||
add_library(mosis-test SHARED
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <android/hardware_buffer.h>
|
||||
#include <android/asset_manager.h>
|
||||
#include <RmlUi/Core.h>
|
||||
#include <RmlUi/Lua.h>
|
||||
#include "RmlUi_Renderer_GL3.h"
|
||||
#include <span>
|
||||
#include <ranges>
|
||||
@@ -119,6 +120,8 @@ void Kernel::main_loop()
|
||||
Rml::SetFileInterface(&AssetFilesInterface::Instance());
|
||||
Rml::SetSystemInterface(&SystemInterface::Instance());
|
||||
Rml::Initialise();
|
||||
Rml::Lua::Initialise();
|
||||
Logger::Log("RmlUi Lua bindings initialized");
|
||||
Rml::Context* context = Rml::CreateContext("default", Rml::Vector2i(540, 960));
|
||||
if (!context)
|
||||
{
|
||||
@@ -195,6 +198,11 @@ void Kernel::add_listener(const std::shared_ptr<IMosisListener> &listener)
|
||||
void Kernel::on_touch_down(float x, float y)
|
||||
{
|
||||
Logger::Log(std::format("on_touch_down {} - {}", x, y));
|
||||
std::lock_guard _lock(m_mutex);
|
||||
m_tasks.emplace_back([x, y](Rml::Context* context){
|
||||
context->ProcessMouseMove(static_cast<int>(x * 540), static_cast<int>(y * 960), 0);
|
||||
context->ProcessMouseButtonDown(0, 0);
|
||||
});
|
||||
}
|
||||
|
||||
void Kernel::on_touch_move(float x, float y)
|
||||
@@ -202,13 +210,18 @@ void Kernel::on_touch_move(float x, float y)
|
||||
Logger::Log(std::format("on_touch_move {} - {}", x, y));
|
||||
std::lock_guard _lock(m_mutex);
|
||||
m_tasks.emplace_back([x, y](Rml::Context* context){
|
||||
context->ProcessMouseMove(x * 540, y * 960, 0);
|
||||
context->ProcessMouseMove(static_cast<int>(x * 540), static_cast<int>(y * 960), 0);
|
||||
});
|
||||
}
|
||||
|
||||
void Kernel::on_touch_up(float x, float y)
|
||||
{
|
||||
Logger::Log(std::format("on_touch_up {} - {}", x, y));
|
||||
std::lock_guard _lock(m_mutex);
|
||||
m_tasks.emplace_back([x, y](Rml::Context* context){
|
||||
context->ProcessMouseMove(static_cast<int>(x * 540), static_cast<int>(y * 960), 0);
|
||||
context->ProcessMouseButtonUp(0, 0);
|
||||
});
|
||||
}
|
||||
|
||||
Kernel::~Kernel() = default;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"name": "mosis-os",
|
||||
"version-string": "0.1.0",
|
||||
"dependencies": [
|
||||
"rmlui"
|
||||
"lua",
|
||||
"freetype"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user