From 4918501712c9442aa4e5c0eadc14ff2408616a9b Mon Sep 17 00:00:00 2001 From: Synthasmagoria Date: Tue, 25 Aug 2026 15:45:25 +0200 Subject: [PATCH] Moving animation shapes --- animation.odin | 28 ++++------------- program.odin | 81 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 76 insertions(+), 33 deletions(-) diff --git a/animation.odin b/animation.odin index 2fcf2a3..9aaad8c 100644 --- a/animation.odin +++ b/animation.odin @@ -54,12 +54,8 @@ draw_animation_rectangle_corners :: proc(corners: RectangleCorners, color: rl.Co as in 2d. But I'm not sure if that's actually how it works. */ -AnimationShape_Rectangle :: struct { - origin: RectangleCorners, -} - AnimationShapes :: struct { - rectangle: AnimationShape_Rectangle, + rectangle: RectangleCorners, } Animation :: struct { @@ -94,17 +90,11 @@ animation_init :: proc(animation: ^Animation, matrices: []f32) { type = .Rectangle, matrices = matrices, shapes = { - rectangle = { - origin = rectangle_corners_from_rect(rect2{-16, -16, 32, 32}) - } + rectangle = rectangle_corners_from_rect(rect2{-16, -16, 32, 32}) }, } } -animation_reset :: proc(animation: ^Animation) { - animation.matrix_index = 0.0 -} - animation_is_finished :: proc(animation: Animation) -> bool { return animation.matrix_index == f32(animation.matrix_count) } @@ -116,14 +106,14 @@ animation_draw :: proc(animation: Animation, global_transform: mat3) { transform := linalg.identity(mat3) color_origin := cast([4]f32)(ANIMATION_COLOR_ORIGIN) color_end := cast([4]f32)(ANIMATION_COLOR_END) - draw_animation_rectangle_corners(rectangle_corners_transform_mat3(shape.origin, global_transform), ANIMATION_COLOR_ORIGIN) + draw_animation_rectangle_corners(rectangle_corners_transform_mat3(shape, global_transform), ANIMATION_COLOR_ORIGIN) matrices := slice.reinterpret([]mat3, animation.matrices) for i in 0.. return } -program_handle_mouse_workspace :: proc(mouse_state: MouseState, top_bar_container, matrix_container: ^ui.Element) -> MouseState { +program_handle_mouse :: proc(mouse_state: MouseState, top_bar_container, matrix_container: ^ui.Element) -> MouseState { mouse := rl.GetMousePosition() mouse_wheel := rl.GetMouseWheelMoveV() + world_to_grid_matrix := grid_world_to_grid_matrix(program.grid.zoom, program.grid.offset) + grid_to_world_matrix := linalg.inverse(world_to_grid_matrix) + + for draggable in program.mouse_draggables { + switch draggable.type { + case .Point: + position := cast(^v2)draggable.data + position_world := (v3{**position^, 1.0} * grid_to_world_matrix).xy + rl.DrawCircleV(position_world, program.mouse_draggable_radius, ANIMATION_COLOR_ORIGIN) + } + } + switch mouse_state { case .Hover: if rect_has_point(rect2(matrix_container.area), mouse) { @@ -588,11 +628,32 @@ program_handle_mouse_workspace :: proc(mouse_state: MouseState, top_bar_containe return mouse_state } if rl.IsMouseButtonPressed(.LEFT) { + for draggable in program.mouse_draggables { + switch draggable.type { + case .Point: + position := cast(^v2)draggable.data + circle_position := (v3{**position^, 1.0} * grid_to_world_matrix).xy + if linalg.distance(mouse, circle_position) <= program.mouse_draggable_radius { + program.mouse_current_draggable = draggable + return .DraggingDraggable + } + } + } return .DraggingGrid } program.grid.zoom_previous = program.grid.zoom grid_zoom_dimension_lock := v2{1.0 - f32(int(program.grid_zoom_y_only)), 1.0 - f32(int(program.grid_zoom_x_only))} program.grid.zoom += grid_zoom_dimension_lock * mouse_wheel.y * 0.01 + case .DraggingDraggable: + if !rl.IsMouseButtonDown(.LEFT) { + return .Hover + } + draggable := program.mouse_current_draggable + switch draggable.type { + case .Point: + vector := cast(^v2)draggable.data + vector^ = (v3{**mouse, 1.0} * world_to_grid_matrix).xy + } case .DraggingGrid: program.grid.offset -= rl.GetMouseDelta() if !rl.IsMouseButtonDown(.LEFT) { @@ -689,17 +750,17 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u case .StartTransformation: if program.matrix_count > 0 { program.animation_state = .Playing - animation_reset(&program.animation) + program.animation.matrix_index = 0.0 } case .PauseTransformation: program.animation_state = .Paused case .ResumeTransformation: if animation_is_finished(program.animation) { - animation_reset(&program.animation) + program.animation.matrix_index = 0.0 } program.animation_state = .Playing case .ResetTransformation: - animation_reset(&program.animation) + program.animation.matrix_index = 0.0 case .SaveProjectConfirm: input := &program.dialog_data.input_text_buffers[0][0] path := strings.string_from_null_terminated_ptr(input, DIALOG_STATE_TEXT_INPUT_FIELD_SIZE)