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
|
NAME(color);
PARENT(trigger);
INIT {
super("init");
this->tick = 0;
}
IMPL(enter) {
if (this->fade_in == 0) {
const auto setfn = this->color_group ? setfgcolor : setbgcolor;
setfn(this->color.r, this->color.g, this->color.b);
} else {
const auto getfn = this->color_group ? getfgcolor : getbgcolor;
getfn(&this->initial_color.r, &this->initial_color.g,
&this->initial_color.b);
this->tick = 1;
}
}
f32 mix(f32 a, f32 b, f32 x) {
return a * x + b * (1. - x);
}
UPDATE_POST {
if (this->tick) {
const auto setfn = this->color_group ? setfgcolor : setbgcolor;
const auto x = this->tick / (f32)this->fade_in;
setfn(mix(this->color.r, this->initial_color.r, x),
mix(this->color.g, this->initial_color.g, x),
mix(this->color.b, this->initial_color.b, x));
this->tick += 1;
if (this->tick > this->fade_in)
this->tick = 0;
}
}
|