diff --git a/build_file.c b/build_file.c index 4ea8a5c..f341d0b 100644 --- a/build_file.c +++ b/build_file.c @@ -38,8 +38,8 @@ int main(int argc, char **argv) { mt_testing(tcx->temp); b32 run_server = false; - b32 core_test_target = true; - b32 win32_target = false; + b32 core_test_target = false; + b32 win32_target = true; b32 standalone_w32_target = false; b32 wasm_target = false; diff --git a/src/app/app_win32.c b/src/app/app_win32.c index f484848..89743c6 100644 --- a/src/app/app_win32.c +++ b/src/app/app_win32.c @@ -1,4 +1,6 @@ +#include "os/os.h" #include "app_win32_opengl.c" +#include "os/os.c" #pragma comment(linker, "/subsystem:windows") #pragma comment(lib, "gdi32.lib") @@ -288,7 +290,7 @@ fn void w32_set_event(app_frame_t *frame, app_event_t ev) { } fn void w32_try_reloading_library(w32_library_t *lib, app_frame_t frame) { - i64 new_write_time = os_get_file_mod_time(lib->dll_name); + i64 new_write_time = os_mod_time(lib->dll_name); if (new_write_time == -1 || new_write_time == lib->last_write_time) { goto end_of_lib_load; } @@ -347,7 +349,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n { ma_temp_t scratch = ma_begin_scratch(); s8_t dir = os_exe_dir(scratch.arena); - for (os_file_iter_t *it = os_iterate_files(scratch.arena, dir); it->is_valid; os_advance(it)) { + for (os_iter_t *it = os_iter(scratch.arena, dir); it->is_valid; os_advance(it)) { b32 is_dll = s8_ends_with(it->name, s8_lit(".dll"), false); b32 is_pdb = s8_ends_with(it->name, s8_lit(".pdb"), false); b32 is_rdi = s8_ends_with(it->name, s8_lit(".rdi"), false); diff --git a/src/os/os.c b/src/os/os.c index 545a1d1..a4d622f 100644 --- a/src/os/os.c +++ b/src/os/os.c @@ -6,26 +6,7 @@ #include "os_unix.c" #endif - -fn_test void os_test(void) { - os_date_t local_time = os_local_time(); - os_date_t universal_time = os_universal_time(); - debugf("local_time = %S | universal_time = %S", os_format_date(tcx->temp, local_time), os_format_date(tcx->temp, universal_time)); - - s8_t exe_dir = os_exe_dir(tcx->temp); - assert(exe_dir.str[exe_dir.len - 1] == '/'); - s8_t exe = os_exe(tcx->temp); - s8_t cwd = os_cwd(tcx->temp); - assert(exe_dir.str[cwd.len - 1] == '/'); - assert(os_is_dir(exe_dir)); - assert(os_is_file(exe)); - assert(os_is_dir(cwd)); - assert(os_exists(exe_dir)); - assert(os_exists(exe)); - assert(os_exists(cwd)); - assert(os_is_abs(exe_dir)); - assert(os_is_abs(exe)); - assert(os_is_abs(cwd)); - assert(!os_is_abs(s8_lit("../path/"))); - debugf("%S %S %S", exe_dir, exe, cwd); +fn s8_t os_format_date(ma_arena_t *arena, os_date_t date) { + s8_t result = s8_printf(arena, "%04u-%02u-%02u %02u:%02u:%02u.%03u", date.year, date.month, date.day, date.hour, date.min, date.sec, date.ms); + return result; } diff --git a/src/os/os_win32.c b/src/os/os_win32.c index 361b110..974ff1d 100644 --- a/src/os/os_win32.c +++ b/src/os/os_win32.c @@ -28,11 +28,6 @@ fn os_date_t os_universal_time(void) { return result; } -fn s8_t os_format_date(ma_arena_t *arena, os_date_t date) { - s8_t result = s8_printf(arena, "%04u-%02u-%02u %02u:%02u:%02u.%03u", date.year, date.month, date.day, date.hour, date.min, date.sec, date.ms); - return result; -} - fn f64 os_seconds(void) { static int64_t counts_per_second; if (counts_per_second == 0) { @@ -303,7 +298,7 @@ fn os_thread_t os_thread_create(ma_arena_t *arena, os_thread_fn_t *func, void *u return result; } -fn i32 os_join(os_thread_t *thread) { +fn i32 os_thread_join(os_thread_t *thread) { DWORD return_value_indicates_event = WaitForSingleObject(thread->w32->handle, INFINITE); if (return_value_indicates_event != WAIT_OBJECT_0) { debugf(__FUNCTION__".WaitForSingleObject failed: %d", GetLastError()); @@ -337,7 +332,7 @@ fn i32 os_join(os_thread_t *thread) { // threads[i] = os_thread_create(scratch.arena, os__thread_log, NULL); // } // for (int i = 0; i < lengthof(threads); i += 1) { -// os_join(&threads[i]); +// os_thread_join(&threads[i]); // } // ma_end_scratch(scratch); // } \ No newline at end of file diff --git a/src/testing/testing.gen.c b/src/testing/testing.gen.c index 7aac4d5..3794dc6 100644 --- a/src/testing/testing.gen.c +++ b/src/testing/testing.gen.c @@ -2,5 +2,4 @@ fn void run_tests(void) { test_s8(); test_hash_table(); test_intern_table(); - os_test(); } diff --git a/src/testing/testing_main.c b/src/testing/testing_main.c index 63a2d02..211faf2 100644 --- a/src/testing/testing_main.c +++ b/src/testing/testing_main.c @@ -5,8 +5,32 @@ #include "testing.gen.c" +fn void os_test(void) { + os_date_t local_time = os_local_time(); + os_date_t universal_time = os_universal_time(); + debugf("local_time = %S | universal_time = %S", os_format_date(tcx->temp, local_time), os_format_date(tcx->temp, universal_time)); + + s8_t exe_dir = os_exe_dir(tcx->temp); + assert(exe_dir.str[exe_dir.len - 1] == '/'); + s8_t exe = os_exe(tcx->temp); + s8_t cwd = os_cwd(tcx->temp); + assert(exe_dir.str[cwd.len - 1] == '/'); + assert(os_is_dir(exe_dir)); + assert(os_is_file(exe)); + assert(os_is_dir(cwd)); + assert(os_exists(exe_dir)); + assert(os_exists(exe)); + assert(os_exists(cwd)); + assert(os_is_abs(exe_dir)); + assert(os_is_abs(exe)); + assert(os_is_abs(cwd)); + assert(!os_is_abs(s8_lit("../path/"))); + debugf("%S %S %S", exe_dir, exe, cwd); +} + int main() { core_init(); run_tests(); + os_test(); return 0; } \ No newline at end of file diff --git a/src/ui/ui.c b/src/ui/ui.c index 85f27a1..2f48973 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -387,17 +387,21 @@ struct ui_draw_compute_t { v4f32_t text_color; }; +fn r2f32_t ui_get_appear_rect(ui_box_t *box) { + r2f32_t result = box->rect; + f32 appear_t = f32_ease_out_n(f32_clamp01(box->appear_t * 2), 10); + if (!ui_id_is_null(box->id)) { + v2f32_t size = v2f32_muls(r2f32_get_size(result), 0.15f); + r2f32_t smaller_rect = r2f32_shrink(result, size); + result = r2f32_lerp(smaller_rect, result, appear_t); + } + return result; +} + fn ui_draw_compute_t ui_draw_compute(ui_box_t *box) { ui_draw_compute_t co = {0}; - co.rect = box->rect; - f32 appear_t = f32_ease_out_n(f32_clamp01(box->appear_t * 2), 10); - if (!ui_id_is_null(box->id)) { - v2f32_t size = v2f32_muls(r2f32_get_size(co.rect), 0.15f); - r2f32_t smaller_rect = r2f32_shrink(co.rect, size); - co.rect = r2f32_lerp(smaller_rect, co.rect, appear_t); - } - + co.rect = ui_get_appear_rect(box); co.background_color = box->background_color; co.text_color = box->text_color; co.border_color = box->border_color; @@ -964,6 +968,7 @@ struct ui_scroller_params_t { b8 enabled; f32 *value; f32 max_size; + ui_code_loc_t loc; } hori; struct { b8 enabled; @@ -973,6 +978,7 @@ struct ui_scroller_params_t { i32 item_count; // @option2: non efficient f32 max_size; + ui_code_loc_t loc; } verti; }; @@ -990,11 +996,11 @@ struct ui_scroller_t { ui_scroller_params_t p; }; -fn ui_scroller_t ui_begin_scroller(ui_scroller_params_t p) { +fn ui_scroller_t ui_begin_scroller(ui_code_loc_t loc, ui_scroller_params_t p) { ui_scroller_t r = {.p = p}; if (p.verti.enabled) { - r.verti.box = ui_box(.rect = r2f32_cut_right(&p.parent->rect, ui_dm(0.5f)), .flags = {.draw_rect = true}); + r.verti.box = ui_box(.loc = loc, .rect = r2f32_cut_right(&p.parent->rect, ui_dm(0.5f)), .flags = {.draw_rect = true}); r2f32_cut_bottom(&r.verti.box->rect, ui_dm(0.5f)); r.verti.item_box_pixels = r2f32_get_size(p.parent->rect).y; @@ -1011,7 +1017,8 @@ fn ui_scroller_t ui_begin_scroller(ui_scroller_params_t p) { } if (p.hori.enabled) { - r.hori.box = ui_box(.rect = r2f32_cut_bottom(&p.parent->rect, ui_dm(0.5f)), .flags = {.draw_rect = true}); + loc.counter += 10000; + r.hori.box = ui_box(.loc = loc, .rect = r2f32_cut_bottom(&p.parent->rect, ui_dm(0.5f)), .flags = {.draw_rect = true}); } return r; @@ -1157,7 +1164,8 @@ fn void ui__draw_box(app_frame_t *frame, ui_box_t *box) { r2f32_t prev_clip_rect = ui->clip_rect; if (box->flags.clip_rect) { - ui->clip_rect = r2f32_intersect(ui->clip_rect, box->rect); + r2f32_t rect = ui_get_appear_rect(box); + ui->clip_rect = r2f32_intersect(ui->clip_rect, rect); rn_set_clip(ui->clip_rect); } for (ui_box_t *it = box->first; it; it = it->next) { @@ -1184,7 +1192,11 @@ fn void ui_begin_frame(app_frame_t *frame) { fn void ui_end_frame(void) { for (ui_box_t *box = ui->hash_first, *next = NULL; box; box = next) { next = box->hash_next; - box->appear_t += (f32)ui->frame->delta; + // if (box->flags.animate_appear) { + box->appear_t += (f32)ui->frame->delta; + // } else { + // box->appear_t = 1; + // } if (ui_is_hot_box(box)) { box->hot_t += (f32)ui->frame->delta; } else { @@ -1249,7 +1261,7 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co ui_box_t *item_box = ui_box(r2f32_cut_left(ui_top_rectp(), ui_max), {.draw_rect = true, .clip_rect = true}); static f32 verti_scroller_value; - ui_scroller_t scroller = ui_begin_scroller((ui_scroller_params_t){ + ui_scroller_t scroller = ui_begin_scroller(UILOC, (ui_scroller_params_t){ .parent = item_box, .verti = { .enabled = true, @@ -1437,7 +1449,7 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co locl f32 right_scroller_value; locl f32 bottom_scroller_value; - ui_scroller_t scroller = ui_begin_scroller((ui_scroller_params_t){ + ui_scroller_t scroller = ui_begin_scroller(UILOC, (ui_scroller_params_t){ .parent = item_box, .verti = { .enabled = true, @@ -1521,32 +1533,6 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co s8_lit("show data tab"), s8_lit("show log tab"), s8_lit("show menus tab"), - s8_lit("x"), - s8_lit("x1"), - s8_lit("x2"), - s8_lit("x3"), - s8_lit("x4"), - s8_lit("x5"), - s8_lit("x6"), - s8_lit("x7"), - s8_lit("x8"), - s8_lit("x9"), - s8_lit("x0"), - s8_lit("x22"), - s8_lit("x33"), - s8_lit("x44"), - s8_lit("x55"), - s8_lit("x66"), - s8_lit("x77"), - s8_lit("x88"), - s8_lit("x99"), - s8_lit("x123"), - s8_lit("x12"), - s8_lit("x32"), - s8_lit("x42"), - s8_lit("x52"), - s8_lit("x64"), - s8_lit("x75"), }; if (lister_open) { @@ -1556,10 +1542,10 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co v2f32_t pos = v2f32_divs(v2f32_sub(frame->window_size, lister_size), 2.0); pos.y *= 0.05f; r2f32_t rect = r2f32_min_dim(pos, lister_size); - ui_box_t *lister = ui_box(.id = lister_id, .rect = rect, .flags = {.draw_rect = true, .draw_border = true, .clip_rect = true}); + ui_box_t *lister = ui_box(.id = lister_id, .rect = rect, .flags = {.animate_appear = true, .draw_rect = true, .draw_border = true, .clip_rect = true}); locl f32 verti_scroller_value; - ui_scroller_t scroller = ui_begin_scroller((ui_scroller_params_t){ + ui_scroller_t scroller = ui_begin_scroller(UILOC, (ui_scroller_params_t){ .parent = lister, .verti = { .enabled = true, diff --git a/src/ui/ui.h b/src/ui/ui.h index 766a97b..2550818 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -17,6 +17,8 @@ struct ui_box_flags_t { b8 draw_text: 1; b8 clip_rect: 1; + b8 animate_appear: 1; + b8 children_sum_x: 1; b8 children_sum_y: 1; b8 keyboard_nav: 1; diff --git a/todo.txt b/todo.txt index c9f0d02..112d61f 100644 --- a/todo.txt +++ b/todo.txt @@ -12,7 +12,7 @@ [ ] os [x] delete all pdbs\dlls on start [?] wasm (explore) - [ ] win32 + [x] win32 [ ] linux [ ] render