implement our own gui module, drop microui
This commit is contained in:
parent
2555bec8eb
commit
8baf5f06ea
25 changed files with 495 additions and 507 deletions
|
|
@ -13,13 +13,12 @@
|
|||
#include <lualib.h>
|
||||
|
||||
#include "pxl8_macros.h"
|
||||
#include "pxl8_ui.h"
|
||||
#include "pxl8_gui.h"
|
||||
|
||||
struct pxl8_script {
|
||||
lua_State* L;
|
||||
pxl8_gfx* gfx;
|
||||
pxl8_input_state* input;
|
||||
pxl8_ui* ui;
|
||||
char last_error[2048];
|
||||
char main_path[256];
|
||||
char watch_dir[256];
|
||||
|
|
@ -109,13 +108,19 @@ static const char* pxl8_ffi_cdefs =
|
|||
"bool pxl8_key_down(const pxl8_input_state* input, const char* key_name);\n"
|
||||
"bool pxl8_key_pressed(const pxl8_input_state* input, const char* key_name);\n"
|
||||
"bool pxl8_key_released(const pxl8_input_state* input, const char* key_name);\n"
|
||||
"bool pxl8_mouse_pressed(const pxl8_input_state* input, i32 button);\n"
|
||||
"bool pxl8_mouse_released(const pxl8_input_state* input, i32 button);\n"
|
||||
"int pxl8_mouse_wheel_x(const pxl8_input_state* input);\n"
|
||||
"int pxl8_mouse_wheel_y(const pxl8_input_state* input);\n"
|
||||
"int pxl8_mouse_x(const pxl8_input_state* input);\n"
|
||||
"int pxl8_mouse_y(const pxl8_input_state* input);\n"
|
||||
"int pxl8_mouse_dx(const pxl8_input_state* input);\n"
|
||||
"int pxl8_mouse_dy(const pxl8_input_state* input);\n"
|
||||
"typedef enum { PXL8_CURSOR_ARROW = 0, PXL8_CURSOR_HAND = 1 } pxl8_cursor;\n"
|
||||
"void pxl8_center_cursor(pxl8* sys);\n"
|
||||
"void pxl8_set_cursor(pxl8* sys, pxl8_cursor cursor);\n"
|
||||
"void pxl8_set_relative_mouse_mode(pxl8* sys, bool enabled);\n"
|
||||
"void pxl8_set_running(pxl8* sys, bool running);\n"
|
||||
"void pxl8_lua_debug(const char* msg);\n"
|
||||
"void pxl8_lua_error(const char* msg);\n"
|
||||
"void pxl8_lua_info(const char* msg);\n"
|
||||
|
|
@ -303,32 +308,19 @@ static const char* pxl8_ffi_cdefs =
|
|||
"void pxl8_world_render(pxl8_world* world, pxl8_gfx* gfx, pxl8_vec3 camera_pos);\n"
|
||||
"void pxl8_world_unload(pxl8_world* world);\n"
|
||||
"\n"
|
||||
"typedef struct pxl8_ui pxl8_ui;\n"
|
||||
"typedef struct { unsigned char bg_color; unsigned int sprite_id; int corner_size; int edge_size; int padding; } pxl8_frame_theme;\n"
|
||||
"typedef struct { bool enabled; const char* label; } pxl8_menu_item;\n"
|
||||
"pxl8_ui* pxl8_ui_create(pxl8_gfx* gfx);\n"
|
||||
"void pxl8_ui_destroy(pxl8_ui* ui);\n"
|
||||
"void pxl8_ui_frame_begin(pxl8_ui* ui);\n"
|
||||
"void pxl8_ui_frame_end(pxl8_ui* ui);\n"
|
||||
"void pxl8_ui_input_keydown(pxl8_ui* ui, int key);\n"
|
||||
"void pxl8_ui_input_keyup(pxl8_ui* ui, int key);\n"
|
||||
"void pxl8_ui_input_mousedown(pxl8_ui* ui, int x, int y, int button);\n"
|
||||
"void pxl8_ui_input_mousemove(pxl8_ui* ui, int x, int y);\n"
|
||||
"void pxl8_ui_input_mouseup(pxl8_ui* ui, int x, int y, int button);\n"
|
||||
"void pxl8_ui_input_scroll(pxl8_ui* ui, int x, int y);\n"
|
||||
"void pxl8_ui_input_text(pxl8_ui* ui, const char* text);\n"
|
||||
"bool pxl8_ui_button(pxl8_ui* ui, const char* label);\n"
|
||||
"bool pxl8_ui_checkbox(pxl8_ui* ui, const char* label, bool* state);\n"
|
||||
"bool pxl8_ui_has_mouse_focus(pxl8_ui* ui);\n"
|
||||
"void pxl8_ui_indent(pxl8_ui* ui, int amount);\n"
|
||||
"void pxl8_ui_label(pxl8_ui* ui, const char* text);\n"
|
||||
"void pxl8_ui_layout_row(pxl8_ui* ui, int item_count, const int* widths, int height);\n"
|
||||
"int pxl8_ui_menu(pxl8_ui* ui, pxl8_menu_item* items, int item_count);\n"
|
||||
"void pxl8_ui_panel(pxl8_ui* ui, pxl8_bounds rect, pxl8_frame_theme* theme);\n"
|
||||
"bool pxl8_ui_window_begin(pxl8_ui* ui, const char* title, pxl8_bounds rect, int options);\n"
|
||||
"void pxl8_ui_window_end(pxl8_ui* ui);\n"
|
||||
"void pxl8_ui_window_set_open(pxl8_ui* ui, const char* title, bool open);\n"
|
||||
"pxl8_frame_theme pxl8_ui_theme_default(void);\n";
|
||||
"typedef struct { i32 cursor_x; i32 cursor_y; bool cursor_down; bool cursor_clicked; u32 hot_id; u32 active_id; } pxl8_gui_state;\n"
|
||||
"pxl8_gui_state* pxl8_gui_state_create(void);\n"
|
||||
"void pxl8_gui_state_destroy(pxl8_gui_state* state);\n"
|
||||
"void pxl8_gui_begin_frame(pxl8_gui_state* state);\n"
|
||||
"void pxl8_gui_end_frame(pxl8_gui_state* state);\n"
|
||||
"void pxl8_gui_cursor_move(pxl8_gui_state* state, i32 x, i32 y);\n"
|
||||
"void pxl8_gui_cursor_down(pxl8_gui_state* state);\n"
|
||||
"void pxl8_gui_cursor_up(pxl8_gui_state* state);\n"
|
||||
"bool pxl8_gui_button(pxl8_gui_state* state, pxl8_gfx* gfx, u32 id, i32 x, i32 y, i32 w, i32 h, const char* label);\n"
|
||||
"void pxl8_gui_window(pxl8_gfx* gfx, i32 x, i32 y, i32 w, i32 h, const char* title);\n"
|
||||
"void pxl8_gui_label(pxl8_gfx* gfx, i32 x, i32 y, const char* text, u8 color);\n"
|
||||
"bool pxl8_gui_is_hovering(const pxl8_gui_state* state);\n"
|
||||
"void pxl8_gui_get_cursor_pos(const pxl8_gui_state* state, i32* x, i32* y);\n";
|
||||
|
||||
void pxl8_lua_info(const char* msg) {
|
||||
pxl8_info("%s", msg);
|
||||
|
|
@ -444,14 +436,6 @@ void pxl8_script_set_input(pxl8_script* script, pxl8_input_state* input) {
|
|||
}
|
||||
}
|
||||
|
||||
void pxl8_script_set_ui(pxl8_script* script, pxl8_ui* ui) {
|
||||
if (!script) return;
|
||||
script->ui = ui;
|
||||
if (script->L && ui) {
|
||||
lua_pushlightuserdata(script->L, ui);
|
||||
lua_setglobal(script->L, "_pxl8_ui");
|
||||
}
|
||||
}
|
||||
|
||||
void pxl8_script_set_sys(pxl8_script* script, void* sys) {
|
||||
if (!script) return;
|
||||
|
|
@ -719,16 +703,27 @@ static time_t get_latest_script_mod_time(const char* dir_path) {
|
|||
while ((entry = readdir(dir)) != NULL) {
|
||||
if (entry->d_name[0] == '.') continue;
|
||||
|
||||
size_t len = strlen(entry->d_name);
|
||||
bool is_script = (len > 4 && strcmp(entry->d_name + len - 4, ".fnl") == 0) ||
|
||||
(len > 4 && strcmp(entry->d_name + len - 4, ".lua") == 0);
|
||||
char full_path[512];
|
||||
snprintf(full_path, sizeof(full_path), "%s/%s", dir_path, entry->d_name);
|
||||
|
||||
if (is_script) {
|
||||
char full_path[512];
|
||||
snprintf(full_path, sizeof(full_path), "%s/%s", dir_path, entry->d_name);
|
||||
time_t mod_time = get_file_mod_time(full_path);
|
||||
if (mod_time > latest) {
|
||||
latest = mod_time;
|
||||
struct stat st;
|
||||
if (stat(full_path, &st) == 0) {
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
time_t subdir_time = get_latest_script_mod_time(full_path);
|
||||
if (subdir_time > latest) {
|
||||
latest = subdir_time;
|
||||
}
|
||||
} else {
|
||||
size_t len = strlen(entry->d_name);
|
||||
bool is_script = (len > 4 && strcmp(entry->d_name + len - 4, ".fnl") == 0) ||
|
||||
(len > 4 && strcmp(entry->d_name + len - 4, ".lua") == 0);
|
||||
|
||||
if (is_script) {
|
||||
time_t mod_time = get_file_mod_time(full_path);
|
||||
if (mod_time > latest) {
|
||||
latest = mod_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue