forked from sam-itt/sofis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base-animation.h
68 lines (57 loc) · 1.71 KB
/
base-animation.h
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
60
61
62
63
64
65
66
67
68
/*
* SPDX-FileCopyrightText: 2021 Samuel Cuella <samuel.cuella@gmail.com>
*
* This file is part of SoFIS - an open source EFIS
*
* SPDX-License-Identifier: GPL-2.0-only
*/
#ifndef BASE_ANIMATION_H
#define BASE_ANIMATION_H
#include <stddef.h>
#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>
#define DEFAULT_DURATION 1000 /*milliseconds*/
/* BaseAnimation can be extended in the future (if needed)
* by making base_animation_loop virtual there is no need
* for that at the moment and doing it would add an additional
* indirection each frame.
*/
typedef enum{
TYPE_INT8,
TYPE_UINT8,
TYPE_INT16,
TYPE_UINT16,
TYPE_INT32,
TYPE_UINT32,
TYPE_FLOAT,
TYPE_DOUBLE,
N_TYPES
}ValueType;
typedef struct{
/* targets, floats only now
* will be generic using a void**
* and a type enum to handle all
* numeric types.
* */
float **targets;
ValueType targets_type;
size_t ntargets;
/*values*/
float start;
float end;
/*milliseconds*/
float duration;
float time_progress;
bool finished;
bool last_value_reached;
size_t refcount; /*must be the same type as ntargets*/
}BaseAnimation;
BaseAnimation *base_animation_new(ValueType type, size_t ntargets, ...);
BaseAnimation *base_animation_init(BaseAnimation *self, ValueType type, size_t ntargets, ...);
BaseAnimation *base_animation_vainit(BaseAnimation *self, ValueType type, size_t ntargets, va_list ap);
void base_animation_unref(BaseAnimation *self);
void base_animation_ref(BaseAnimation *self);
void base_animation_start(BaseAnimation *self, float from, float to, float duration);
bool base_animation_loop(BaseAnimation *self, uint32_t dt);
#endif /* BASE_ANIMATION_H */