add animations (lerp only for now)
This commit is contained in:
@@ -1,22 +1,55 @@
|
||||
#pragma once
|
||||
#ifndef DANGERZONE_RENDER_ANIM_H
|
||||
#define DANGERZONE_RENDER_ANIM_H
|
||||
|
||||
#include <dangerzone/engine.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* animate a rectangle's position changing over time
|
||||
* => x0 -> x1, y0 -> y1, all else stays the same
|
||||
*
|
||||
* ONLY DOES ONE FRAME OF THE ANIMATION
|
||||
#define ANIM_MAX_TRACKS 64
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
float w;
|
||||
float h;
|
||||
} anim_rect_t;
|
||||
|
||||
/* payload is application data; the animation module does not interpret it. */
|
||||
typedef struct {
|
||||
uint32_t payload;
|
||||
anim_rect_t from;
|
||||
anim_rect_t to;
|
||||
} anim_track_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t payload;
|
||||
anim_rect_t rect;
|
||||
} anim_item_t;
|
||||
|
||||
typedef struct {
|
||||
anim_track_t tracks[ANIM_MAX_TRACKS];
|
||||
anim_item_t items[ANIM_MAX_TRACKS];
|
||||
size_t count;
|
||||
float elapsed;
|
||||
float duration;
|
||||
bool active;
|
||||
} anim_t;
|
||||
|
||||
void anim_init(anim_t *anim);
|
||||
|
||||
/*
|
||||
* Start tracks from their initial rectangles to their destination rectangles.
|
||||
* Returns false for invalid input or if count exceeds ANIM_MAX_TRACKS.
|
||||
* A zero-duration animation completes immediately.
|
||||
*/
|
||||
void
|
||||
anim_rect_pos(
|
||||
framebuffer_e framebuffer,
|
||||
uint32_t x0,
|
||||
uint32_t y0,
|
||||
uint32_t x1,
|
||||
uint32_t y1,
|
||||
uint32_t w,
|
||||
uint32_t h,
|
||||
uint32_t color
|
||||
);
|
||||
bool anim_start(anim_t *anim, const anim_track_t *tracks,
|
||||
size_t count, float duration);
|
||||
|
||||
/* Advance by nonnegative seconds. Returns true once the animation is finished. */
|
||||
bool anim_update(anim_t *anim, float dt);
|
||||
|
||||
bool anim_is_active(const anim_t *anim);
|
||||
size_t anim_count(const anim_t *anim);
|
||||
const anim_item_t *anim_items(const anim_t *anim);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user