simplify
This commit is contained in:
parent
1c2a324f55
commit
4e920b5f0a
3 changed files with 119 additions and 156 deletions
79
program.odin
79
program.odin
|
|
@ -197,25 +197,7 @@ Program :: struct {
|
|||
message_type: ProgramMessageType,
|
||||
dialog_type: ProgramDialogType,
|
||||
dialog_data: ProgramData_DialogState,
|
||||
animation_data: AnimationData,
|
||||
animation_state: AnimationState,
|
||||
animations: [AnimationType]AnimationInterface,
|
||||
animation: AnimationInterface,
|
||||
animation_matrix_index: int,
|
||||
animation_matrix_progress: f32,
|
||||
animation_speed: f32,
|
||||
animation_ease: ease.Ease,
|
||||
}
|
||||
|
||||
AnimationData :: struct {
|
||||
rectangle: AnimationData_Rectangle,
|
||||
}
|
||||
|
||||
AnimationState :: enum {
|
||||
Ready,
|
||||
Playing,
|
||||
Paused,
|
||||
Finished,
|
||||
animation: Animation,
|
||||
}
|
||||
|
||||
float_slice_get_mat3 :: proc(floats: []f32, index: int) -> ^mat3 {
|
||||
|
|
@ -254,7 +236,7 @@ program_load_project :: proc(program: ^Program, path: string) -> ProjectReadErro
|
|||
for val, i in program.matrix_float_pool[:program.matrix_count * 9] {
|
||||
fmt.bprint(program.matrix_value_string_pool[i][:], val)
|
||||
}
|
||||
animation_update_last(&program.animation, program_get_master_matrix())
|
||||
animation_update(&program.animation, (cast([^]mat3)(raw_data(program.matrix_float_pool)))[:program.matrix_count])
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -286,16 +268,7 @@ program_init :: proc(allocator := context.allocator) {
|
|||
ui.init(&program.ui_overlay_context, 200, ui_measure_text, &program.font_style, allocator)
|
||||
program.ui_overlay_element_focus = ui.element_id_invalid()
|
||||
|
||||
animation_rectangle := RectangleCorners {{320.0, 320.0}, {352.0, 320.0}, {352.0, 352.0}, {320.0, 352.0}}
|
||||
program.animation_data = {
|
||||
rectangle = {animation_rectangle,animation_rectangle,animation_rectangle,animation_rectangle,animation_rectangle},
|
||||
}
|
||||
program.animations = {
|
||||
.Rectangle = animation_create_rectangle(&program.animation_data.rectangle)
|
||||
}
|
||||
program.animation = program.animations[.Rectangle]
|
||||
program.animation_speed = 0.02
|
||||
program.animation_ease = .Quadratic_Out
|
||||
animation_init(&program.animation, program.matrix_float_pool)
|
||||
|
||||
if err := program_load_project(&program, DEFAULT_PROJECT_LOAD_LOCATION); err != nil {
|
||||
fmt.println("ERROR:", err)
|
||||
|
|
@ -312,12 +285,11 @@ program_get_master_matrix :: proc() -> mat3 {
|
|||
}
|
||||
|
||||
program_set_transformation_state :: proc(state: AnimationState) {
|
||||
if program.animation_state == state do return
|
||||
previous_state := program.animation_state
|
||||
program.animation_state = state
|
||||
switch program.animation_state {
|
||||
if program.animation.state == state do return
|
||||
previous_state := program.animation.state
|
||||
program.animation.state = state
|
||||
switch program.animation.state {
|
||||
case .Ready:
|
||||
program.animation_matrix_index = -1
|
||||
animation_reset(&program.animation)
|
||||
case .Playing:
|
||||
|
||||
|
|
@ -404,7 +376,7 @@ program_update :: proc() {
|
|||
}
|
||||
case .LoadProject:
|
||||
}
|
||||
animation_update_last(&program.animation, program_get_master_matrix())
|
||||
animation_update(&program.animation, (cast([^]mat3)(raw_data(program.matrix_float_pool)))[:program.matrix_count])
|
||||
program.state = .Normal
|
||||
}
|
||||
}
|
||||
|
|
@ -414,27 +386,7 @@ program_update :: proc() {
|
|||
grid_text_clip := rect_from_area(v2{matrix_container_br.x, top_bar_container_br.y}, v2{WINDOW_WIDTH, WINDOW_HEIGHT})
|
||||
draw_grid(program.grid, rect_grow(grid_text_clip, -4.0), rect_grow(grid_text_clip, -32.0))
|
||||
|
||||
if program.animation_state == .Playing {
|
||||
program.animation_matrix_progress += program.animation_speed * delta_time_fraction()
|
||||
if program.animation_matrix_progress >= 1.0 {
|
||||
if program.animation_matrix_index + 1 < program.matrix_count {
|
||||
program.animation_matrix_index += 1
|
||||
animation_next_matrix(&program.animation, float_slice_get_mat3(program.matrix_float_pool, program.animation_matrix_index)^)
|
||||
program.animation_matrix_progress = fract(program.animation_matrix_progress)
|
||||
} else {
|
||||
program.animation_matrix_progress = 1.0;
|
||||
program.animation_state = .Finished
|
||||
}
|
||||
}
|
||||
animation_update(&program.animation, ease.ease(program.animation_ease, program.animation_matrix_progress))
|
||||
}
|
||||
|
||||
switch program.animation_state {
|
||||
case .Ready:
|
||||
animation_draw_idle(program.animation)
|
||||
case .Playing, .Paused, .Finished:
|
||||
animation_draw_active(program.animation)
|
||||
}
|
||||
animation_draw(program.animation)
|
||||
|
||||
ui_element_focus := program.state == .Normal ? program.ui_element_focus : ui.element_id_invalid()
|
||||
program.ui_element_focus = program_render_ui_and_handle_focus(&program.ui_context, ui_element_focus, program.font_style, ui_elements)
|
||||
|
|
@ -576,7 +528,7 @@ program_build_workspace_ui :: proc(ctx: ^ui.Context) ->
|
|||
|
||||
play_button_label: cstring
|
||||
button_data = new(UiElementData_Button, context.temp_allocator)
|
||||
switch program.animation_state {
|
||||
switch program.animation.state {
|
||||
case .Ready, .Finished:
|
||||
button_config.label = RAYGUI_ICON_PLAY
|
||||
button_data^ = {type = .StartTransformation}
|
||||
|
|
@ -723,14 +675,13 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u
|
|||
program.state = .Normal
|
||||
case .StartTransformation:
|
||||
if program.matrix_count > 0 {
|
||||
program.animation_state = .Playing
|
||||
program.animation.state = .Playing
|
||||
animation_reset(&program.animation)
|
||||
animation_next_matrix(&program.animation, (cast(^mat3)raw_data(program.matrix_float_pool))^)
|
||||
}
|
||||
case .PauseTransformation:
|
||||
program.animation_state = .Paused
|
||||
program.animation.state = .Paused
|
||||
case .ResumeTransformation:
|
||||
program.animation_state = .Playing
|
||||
program.animation.state = .Playing
|
||||
case .ResetTransformation:
|
||||
animation_reset(&program.animation)
|
||||
case .SaveProjectConfirm:
|
||||
|
|
@ -760,7 +711,7 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u
|
|||
matrix_move_to(program.matrix_float_pool, program.matrix_value_string_pool, data.target_matrix, data.target_matrix + 1)
|
||||
}
|
||||
if data.type in UiButtonRecalculateFinishGroup {
|
||||
animation_update_last(&program.animation, program_get_master_matrix())
|
||||
animation_update(&program.animation, (cast([^]mat3)(raw_data(program.matrix_float_pool)))[:program.matrix_count])
|
||||
}
|
||||
}
|
||||
case .Slider:
|
||||
|
|
@ -773,7 +724,7 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u
|
|||
focus_element_id = element.id
|
||||
}
|
||||
if value_previous != data.value^ && .UpdateMatrix in data.tag {
|
||||
animation_update_last(&program.animation, program_get_master_matrix())
|
||||
animation_update(&program.animation, (cast([^]mat3)(raw_data(program.matrix_float_pool)))[:program.matrix_count])
|
||||
}
|
||||
case .InputText:
|
||||
data := cast(^UiElementData_TextInput)element.data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue