diff --git a/default b/default index 84c6bc7..6dacf6b 100755 Binary files a/default and b/default differ diff --git a/src/animation.odin b/src/animation.odin index 2e14160..bb001b3 100644 --- a/src/animation.odin +++ b/src/animation.odin @@ -226,13 +226,15 @@ animation_draw :: proc(animation: Animation, global_transform: mat3, temp_alloca color := linalg.lerp(color_origin, color_end, f32(i) / f32(animation.matrix_count)) draw_animation_rectangle_corners(rectangle, rl.Color(color)) } - - animation_progress := math.clamp(animation.matrix_index, 0.0, f32(animation.matrix_count - 1)) + if animation.matrix_count <= 0 { + break + } + animation_progress := math.clamp(animation.matrix_index, 0.0, f32(animation.matrix_count)) animation_progress_frame := ease.ease(animation.ease, fract(animation.matrix_index)) animation_progress_total := animation_progress + animation_progress_frame animation_progress_fraction := animation_progress_total / f32(animation.matrix_count) - rectangle_previous := rectangles[i32(animation_progress)] - rectangle_next := rectangles[i32(animation_progress + 1)] + rectangle_previous := rectangles[int(animation_progress)] + rectangle_next := rectangles[min(int(animation_progress + 1), animation.matrix_count)] rectangle_current := rectangle_corners_lerp(rectangle_previous, rectangle_next, animation_progress_frame) rectangle_current_color := linalg.lerp(color_origin, color_end, animation_progress_fraction) draw_animation_rectangle_corners(rectangle_current, rl.Color(rectangle_current_color)) diff --git a/src/grid.odin b/src/grid.odin index 180e724..3e118ed 100644 --- a/src/grid.odin +++ b/src/grid.odin @@ -5,7 +5,7 @@ import rl "libraries/raylib" Grid :: struct { cell_size_px: v2, - zoom_previous, zoom: v2, + zoom: v2, offset: v2, } diff --git a/src/program.odin b/src/program.odin index 1f9553e..0d93a9c 100644 --- a/src/program.odin +++ b/src/program.odin @@ -111,6 +111,7 @@ UiButtonType :: enum { PauseTransformation, ResumeTransformation, ResetTransformation, + ResetGrid, MatrixDelete, MatrixMoveUp, MatrixMoveDown, @@ -336,6 +337,8 @@ program_save_project :: proc(program: ^Program, path: string) -> ProjectWriteErr project := ProjectData { matrix_count = u32(program.matrix_count), matrices = program.matrix_float_pool, + grid = program.grid, + shapes = program.animation.shapes, } project_write(&project, path) or_return return nil @@ -360,6 +363,8 @@ program_load_project :: proc(program: ^Program, path: string) -> ProjectReadErro project.matrices = program.matrix_float_pool project_read(&project, path) or_return program.matrix_count = int(project.matrix_count) + program.grid = project.grid + program.animation.shapes = project.shapes for val, i in program.matrix_float_pool[:program.matrix_count * 9] { fmt.bprint(program.matrix_value_string_pool[i][:], val) } @@ -818,6 +823,12 @@ program_build_workspace_ui :: proc(ctx: ^ui.Context) -> (elements: []ui.Element, ui.same_line() ui.element(.Button, button_dimensions, button_config, button_data) + button_config = {margin = button_margin, label = RAYGUI_ICON_RESET, tooltip = "Reset\ngrid"} + button_data = new(UiElementData_Button, context.temp_allocator) + button_data^ = {type = .ResetGrid} + 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} @@ -1089,6 +1100,10 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u case .ProjectLoad: program_show_dialog(&program, .LoadProject) case .ProjectNew: + case .ResetGrid: + program.grid.offset = program_screen_size() / 2.0 + program.grid.zoom = 1.0 + program.grid.cell_size_px = 50.0 case .DismissError: program.state = .Normal } diff --git a/src/project.odin b/src/project.odin index f7f1c88..af8114a 100644 --- a/src/project.odin +++ b/src/project.odin @@ -8,7 +8,7 @@ ProjectData :: struct { matrix_count: u32, matrices: []f32, grid: Grid, - animation: Animation, + shapes: AnimationShapes, } project_write :: proc(project: ^ProjectData, path: string) -> ProjectWriteError { diff --git a/src/project_default.odin b/src/project_default.odin index f7b168a..b4b3fa9 100644 --- a/src/project_default.odin +++ b/src/project_default.odin @@ -34,7 +34,9 @@ _project_write :: proc(project: ^ProjectData, path: string) -> ProjectWriteError io.write_full(w, transmute([]u8)header) or_return io.write_ptr(w, &version, size_of(version)) or_return io.write_ptr(w, &project.matrix_count, size_of(project.matrix_count)) or_return - n := io.write_ptr(w, raw_data(project.matrices), int(project.matrix_count) * 9 * size_of(f32)) or_return + _ = io.write_ptr(w, raw_data(project.matrices), int(project.matrix_count) * 9 * size_of(f32)) or_return + _ = io.write_ptr(w, &project.grid, size_of(project.grid)) or_return + _ = io.write_ptr(w, &project.shapes, size_of(project.shapes)) or_return os.close(f) return nil } @@ -56,6 +58,8 @@ _project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError { return ProjectReadErrorType.VersionNeedsUpgrade } _ = io.read_ptr(r, &project.matrix_count, size_of(project.matrix_count)) or_return - n := io.read_ptr(r, raw_data(project.matrices), size_of(f32) * len(project.matrices)) or_return + _ = io.read_ptr(r, raw_data(project.matrices), size_of(f32) * int(project.matrix_count) * 9) or_return + _ = io.read_ptr(r, &project.grid, size_of(project.grid)) or_return + _ = io.read_ptr(r, &project.shapes, size_of(project.shapes)) or_return return nil }