diff options
Diffstat (limited to 'src/color.c')
-rw-r--r-- | src/color.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/color.c b/src/color.c index 67c3fb8..d1c918f 100644 --- a/src/color.c +++ b/src/color.c @@ -1,11 +1,36 @@ NAME(color); PARENT(trigger); +INIT { + super("init"); + this->tick = 0; +} + IMPL(enter) { - if (this->color_group) - setfgcolor(this->color.r / 255., this->color.g / 255., - this->color.b / 255.); - else - setbgcolor(this->color.r / 255., this->color.g / 255., - this->color.b / 255.); + 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; + } } |