UI: Mouse coordinate improvements | Meta-program: Enum deserialization support | Transform: Added set_scale convenience procedure

This commit is contained in:
2024-11-19 22:51:04 +01:00
parent 2327b78015
commit 14892d792a
4 changed files with 38 additions and 28 deletions

View File

@@ -152,6 +152,10 @@ set_scale :: (e: *Entity, scale: Vector3, calculate_matrix: bool = true) {
set_scale(*e.transform, scale, calculate_matrix); set_scale(*e.transform, scale, calculate_matrix);
} }
set_scale :: (e: *Entity, scale: float, calculate_matrix: bool = true) {
set_scale(*e.transform, scale, calculate_matrix);
}
set_scale :: (transform: *Transform, scale: Vector3, calculate_matrix: bool = true) { set_scale :: (transform: *Transform, scale: Vector3, calculate_matrix: bool = true) {
transform.scale = scale; transform.scale = scale;
if calculate_matrix update_matrix(transform); if calculate_matrix update_matrix(transform);

View File

@@ -123,6 +123,7 @@ generate_member_deserialization :: (type: *Type_Info_Struct, builder: *String_Bu
} }
case .BOOL; #through; case .BOOL; #through;
case .FLOAT; #through; case .FLOAT; #through;
case .ENUM; #through;
case .INTEGER; { case .INTEGER; {
print_to_builder(builder, "\t\t\t\tcase \"%\";\n", new_path); print_to_builder(builder, "\t\t\t\tcase \"%\";\n", new_path);
print_to_builder(builder, "\t\t\t\t\tscan2(values[1], \"\%\", *e.%);\n", new_path); print_to_builder(builder, "\t\t\t\t\tscan2(values[1], \"\%\", *e.%);\n", new_path);

View File

@@ -9,6 +9,8 @@ UI_Box_Flags :: enum_flags u32 {
CLIP :: 16; CLIP :: 16;
ANIMATE_ON_HOVER :: 32; ANIMATE_ON_HOVER :: 32;
PLAY_MODE_FOCUSABLE :: 64;
} }
Rect :: struct { Rect :: struct {
@@ -926,44 +928,47 @@ is_mouse_inside :: (x: float, y: float, rect: Rect) -> bool {
} }
ui_update_input :: () { ui_update_input :: () {
if engine.mode == .PLAYING return; // @Robustness //if engine.mode == .PLAYING return; // @Robustness
mouse_x := engine.input.mouse.x; mouse_x := engine.input.mouse.x;
mouse_y := engine.input.mouse.y; mouse_y := engine.input.mouse.y;
for *box: ui_state.boxes { for *box: ui_state.boxes {
if box.flags & .CLICKABLE { if engine.mode == .EDITING || box.flags & .PLAY_MODE_FOCUSABLE {
local_mouse: Vector2; if box.flags & .CLICKABLE {
local_mouse.x = clamp(mouse_x - box.rect.x, 0.0, box.rect.w); local_mouse: Vector2;
local_mouse.y = clamp(mouse_y - box.rect.y, 0.0, box.rect.h); local_mouse.x = clamp(mouse_x - box.rect.x, 0.0, box.rect.w);
box.interaction.local_mouse_coordinates = local_mouse; local_mouse.y = clamp(mouse_y - box.rect.y, 0.0, box.rect.h);
box.interaction.normalized_local_mouse_coordinates.x = local_mouse.x / box.rect.w; box.interaction.local_mouse_coordinates = local_mouse;
box.interaction.normalized_local_mouse_coordinates.y = local_mouse.y / box.rect.h; box.interaction.normalized_local_mouse_coordinates.x = local_mouse.x / box.rect.w;
if box.interaction.clicked { box.interaction.normalized_local_mouse_coordinates.y = local_mouse.y / box.rect.h;
box.interaction.clicked = false;
}
if box.interaction.left_mouse_pressed { if box.interaction.clicked {
box.interaction.left_mouse_down = false; box.interaction.clicked = false;
if !key_pressed(.MOUSE_LEFT) {
box.interaction.clicked = true;
box.interaction.left_mouse_pressed = false;
} }
} else {
if is_mouse_inside(mouse_x, mouse_y, box.rect) && key_pressed(.MOUSE_LEFT) { if box.interaction.left_mouse_pressed {
box.interaction.left_mouse_pressed = true; box.interaction.left_mouse_down = false;
box.interaction.left_mouse_down = true; if !key_pressed(.MOUSE_LEFT) {
box.interaction.clicked = true;
box.interaction.left_mouse_pressed = false;
}
} else {
if is_mouse_inside(mouse_x, mouse_y, box.rect) && key_pressed(.MOUSE_LEFT) {
box.interaction.left_mouse_pressed = true;
box.interaction.left_mouse_down = true;
}
} }
} }
}
if box.flags & .ANIMATE_ON_HOVER { if box.flags & .ANIMATE_ON_HOVER {
if is_mouse_inside(mouse_x, mouse_y, box.rect) { if is_mouse_inside(mouse_x, mouse_y, box.rect) {
box.hover_animation_t += dt * 10; box.hover_animation_t += dt * 10;
} else { } else {
box.hover_animation_t -= dt * 10; box.hover_animation_t -= dt * 10;
}
box.hover_animation_t = clamp(box.hover_animation_t, 0.0, 1.0);
} }
box.hover_animation_t = clamp(box.hover_animation_t, 0.0, 1.0);
} }
} }
} }

View File

@@ -368,7 +368,7 @@ ui_texture :: (texture: Texture_Handle, identifier: s64 = 0, loc := #caller_loca
ui_interactable_texture :: (texture: Texture_Handle, identifier: s64 = 0, loc := #caller_location) -> Interaction_State { ui_interactable_texture :: (texture: Texture_Handle, identifier: s64 = 0, loc := #caller_location) -> Interaction_State {
ui_set_next_texture(texture); ui_set_next_texture(texture);
ui_set_next_background_color(.{0.1,0.1,0.1,1}); ui_set_next_background_color(.{0.1,0.1,0.1,1});
box := ui_box_make(.DRAW_BACKGROUND | .CLICKABLE, get_hash(loc, identifier)); box := ui_box_make(.DRAW_BACKGROUND | .CLICKABLE | .PLAY_MODE_FOCUSABLE, get_hash(loc, identifier));
return box.interaction; return box.interaction;
} }