Input: Added viewport local mouse position | Transform: Added default parameter values for create_transform procedure
This commit is contained in:
@@ -34,7 +34,7 @@ make_matrix :: (position: Vector3, orientation: Quaternion, scale: Vector3) -> M
|
||||
return trans_mat * rot_mat * scale_mat;
|
||||
}
|
||||
|
||||
create_transform :: (position: Vector3, orientation: Quaternion, scale: Vector3) -> Transform {
|
||||
create_transform :: (position: Vector3=.{0,0,0}, orientation: Quaternion = .{0,0,0,1}, scale: Vector3=.{1,1,1}) -> Transform {
|
||||
transform : Transform;
|
||||
|
||||
transform.position = position;
|
||||
|
||||
@@ -142,6 +142,8 @@ editor_ui :: () {
|
||||
ui_set_next_size_y(.PCT, 0.75);
|
||||
|
||||
state := ui_interactable_texture(get_texture_from_pass("UI Blend Pass"));
|
||||
engine.input.viewport_mouse_position = state.local_mouse_coordinates;
|
||||
engine.input.normalized_viewport_mouse_position = state.normalized_local_mouse_coordinates;
|
||||
if state.left_mouse_down {
|
||||
if engine.current_scene != null {
|
||||
pick_scene_view_at(engine.editor.camera, .{state.normalized_local_mouse_coordinates.x, 1.0-state.normalized_local_mouse_coordinates.y});
|
||||
|
||||
@@ -157,6 +157,9 @@ Input_State :: struct {
|
||||
wheel: float;
|
||||
}
|
||||
|
||||
normalized_viewport_mouse_position: Vector2;
|
||||
viewport_mouse_position: Vector2;
|
||||
|
||||
gamepads: [MAX_GAMEPADS] Gamepad;
|
||||
num_gamepads: s32;
|
||||
|
||||
@@ -216,6 +219,12 @@ update_input :: () {
|
||||
update_sdl_input();
|
||||
|
||||
update_gamepad_input();
|
||||
|
||||
#if !EDITOR {
|
||||
engine.input.viewport_mouse_position.x = engine.input.mouse.x;
|
||||
engine.input.viewport_mouse_position.y = engine.input.mouse.y;
|
||||
engine.input.normalized_viewport_mouse_position /= Vector2.{xx engine.renderer.render_target_width, xx engine.renderer.render_target_height};
|
||||
}
|
||||
}
|
||||
|
||||
remove_all_temp_key_flags :: (using input_state: *Input_State) {
|
||||
|
||||
10
ui/ui.jai
10
ui/ui.jai
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user