aboutsummaryrefslogtreecommitdiff
path: root/src/animation.h
blob: 3064d1bfafe9d2478c884c0c462016bbe6a30d10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * animation.h
 *
 * Created by buzzert <buzzert@buzzert.net> 2019-01-20
 */

#pragma once
#include <stdbool.h>
#include <time.h>

typedef double anim_time_interval_t;

struct animation_t;
typedef void(*AnimationCompletion)(struct animation_t *anim, void *context);

typedef enum {
    _EmptyAnimationType,
    ACursorAnimation,
    ALogoAnimation,
} AnimationType;

typedef struct {
    AnimationType type;

    bool   cursor_animating;
    double cursor_fade_direction;
} CursorAnimation;

typedef struct {
    AnimationType type;

    bool                 direction; // false: in, true: out
} LogoAnimation;

typedef union {
    AnimationType type;

    CursorAnimation cursor_anim;
    LogoAnimation   logo_anim;
} Animation;

typedef struct {
    bool                 completed;
    anim_time_interval_t start_time;

    AnimationCompletion  completion_func;
    void                *completion_func_context;

    Animation anim;
} animation_t;

// Convenience: returns current time as anim_time_interval_t
anim_time_interval_t anim_now();

// Easing functions
double anim_qubic_ease_out(double p);
double anim_quad_ease_out(double p);