66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
#include <SDL2/SDL.h>
|
|
#include <emscripten.h>
|
|
#include <emscripten/bind.h>
|
|
#include <iostream>
|
|
#include <lvgl/lvgl.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
using namespace emscripten;
|
|
|
|
void setCanvasSize(int width, int height) {
|
|
std::cout << "canvas size: " << width << "*" << height << std::endl;
|
|
}
|
|
|
|
EMSCRIPTEN_BINDINGS(lvglapp) {
|
|
function("setCanvasSize", &setCanvasSize);
|
|
}
|
|
|
|
int monitor_hor_res, monitor_ver_res;
|
|
static void hal_init(void);
|
|
|
|
extern "C" {
|
|
void lv_demo_widgets(void);
|
|
void do_loop();
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
monitor_hor_res = atoi(argv[1]);
|
|
monitor_ver_res = atoi(argv[2]);
|
|
printf("Starting with screen resolution of %dx%d px\n", monitor_hor_res, monitor_ver_res);
|
|
|
|
lv_init();
|
|
hal_init();
|
|
|
|
lv_demo_widgets();
|
|
|
|
emscripten_set_main_loop(do_loop, -1, true);
|
|
return 0;
|
|
}
|
|
|
|
void do_loop() {
|
|
/* Periodically call the lv_task handler.
|
|
* It could be done in a timer interrupt or an OS task too.*/
|
|
lv_task_handler();
|
|
}
|
|
|
|
static void hal_init(void) {
|
|
lv_display_t *disp = lv_sdl_window_create(monitor_hor_res, monitor_ver_res);
|
|
lv_sdl_window_set_resizeable(disp, true);
|
|
lv_group_t *g = lv_group_create();
|
|
lv_group_set_default(g);
|
|
|
|
lv_sdl_mouse_create();
|
|
lv_sdl_mousewheel_create();
|
|
lv_sdl_keyboard_create();
|
|
|
|
lv_indev_t *mouse = lv_sdl_mouse_create();
|
|
lv_indev_set_group(mouse, lv_group_get_default());
|
|
|
|
lv_indev_t *mousewheel = lv_sdl_mousewheel_create();
|
|
lv_indev_set_group(mousewheel, lv_group_get_default());
|
|
|
|
lv_indev_t *keyboard = lv_sdl_keyboard_create();
|
|
lv_indev_set_group(keyboard, lv_group_get_default());
|
|
}
|