better lighting

This commit is contained in:
asrael 2026-01-31 09:31:17 -06:00
parent 805a2713a3
commit 6ed4e17065
75 changed files with 6417 additions and 3667 deletions

View file

@ -106,6 +106,63 @@ bool pxl8_gui_button(pxl8_gui_state* state, pxl8_gfx* gfx, u32 id, i32 x, i32 y,
return clicked;
}
bool pxl8_gui_slider(pxl8_gui_state* state, pxl8_gfx* gfx, u32 id, i32 x, i32 y, i32 w, i32 h, f32* value, f32 min_val, f32 max_val) {
if (!state || !gfx || !value) return false;
bool cursor_over = is_cursor_over(state, x, y, w, h);
bool is_active = (state->active_id == id);
bool changed = false;
if (cursor_over) {
state->hot_id = id;
}
if (cursor_over && state->cursor_down && state->active_id == 0) {
state->active_id = id;
}
if (is_active && state->cursor_down) {
f32 t = (f32)(state->cursor_x - x) / (f32)w;
if (t < 0.0f) t = 0.0f;
if (t > 1.0f) t = 1.0f;
f32 new_val = min_val + t * (max_val - min_val);
if (new_val != *value) {
*value = new_val;
changed = true;
}
}
u8 bg_color = pxl8_gfx_ui_color(gfx, PXL8_UI_BG1);
u8 fill_color = pxl8_gfx_ui_color(gfx, is_active ? PXL8_UI_FG0 : PXL8_UI_BG3);
u8 handle_color = pxl8_gfx_ui_color(gfx, PXL8_UI_FG1);
pxl8_2d_rect_fill(gfx, x, y, w, h, bg_color);
f32 t = (*value - min_val) / (max_val - min_val);
i32 fill_w = (i32)(t * (f32)w);
if (fill_w > 0) {
pxl8_2d_rect_fill(gfx, x, y, fill_w, h, fill_color);
}
i32 handle_x = x + fill_w - 2;
if (handle_x < x) handle_x = x;
if (handle_x > x + w - 4) handle_x = x + w - 4;
pxl8_2d_rect_fill(gfx, handle_x, y, 4, h, handle_color);
return changed;
}
bool pxl8_gui_slider_int(pxl8_gui_state* state, pxl8_gfx* gfx, u32 id, i32 x, i32 y, i32 w, i32 h, i32* value, i32 min_val, i32 max_val) {
if (!state || !gfx || !value) return false;
f32 fval = (f32)*value;
bool changed = pxl8_gui_slider(state, gfx, id, x, y, w, h, &fval, (f32)min_val, (f32)max_val);
if (changed) {
*value = (i32)(fval + 0.5f);
}
return changed;
}
void pxl8_gui_window(pxl8_gfx* gfx, i32 x, i32 y, i32 w, i32 h, const char* title) {
if (!gfx || !title) return;