Easier interface use

This commit is contained in:
Synthasmagoria 2026-08-17 23:45:21 +02:00
commit 4261f07762
3 changed files with 73 additions and 29 deletions

View file

@ -9,6 +9,36 @@ import "core:fmt"
as in 2d. But I'm not sure if that's actually how it works.
*/
AnimationInterface :: struct {
data: rawptr,
reset: proc(animation: ^AnimationInterface),
update_last: proc(animation: ^AnimationInterface, master_matrix: mat3),
update: proc(animation: ^AnimationInterface, animation_progress: f32),
next_matrix: proc(animation: ^AnimationInterface, next_matrix: mat3),
draw_idle: proc(animation: AnimationInterface),
draw_active: proc(animation: AnimationInterface),
}
animation_update_last :: proc(animation: ^AnimationInterface, master_matrix: mat3) {
animation.update_last(animation, master_matrix)
}
animation_update :: proc(animation: ^AnimationInterface, animation_progress: f32) {
animation.update(animation, animation_progress)
}
animation_next_matrix :: proc(animation: ^AnimationInterface, next_matrix: mat3) {
animation.next_matrix(animation, next_matrix)
}
animation_draw_idle :: proc(animation: AnimationInterface) {
animation.draw_idle(animation)
}
animation_draw_active :: proc(animation: AnimationInterface) {
animation.draw_active(animation)
}
AnimationType :: enum {
Rectangle,
}
@ -33,17 +63,23 @@ AnimationData_Rectangle :: struct {
draw_transformation_rectangle :: proc(rectangle: RectangleCorners, color: rl.Color) {
rect := rect_from_corners(rectangle.tl, rectangle.tr, rectangle.br, rectangle.bl)
rl.DrawRectangleRec(rect, rl.Color{**color.rgb, color.a / 2})
points := []v2{rectangle.tl, rectangle.tr, rectangle.br, rectangle.bl}
for i := 0; i < len(points); i += 1 {
rl.DrawLineV(points[i], points[(i + 1) % len(points)], color)
rl.DrawCircleV(points[i], 4.0, rl.RED)
}
rl.DrawRectangleLinesEx(rect, 1.0, color)
}
draw_transformation_rectangle_with_handles :: proc(rectangle: RectangleCorners, color: rl.Color) {
rect := rect_from_corners(rectangle.tl, rectangle.tr, rectangle.br, rectangle.bl)
rl.DrawRectangleRec(rect, rl.Color{**color.rgb, color.a / 2})
rl.DrawRectangleLinesEx(rect, 1.0, color)
rl.DrawCircleV(rectangle.tl, 4.0, color)
rl.DrawCircleV(rectangle.tr, 4.0, color)
rl.DrawCircleV(rectangle.br, 4.0, color)
rl.DrawCircleV(rectangle.bl, 4.0, color)
}
_animation_rectangle_draw_idle :: proc(animation: AnimationInterface) {
data := cast(^AnimationData_Rectangle)animation.data
draw_transformation_rectangle(data.last, TRANSFORMATION_RECTANGLE_COLOR_LAST)
draw_transformation_rectangle(data.origin, TRANSFORMATION_RECTANGLE_COLOR_ORIGIN)
draw_transformation_rectangle_with_handles(data.origin, TRANSFORMATION_RECTANGLE_COLOR_ORIGIN)
}
_animation_rectangle_draw_active :: proc(animation: AnimationInterface) {
@ -88,8 +124,8 @@ _animation_rectangle_update :: proc(animation: ^AnimationInterface, animation_pr
}
}
_animation_rectangle_update_goto_next :: proc(animation: ^AnimationInterface, next_matrix: mat3) {
animation_reset :: proc(animation: ^AnimationInterface) {
animation.reset(animation)
}
animation_create_rectangle :: proc(rectangle: ^AnimationData_Rectangle) -> AnimationInterface {
@ -103,13 +139,3 @@ animation_create_rectangle :: proc(rectangle: ^AnimationData_Rectangle) -> Anima
draw_active = _animation_rectangle_draw_active,
}
}
AnimationInterface :: struct {
data: rawptr,
reset: proc(animation: ^AnimationInterface),
update_last: proc(animation: ^AnimationInterface, master_matrix: mat3),
update: proc(animation: ^AnimationInterface, animation_progress: f32),
next_matrix: proc(animation: ^AnimationInterface, next_matrix: mat3),
draw_idle: proc(animation: AnimationInterface),
draw_active: proc(animation: AnimationInterface),
}