Input: Added viewport local mouse position | Transform: Added default parameter values for create_transform procedure

This commit is contained in:
2024-10-28 23:32:17 +01:00
parent a3e5cf7e4a
commit f9bcc3538e
4 changed files with 19 additions and 4 deletions

View File

@@ -38,6 +38,7 @@ Interaction_State :: struct {
editing: bool;
local_mouse_coordinates: Vector2; // Coordinates inside the rect in the range [0,1]
normalized_local_mouse_coordinates: Vector2; // Coordinates inside the rect in the range [0,1]
}
@@ -928,9 +929,12 @@ ui_update_input :: () {
for *box: ui_state.boxes {
if box.flags & .CLICKABLE {
normalized_local_mouse_coordinates: Vector2; // Coordinates inside the rect in the range [0,1]
box.interaction.normalized_local_mouse_coordinates.x = clamp(mouse_x - box.rect.x, 0.0, box.rect.w) / box.rect.w;
box.interaction.normalized_local_mouse_coordinates.y = clamp(mouse_y - box.rect.y, 0.0, box.rect.h) / box.rect.h;
local_mouse: Vector2;
local_mouse.x = clamp(mouse_x - box.rect.x, 0.0, box.rect.w);
local_mouse.y = clamp(mouse_y - box.rect.y, 0.0, box.rect.h);
box.interaction.local_mouse_coordinates = local_mouse;
box.interaction.normalized_local_mouse_coordinates.x = local_mouse.x / box.rect.w;
box.interaction.normalized_local_mouse_coordinates.y = local_mouse.y / box.rect.h;
if box.interaction.clicked {
box.interaction.clicked = false;
}