forked from FelixKratz/SketchyBar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation.h
129 lines (109 loc) · 4.23 KB
/
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#pragma once
#include <CoreVideo/CoreVideo.h>
#include "misc/helpers.h"
extern struct bar_manager g_bar_manager;
#define ANIMATE(f, o, p, t) \
{\
if (g_bar_manager.animator.duration > 0) { \
animator_cancel_locked(&g_bar_manager.animator, (void*)o, (bool (*)(void*, int))&f); \
struct animation* animation = animation_create(); \
animation_setup(animation, \
(void*)o, \
(bool (*)(void*, int))&f, \
p, \
t, \
g_bar_manager.animator.duration, \
g_bar_manager.animator.interp_function ); \
animator_add(&g_bar_manager.animator, animation); \
} else { \
needs_refresh = animator_cancel(&g_bar_manager.animator, (void*)o, (bool (*)(void*, int))&f); \
needs_refresh |= f(o, t); \
} \
}
#define ANIMATE_FLOAT(f, o, p, t) \
{\
if (g_bar_manager.animator.duration > 0) { \
animator_cancel_locked(&g_bar_manager.animator, (void*)o, (bool (*)(void*, int))&f); \
struct animation* animation = animation_create(); \
float initial_value = p; \
float final_value = t; \
animation_setup(animation, \
(void*)o, \
(bool (*)(void*, int))&f, \
*(int*)&initial_value, \
*(int*)&final_value, \
g_bar_manager.animator.duration, \
g_bar_manager.animator.interp_function ); \
animation->as_float = true; \
animator_add(&g_bar_manager.animator, animation); \
} else { \
needs_refresh = animator_cancel(&g_bar_manager.animator, (void*)o, (bool (*)(void*, int))&f); \
needs_refresh |= f(o, t); \
} \
}
#define ANIMATE_BYTES(f, o, p, t) \
{\
if (g_bar_manager.animator.duration > 0) { \
animator_cancel_locked(&g_bar_manager.animator, (void*)o, (bool (*)(void*, int))&f); \
struct animation* animation = animation_create(); \
animation_setup(animation, \
(void*)o, \
(bool (*)(void*, int))&f, \
p, \
t, \
g_bar_manager.animator.duration, \
g_bar_manager.animator.interp_function ); \
animation->separate_bytes = true; \
animator_add(&g_bar_manager.animator, animation); \
} else { \
needs_refresh = animator_cancel(&g_bar_manager.animator, (void*)o, (bool (*)(void*, int))&f); \
needs_refresh |= f(o, t); \
} \
}
#define ANIMATOR_FUNCTION(name) bool name(void* target, int value);
typedef ANIMATOR_FUNCTION(animator_function);
#define ANIMATION_FUNCTION(name) double name(double x);
typedef ANIMATION_FUNCTION(animation_function);
#define INTERP_FUNCTION_LINEAR 'l'
#define INTERP_FUNCTION_QUADRATIC 'q'
#define INTERP_FUNCTION_SIN 's'
#define INTERP_FUNCTION_TANH 't'
#define INTERP_FUNCTION_CIRC 'c'
#define INTERP_FUNCTION_BOUNCE 'b'
#define INTERP_FUNCTION_EXP 'e'
#define INTERP_FUNCTION_OVERSHOOT 'o'
struct animation {
bool separate_bytes;
bool as_float;
bool locked;
bool finished;
bool waiting;
uint64_t initial_time;
double duration;
int initial_value;
int final_value;
animation_function* interp_function;
void* target;
animator_function* update_function;
struct animation* next;
struct animation* previous;
};
struct animation* animation_create();
void animation_setup(struct animation* animation, void* target, animator_function* update_function, int initial_value, int final_value, uint32_t duration, char interp_function);
struct animator {
CVDisplayLinkRef display_link;
double clock;
uint32_t interp_function;
uint32_t duration;
struct animation** animations;
uint32_t animation_count;
};
void animator_init(struct animator* animator);
void animator_add(struct animator* animator, struct animation* animation);
bool animator_cancel(struct animator* animator, void* target, animator_function* function);
void animator_cancel_locked(struct animator* animator, void* target, animator_function* function);
bool animator_update(struct animator* animator, uint64_t time);
void animator_lock(struct animator* animator);
void animator_destroy(struct animator* animator);
void animator_renew_display_link(struct animator* animator);
void animator_destroy_display_link(struct animator* animator);