From ccf049b4d5f5bbe4d15eedd2d83d5f81612cd71b Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Sun, 1 May 2022 12:04:55 -0700 Subject: [PATCH] Implement fade effects Implement EFFECT_FADEOUT, EFFECT_FADEIN, EFFECT_WHITEOUT and EFFECT_WHITEIN. I'm not aware of these being used in any game (fade effects seem to be implemented manually most of the time). --- src/effect.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/effect.c b/src/effect.c index aaeb59b..5190273 100644 --- a/src/effect.c +++ b/src/effect.c @@ -162,6 +162,32 @@ static struct { Texture new; } effect = {0}; +static void effect_fadeout(float rate) +{ + gfx_copy_bright(gfx_main_surface(), 0, 0, &effect.old, 0, 0, + effect.old.w, effect.old.h, (1.0f - rate) * 255); +} + +static void effect_fadein(float rate) +{ + gfx_copy_bright(gfx_main_surface(), 0, 0, &effect.new, 0, 0, + effect.new.w, effect.new.h, rate * 255); +} + +static void effect_whiteout(float rate) +{ + Texture *dst = gfx_main_surface(); + gfx_fill(dst, 0, 0, dst->w, dst->h, 255, 255, 255); + gfx_blend(dst, 0, 0, &effect.old, 0, 0, dst->w, dst->h, (1.0f - rate) * 255); +} + +static void effect_whitein(float rate) +{ + Texture *dst = gfx_main_surface(); + gfx_fill(dst, 0, 0, dst->w, dst->h, 255, 255, 255); + gfx_blend(dst, 0, 0, &effect.new, 0, 0, dst->w, dst->h, rate * 255); +} + static void effect_zoom_lr(float rate) { Texture *dst = gfx_main_surface(); @@ -180,8 +206,12 @@ static void effect_zoom_rl(float rate) typedef void (*effect_fun)(float rate); static effect_fun effect_functions[NR_EFFECTS] = { - [EFFECT_ZOOM_LR] = effect_zoom_lr, - [EFFECT_ZOOM_RL] = effect_zoom_rl, + [EFFECT_FADEOUT] = effect_fadeout, + [EFFECT_FADEIN] = effect_fadein, + [EFFECT_WHITEOUT] = effect_whiteout, + [EFFECT_WHITEIN] = effect_whitein, + [EFFECT_ZOOM_LR] = effect_zoom_lr, + [EFFECT_ZOOM_RL] = effect_zoom_rl, }; int sact_TRANS_Begin(int type)