Show coordsr
This commit is contained in:
parent
9aee47c12c
commit
3241dc52b6
2 changed files with 70 additions and 55 deletions
|
|
@ -53,49 +53,25 @@ rectangle_corners_move_corner :: proc "contextless" (corners: RectangleCorners,
|
||||||
corners := corners
|
corners := corners
|
||||||
switch corner {
|
switch corner {
|
||||||
case .Tl:
|
case .Tl:
|
||||||
corners = _rectangle_corners_move_corner_resolve_tl(corners, position)
|
corners.tl = position
|
||||||
|
corners.bl.x = position.x
|
||||||
|
corners.tr.y = position.y
|
||||||
case .Tr:
|
case .Tr:
|
||||||
corners = _rectangle_corners_move_corner_resolve_tr(corners, position)
|
corners.tr = position
|
||||||
|
corners.br.x = position.x
|
||||||
|
corners.tl.y = position.y
|
||||||
case .Br:
|
case .Br:
|
||||||
corners = _rectangle_corners_move_corner_resolve_br(corners, position)
|
corners.br = position
|
||||||
|
corners.tr.x = position.x
|
||||||
|
corners.bl.y = position.y
|
||||||
case .Bl:
|
case .Bl:
|
||||||
corners = _rectangle_corners_move_corner_resolve_bl(corners, position)
|
corners.bl = position
|
||||||
|
corners.tl.x = position.x
|
||||||
|
corners.br.y = position.y
|
||||||
}
|
}
|
||||||
return corners
|
return corners
|
||||||
}
|
}
|
||||||
|
|
||||||
_rectangle_corners_move_corner_resolve_tl :: proc "contextless" (corners: RectangleCorners, position: v2) -> RectangleCorners {
|
|
||||||
corners := corners
|
|
||||||
corners.tl = position
|
|
||||||
corners.bl.x = position.x
|
|
||||||
corners.tr.y = position.y
|
|
||||||
return corners
|
|
||||||
}
|
|
||||||
|
|
||||||
_rectangle_corners_move_corner_resolve_tr :: proc "contextless" (corners: RectangleCorners, position: v2) -> RectangleCorners {
|
|
||||||
corners := corners
|
|
||||||
corners.tr = position
|
|
||||||
corners.br.x = position.x
|
|
||||||
corners.tl.y = position.y
|
|
||||||
return corners
|
|
||||||
}
|
|
||||||
|
|
||||||
_rectangle_corners_move_corner_resolve_br :: proc "contextless" (corners: RectangleCorners, position: v2) -> RectangleCorners {
|
|
||||||
corners := corners
|
|
||||||
corners.br = position
|
|
||||||
corners.tr.x = position.x
|
|
||||||
corners.bl.y = position.y
|
|
||||||
return corners
|
|
||||||
}
|
|
||||||
|
|
||||||
_rectangle_corners_move_corner_resolve_bl :: proc "contextless" (corners: RectangleCorners, position: v2) -> RectangleCorners {
|
|
||||||
corners := corners
|
|
||||||
corners.bl = position
|
|
||||||
corners.tl.x = position.x
|
|
||||||
corners.br.y = position.y
|
|
||||||
return corners
|
|
||||||
}
|
|
||||||
|
|
||||||
rectangle_corners_transform_mat2 :: proc "contextless" (corners: RectangleCorners, transform: mat2) -> RectangleCorners {
|
rectangle_corners_transform_mat2 :: proc "contextless" (corners: RectangleCorners, transform: mat2) -> RectangleCorners {
|
||||||
return {corners.tl * transform, corners.tr * transform, corners.br * transform, corners.bl * transform}
|
return {corners.tl * transform, corners.tr * transform, corners.br * transform, corners.bl * transform}
|
||||||
}
|
}
|
||||||
|
|
@ -160,6 +136,7 @@ Animation :: struct {
|
||||||
matrix_count: int,
|
matrix_count: int,
|
||||||
matrix_type: AnimationMatrixType,
|
matrix_type: AnimationMatrixType,
|
||||||
shapes: AnimationShapes,
|
shapes: AnimationShapes,
|
||||||
|
shapes_animated_last: AnimationShapes,
|
||||||
ease: ease.Ease,
|
ease: ease.Ease,
|
||||||
type: AnimationType,
|
type: AnimationType,
|
||||||
}
|
}
|
||||||
|
|
@ -194,6 +171,7 @@ animation_init :: proc(animation: ^Animation, matrices: []f32) {
|
||||||
rectangle = rectangle_corners_from_rect(rect2{-16, -16, 32, 32})
|
rectangle = rectangle_corners_from_rect(rect2{-16, -16, 32, 32})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
animation.shapes_animated_last = animation.shapes
|
||||||
}
|
}
|
||||||
|
|
||||||
animation_is_finished :: proc(animation: Animation) -> bool {
|
animation_is_finished :: proc(animation: Animation) -> bool {
|
||||||
|
|
@ -204,24 +182,24 @@ animation_get_eased_progress :: proc(animation: Animation) -> f32 {
|
||||||
return math.floor(animation.matrix_index) + ease.ease(animation.ease, fract(animation.matrix_index))
|
return math.floor(animation.matrix_index) + ease.ease(animation.ease, fract(animation.matrix_index))
|
||||||
}
|
}
|
||||||
|
|
||||||
animation_draw :: proc(animation: Animation, global_transform: mat3, mode: AnimationMode, 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_origin := cast([4]f32)ANIMATION_COLOR_ORIGIN
|
||||||
color_end := cast([4]f32)ANIMATION_COLOR_END
|
color_end := cast([4]f32)ANIMATION_COLOR_END
|
||||||
|
|
||||||
switch animation.type {
|
switch animation.type {
|
||||||
case .Rectangle:
|
case .Rectangle:
|
||||||
rectangles := make([]RectangleCorners, animation.matrix_count + 1, temp_allocator)
|
rectangles := make([]RectangleCorners, animation.matrix_count + 1, temp_allocator)
|
||||||
rectangles[0] = rectangle_corners_transform_mat3(global_transform, animation.shapes.rectangle)
|
rectangles[0] = animation.shapes.rectangle
|
||||||
transform := linalg.identity(mat3)
|
transform := linalg.identity(mat3)
|
||||||
matrices := slice.reinterpret([]mat3, animation.matrices[:animation.matrix_count * 9])
|
matrices := slice.reinterpret([]mat3, animation.matrices[:animation.matrix_count * 9])
|
||||||
for mat, i in matrices {
|
for mat, i in matrices {
|
||||||
transform *= mat
|
transform *= mat
|
||||||
rectangle_transformed := rectangle_corners_transform_mat3(transform, animation.shapes.rectangle)
|
rectangles[i + 1] = rectangle_corners_transform_mat3(transform, animation.shapes.rectangle)
|
||||||
rectangles[i + 1] = rectangle_corners_transform_mat3(global_transform, rectangle_transformed)
|
|
||||||
}
|
}
|
||||||
for rectangle, i in rectangles {
|
for rectangle, i in rectangles {
|
||||||
color := linalg.lerp(color_origin, color_end, f32(i) / f32(animation.matrix_count))
|
color := linalg.lerp(color_origin, color_end, f32(i) / f32(animation.matrix_count))
|
||||||
draw_animation_rectangle_corners(rectangle, rl.Color(color))
|
rectangle_world := rectangle_corners_transform_mat3(global_transform, rectangle)
|
||||||
|
draw_animation_rectangle_corners(rectangle_world, rl.Color(color))
|
||||||
}
|
}
|
||||||
if animation.matrix_count <= 0 {
|
if animation.matrix_count <= 0 {
|
||||||
break
|
break
|
||||||
|
|
@ -235,18 +213,20 @@ animation_draw :: proc(animation: Animation, global_transform: mat3, mode: Anima
|
||||||
animation_progress_fraction := math.min(animation_progress_total / f32(animation.matrix_count), 1.0)
|
animation_progress_fraction := math.min(animation_progress_total / f32(animation.matrix_count), 1.0)
|
||||||
rectangle_previous := rectangles[int(animation_progress)]
|
rectangle_previous := rectangles[int(animation_progress)]
|
||||||
rectangle_next := rectangles[min(int(animation_progress + 1), animation.matrix_count)]
|
rectangle_next := rectangles[min(int(animation_progress + 1), animation.matrix_count)]
|
||||||
rectangle_current := rectangle_corners_lerp(rectangle_previous, rectangle_next, animation_progress_frame)
|
rectangle := rectangle_corners_lerp(rectangle_previous, rectangle_next, animation_progress_frame)
|
||||||
rectangle_current_color := linalg.lerp(color_origin, color_end, animation_progress_fraction)
|
rectangle_world := rectangle_corners_transform_mat3(global_transform, rectangle)
|
||||||
draw_animation_rectangle_corners(rectangle_current, rl.Color(rectangle_current_color))
|
rectangle_color := linalg.lerp(color_origin, color_end, animation_progress_fraction)
|
||||||
|
draw_animation_rectangle_corners(rectangle_world, rl.Color(rectangle_color))
|
||||||
|
animation.shapes_animated_last.rectangle = rectangle
|
||||||
case .All:
|
case .All:
|
||||||
animation_progress := math.clamp(animation.matrix_index / f32(animation.matrix_count), 0.0, 1.0)
|
animation_progress := math.clamp(animation.matrix_index / f32(animation.matrix_count), 0.0, 1.0)
|
||||||
animation_progress = ease.ease(animation.ease, animation_progress)
|
animation_progress = ease.ease(animation.ease, animation_progress)
|
||||||
color := linalg.lerp(color_origin, color_end, animation_progress)
|
color := linalg.lerp(color_origin, color_end, animation_progress)
|
||||||
rectangle_end := rectangle_corners_transform_mat3(transform, animation.shapes.rectangle)
|
rectangle_end := rectangle_corners_transform_mat3(transform, animation.shapes.rectangle)
|
||||||
rectangle_end_world := rectangle_corners_transform_mat3(global_transform, rectangle_end)
|
rectangle := rectangle_corners_lerp(animation.shapes.rectangle, rectangle_end, animation_progress)
|
||||||
rectangle_origin_world := rectangle_corners_transform_mat3(global_transform, animation.shapes.rectangle)
|
rectangle_world := rectangle_corners_transform_mat3(global_transform, rectangle)
|
||||||
rectangle := rectangle_corners_lerp(rectangle_origin_world, rectangle_end_world, animation_progress)
|
draw_animation_rectangle_corners(rectangle_world, rl.Color(color))
|
||||||
draw_animation_rectangle_corners(rectangle, rl.Color(color))
|
animation.shapes_animated_last.rectangle = rectangle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -263,6 +263,11 @@ RotationMode :: enum {
|
||||||
Radians,
|
Radians,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProgramShowAnimationCoords :: enum {
|
||||||
|
NoCoords,
|
||||||
|
Coords,
|
||||||
|
}
|
||||||
|
|
||||||
Program :: struct {
|
Program :: struct {
|
||||||
ui_context: ui.Context,
|
ui_context: ui.Context,
|
||||||
ui_element_focus: ui.ElementId,
|
ui_element_focus: ui.ElementId,
|
||||||
|
|
@ -296,6 +301,7 @@ Program :: struct {
|
||||||
animation_state: ProgramAnimationState,
|
animation_state: ProgramAnimationState,
|
||||||
animation_speed: f32,
|
animation_speed: f32,
|
||||||
animation_mode: AnimationMode,
|
animation_mode: AnimationMode,
|
||||||
|
animation_show_coordinates: ProgramShowAnimationCoords,
|
||||||
window_should_close: bool,
|
window_should_close: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -562,6 +568,7 @@ program_update :: proc() {
|
||||||
grid_origin_color := rl.Color{255, 255, 255, 128}
|
grid_origin_color := rl.Color{255, 255, 255, 128}
|
||||||
draw_grid(program.grid, grid_area, rect_grow(grid_text_clip, -4.0), rect_grow(grid_text_clip, -32.0), grid_color, grid_origin_color)
|
draw_grid(program.grid, grid_area, rect_grow(grid_text_clip, -4.0), rect_grow(grid_text_clip, -32.0), grid_color, grid_origin_color)
|
||||||
|
|
||||||
|
shape_coord_string: cstring
|
||||||
{
|
{
|
||||||
animation := &program.animation
|
animation := &program.animation
|
||||||
|
|
||||||
|
|
@ -569,7 +576,8 @@ program_update :: proc() {
|
||||||
animation.matrix_index += 0.01
|
animation.matrix_index += 0.01
|
||||||
}
|
}
|
||||||
|
|
||||||
animation_draw(animation^, linalg.inverse(grid_world_to_grid_matrix(program.grid.zoom, program.grid.offset)), program.animation_mode)
|
grid_to_world_matrix := linalg.inverse(grid_world_to_grid_matrix(program.grid.zoom, program.grid.offset))
|
||||||
|
animation_draw(animation, grid_to_world_matrix, program.animation_mode)
|
||||||
|
|
||||||
switch animation.type {
|
switch animation.type {
|
||||||
case .Rectangle:
|
case .Rectangle:
|
||||||
|
|
@ -590,6 +598,17 @@ program_update :: proc() {
|
||||||
corners_ref = &animation.shapes.rectangle,
|
corners_ref = &animation.shapes.rectangle,
|
||||||
corner_ref = &animation.shapes.rectangle.br})
|
corner_ref = &animation.shapes.rectangle.br})
|
||||||
append(&program.mouse_draggables, MouseDraggable_RectangleData{&animation.shapes.rectangle})
|
append(&program.mouse_draggables, MouseDraggable_RectangleData{&animation.shapes.rectangle})
|
||||||
|
|
||||||
|
rectangle_corners := animation.shapes_animated_last.rectangle
|
||||||
|
rectangle := rect_from_corners(rectangle_corners.tl, rectangle_corners.tr, rectangle_corners.br, rectangle_corners.bl)
|
||||||
|
rectangle_corners = rectangle_corners_from_rect(rectangle)
|
||||||
|
shape_coord_string = fmt.ctprintf(
|
||||||
|
"tl: {{%.2f, %.2f}}\ntr: {{%.2f, %.2f}}\nbr: {{%.2f, %.2f}}\nbl: {{%.2f, %.2f}}",
|
||||||
|
rectangle_corners.tl.x, rectangle_corners.tl.y,
|
||||||
|
rectangle_corners.tr.x, rectangle_corners.tr.y,
|
||||||
|
rectangle_corners.br.x, rectangle_corners.br.y,
|
||||||
|
rectangle_corners.bl.x, rectangle_corners.bl.y,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -617,6 +636,11 @@ program_update :: proc() {
|
||||||
program.font_style,
|
program.font_style,
|
||||||
ui_overlay_elements)
|
ui_overlay_elements)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (program.animation_show_coordinates == .Coords) {
|
||||||
|
shape_coords_string_position := program_screen_size() - 4.0
|
||||||
|
draw_text_aligned(shape_coord_string, shape_coords_string_position, program.font_style, .Right, .Bottom, rl.WHITE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
program_add_identity_matrix :: proc() {
|
program_add_identity_matrix :: proc() {
|
||||||
|
|
@ -874,20 +898,31 @@ program_build_workspace_ui :: proc(ctx: ^ui.Context) -> (elements: []ui.Element,
|
||||||
ui.same_line()
|
ui.same_line()
|
||||||
ui.element(.Slider, slider_dimensions, slider_config, slider_data)
|
ui.element(.Slider, slider_dimensions, slider_config, slider_data)
|
||||||
|
|
||||||
label_config := ui.ElementConfiguration{margin = button_margin, label = "Animation mode: ", color = ui.col(rl.WHITE)}
|
// label_config := ui.ElementConfiguration{margin = button_margin, label = "Animation mode: ", color = ui.col(rl.WHITE)}
|
||||||
ui.same_line()
|
// ui.same_line()
|
||||||
ui.element(.Label, ui.dimensions_auto(), label_config)
|
// ui.element(.Label, ui.dimensions_auto(), label_config)
|
||||||
|
|
||||||
toggle_group_config := ui.ElementConfiguration{
|
toggle_group_config: ui.ElementConfiguration
|
||||||
|
toggle_group_dimensions := ui.Dimensions{top_bar_button_width * 3.0, ui.Size_Percentage(1.0)}
|
||||||
|
toggle_group_data: ^UiElementData_ToggleGroup
|
||||||
|
|
||||||
|
toggle_group_config = {
|
||||||
margin = button_margin,
|
margin = button_margin,
|
||||||
label = enum_to_raygui_options_string(AnimationMode, context.temp_allocator),
|
label = enum_to_raygui_options_string(AnimationMode, context.temp_allocator),
|
||||||
tooltip = "Play animation\nstep by step;Play animation using the\nfull transformation matrix"}
|
tooltip = "Play animation\nstep by step;Play animation using the\nfull transformation matrix"}
|
||||||
toggle_group_dimensions := ui.Dimensions{top_bar_button_width * 3.0, ui.Size_Percentage(1.0)}
|
|
||||||
toggle_group_data: ^UiElementData_ToggleGroup
|
|
||||||
toggle_group_data = new(UiElementData_ToggleGroup, context.temp_allocator)
|
toggle_group_data = new(UiElementData_ToggleGroup, context.temp_allocator)
|
||||||
toggle_group_data^ = {value = cast(^i32)&program.animation_mode}
|
toggle_group_data^ = {value = cast(^i32)&program.animation_mode}
|
||||||
ui.same_line()
|
ui.same_line()
|
||||||
ui.element(.ToggleGroup, toggle_group_dimensions, toggle_group_config, toggle_group_data)
|
ui.element(.ToggleGroup, toggle_group_dimensions, toggle_group_config, toggle_group_data)
|
||||||
|
|
||||||
|
toggle_group_config = {
|
||||||
|
margin = button_margin,
|
||||||
|
label = enum_to_raygui_options_string(ProgramShowAnimationCoords, context.temp_allocator),
|
||||||
|
}
|
||||||
|
toggle_group_data = new(UiElementData_ToggleGroup, context.temp_allocator)
|
||||||
|
toggle_group_data^ = {value = cast(^i32)&program.animation_show_coordinates}
|
||||||
|
ui.same_line()
|
||||||
|
ui.element(.ToggleGroup, toggle_group_dimensions, toggle_group_config, toggle_group_data)
|
||||||
}
|
}
|
||||||
ui.container_end()
|
ui.container_end()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue