diff --git a/build_web.sh b/build_web.sh index db4f94d..8b88556 100755 --- a/build_web.sh +++ b/build_web.sh @@ -43,7 +43,7 @@ files="$OUT_DIR/$WASM_OBJ_NAME $RAYLIB_PATH/wasm/libraylib.a $RAYLIB_PATH/wasm/l # index_template.html contains the javascript code that calls the procedures in # source/main_web/main_web.odin EMCC_SETTINGS="-sEXPORTED_RUNTIME_METHODS=['HEAPF32'] -sUSE_GLFW=3 -sWASM_BIGINT -sWARN_ON_UNDEFINED_SYMBOLS=0" -flags="-Wl,--gc-sections -Os $EMCC_SETTINGS --shell-file $INDEX_TEMPLATE_PATH --preload-file src/assets" +flags="-Os $EMCC_SETTINGS --shell-file $INDEX_TEMPLATE_PATH --preload-file src/assets" # For debugging: Add `-g` to `emcc` (gives better error callstack in chrome) emcc -o $OUT_DIR/index.html $files $flags diff --git a/src/animation.odin b/src/animation.odin index b9ae9df..d5ea02f 100644 --- a/src/animation.odin +++ b/src/animation.odin @@ -170,6 +170,11 @@ AnimationMatrixType :: enum { Mat4, } +AnimationMode :: enum { + Step, + All, +} + @private @rodata animation_matrix_type_size := [AnimationMatrixType]int { .Mat2 = size_of(mat2), .Mat3 = size_of(mat3), @@ -199,7 +204,7 @@ animation_get_eased_progress :: proc(animation: Animation) -> f32 { return math.floor(animation.matrix_index) + ease.ease(animation.ease, fract(animation.matrix_index)) } -animation_draw :: proc(animation: Animation, global_transform: mat3, temp_allocator := context.temp_allocator) { +animation_draw :: proc(animation: Animation, global_transform: mat3, mode: AnimationMode, temp_allocator := context.temp_allocator) { color_origin := cast([4]f32)ANIMATION_COLOR_ORIGIN color_end := cast([4]f32)ANIMATION_COLOR_END @@ -221,16 +226,21 @@ animation_draw :: proc(animation: Animation, global_transform: mat3, temp_alloca 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 := math.floor(animation_progress) + animation_progress_frame - // TODO (synthas): math.min is a temp fix because I lost track of the math and got lazy with it - animation_progress_fraction := math.min(animation_progress_total / f32(animation.matrix_count), 1.0) - 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)) + switch mode { + case .Step: + 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 := math.floor(animation_progress) + animation_progress_frame + // TODO (synthas): math.min is a temp fix because I lost track of the math and got lazy with it + animation_progress_fraction := math.min(animation_progress_total / f32(animation.matrix_count), 1.0) + 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)) + case .All: + + } } } diff --git a/src/program.odin b/src/program.odin index 978279b..9b133ed 100644 --- a/src/program.odin +++ b/src/program.odin @@ -295,6 +295,7 @@ Program :: struct { animation: Animation, animation_state: ProgramAnimationState, animation_speed: f32, + animation_mode: AnimationMode, window_should_close: bool, } @@ -568,7 +569,7 @@ program_update :: proc() { animation.matrix_index += 0.01 } - animation_draw(animation^, linalg.inverse(grid_world_to_grid_matrix(program.grid.zoom, program.grid.offset))) + animation_draw(animation^, linalg.inverse(grid_world_to_grid_matrix(program.grid.zoom, program.grid.offset)), program.animation_mode) switch animation.type { case .Rectangle: @@ -872,6 +873,18 @@ program_build_workspace_ui :: proc(ctx: ^ui.Context) -> (elements: []ui.Element, } ui.same_line() ui.element(.Slider, slider_dimensions, slider_config, slider_data) + + label_config := ui.ElementConfiguration{margin = button_margin, label = "Animation mode: ", color = ui.col(rl.WHITE)} + ui.same_line() + ui.element(.Label, ui.dimensions_auto(), label_config) + + toggle_group_config := ui.ElementConfiguration{margin = button_margin, label = enum_to_raygui_options_string(AnimationMode, context.temp_allocator)} + toggle_group_dimensions := ui.Dimensions{top_bar_button_width * 2.0, ui.Size_Percentage(1.0)} + toggle_group_data: ^UiElementData_ToggleGroup + toggle_group_data = new(UiElementData_ToggleGroup, context.temp_allocator) + toggle_group_data^ = {value = cast(^i32)&program.animation_mode} + ui.same_line() + ui.element(.ToggleGroup, toggle_group_dimensions, toggle_group_config, toggle_group_data) } ui.container_end()