From 07732bd2aeaab2c92455a8335762a6c11babbf2b Mon Sep 17 00:00:00 2001 From: Synthasmagoria Date: Thu, 27 Aug 2026 12:56:28 +0200 Subject: [PATCH] Reset view --- TODO.MD | 2 -- animation.odin | 8 ++++++++ program.odin | 22 ++++++++++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/TODO.MD b/TODO.MD index 4718e46..741f375 100644 --- a/TODO.MD +++ b/TODO.MD @@ -1,6 +1,4 @@ - Scale resolution -- Tooltips -- Reset zoom - Save grid and animation data to file - Load project - Fix focus on submenu diff --git a/animation.odin b/animation.odin index 3f91543..f2b05b8 100644 --- a/animation.odin +++ b/animation.odin @@ -189,3 +189,11 @@ animation_draw :: proc(animation: Animation, global_transform: mat3) { } } } + +animation_get_center :: proc(animation: Animation) -> v2 { + switch animation.type { + case .Rectangle: + return linalg.lerp(animation.shapes.rectangle.tl, animation.shapes.rectangle.br, v2(0.5)) + } + unreachable() +} diff --git a/program.odin b/program.odin index 5a08f33..31bee1e 100644 --- a/program.odin +++ b/program.odin @@ -72,6 +72,7 @@ UiButtonType :: enum { MatrixDelete, MatrixMoveUp, MatrixMoveDown, + CenterView, } UiButtonRecalculateFinishGroup :: bit_set[UiButtonType]{ @@ -609,23 +610,29 @@ program_build_workspace_ui :: proc(ctx: ^ui.Context) -> button_data = new(UiElementData_Button, context.temp_allocator) switch program.animation_state { case .Ready: - button_config.label = RAYGUI_ICON_PLAY + button_config = {margin = button_margin, label = RAYGUI_ICON_PLAY, tooltip = "Play\nanimation"} button_data^ = {type = .StartTransformation} case .Paused: - button_config.label = RAYGUI_ICON_PLAY + button_config = {margin = button_margin, label = RAYGUI_ICON_PLAY, tooltip = "Resume\nanimation"} button_data^ = {type = .ResumeTransformation} case .Playing: - button_config.label = RAYGUI_ICON_PAUSE + button_config = {margin = button_margin, label = RAYGUI_ICON_PAUSE, tooltip = "Pause\nanimation"} button_data^ = {type = .PauseTransformation} } ui.same_line() ui.element(.Button, button_dimensions, button_config, button_data) + button_config = {margin = button_margin, label = RAYGUI_ICON_RESET, tooltip = "Reset\nanimation"} button_data = new(UiElementData_Button, context.temp_allocator) - button_config.label = RAYGUI_ICON_RESET button_data^ = {type = .ResetTransformation} ui.same_line() ui.element(.Button, button_dimensions, button_config, button_data) + + button_config = {margin = button_margin, label = "1", tooltip = "Center\nanimation"} + button_data = new(UiElementData_Button, context.temp_allocator) + button_data^ = {type = .CenterView} + ui.same_line() + ui.element(.Button, button_dimensions, button_config, button_data) } ui.container_end() @@ -867,6 +874,13 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u case .MatrixMoveDown: if data.target_matrix + 1 >= program.matrix_count do break; matrix_move_to(program.matrix_float_pool, program.matrix_value_string_pool, data.target_matrix, data.target_matrix + 1) + case .CenterView: + // TODO (synthas): Could be improved to center the whole animation + // TODO (synthas): Reset zoom + 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) + center := animation_get_center(program.animation) / grid_get_zoom(program.grid.zoom) - program.grid.world_size / 2.0 + program.grid.offset = center } if data.type in UiButtonRecalculateFinishGroup { program.animation.matrix_count = program.matrix_count