diff options
| author | KonAki <konaki@anokonaki.org> | 2026-10-12 13:54:29 +0800 |
|---|---|---|
| committer | KonAki <konaki@anokonaki.org> | 2026-10-12 13:54:29 +0800 |
| commit | e1bca003fa9ac46a1ce1b71d14d2a8feb8462dc6 (patch) | |
| tree | 0a5aaca4f6555dc7f2a426b0e315e4270fe39d41 /kon/konfx.h | |
| parent | d5cdd33e46c8646fe48f3a31f30dbd90c69e823c (diff) | |
add fx module: screen fade, flash, shake and tone
Diffstat (limited to 'kon/konfx.h')
| -rw-r--r-- | kon/konfx.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/kon/konfx.h b/kon/konfx.h new file mode 100644 index 0000000..0261b59 --- /dev/null +++ b/kon/konfx.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: MIT */ +/* + * konfx.h + * + * Copyright (c) 2026 KonAki + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef KONFX_H +#define KONFX_H + +#include "konsofren.h" +#include "kon2d.h" + +/*** definition ***/ + +/* the effects that go over a whole picture: a fade to a colour, a flash, a shake and a tone. they are done to the pixels after + the scene is drawn, so they work on anything, a map, a stage, a 3D view. start them with the functions below, call kon_screenfxUpdate + every frame and then kon_screenfxApply on the framebuffer when the scene is drawn. keep the struct around, it holds the state */ +typedef struct kon_screenfx { + kon_tween_t fade; + uint32_t fadeColor; + kon_tween_t flash; + uint32_t flashColor; + kon_tween_t tone[4]; /* red, green, blue, gray */ + float shakeX, shakeY, shakeHz, shakeTime, shakeDuration; +} kon_screenfx_t; + +void kon_screenfxInit(kon_screenfx_t *fx); + +/* fades to color (alpha is ignored) until it covers alpha of the picture, 1 is all of it, 0 is back to normal */ +void kon_screenfxFade(kon_screenfx_t *fx, uint32_t color, float alpha, float seconds, kon_ease_t ease); + +/* covers the picture with color at the strength of its alpha and lets it go in seconds */ +void kon_screenfxFlash(kon_screenfx_t *fx, uint32_t color, float seconds); + +/* shakes by up to powerX and powerY pixels, hz times a second, getting weaker until it stops after seconds */ +void kon_screenfxShake(kon_screenfx_t *fx, float powerX, float powerY, float hz, float seconds); + +/* r, g, b from -255 to 255 are added to every pixel, gray from 0 to 255 takes the colour out, 255 is black and white. + all zero is no change. the same as RPG Maker's screen tone */ +void kon_screenfxTone(kon_screenfx_t *fx, int r, int g, int b, int gray, float seconds, kon_ease_t ease); + +void kon_screenfxUpdate(kon_screenfx_t *fx, float dt); + +/* 1 while something is still changing, for a script that waits for it */ +int kon_screenfxBusy(const kon_screenfx_t *fx); + +/* how far the picture is shifted right now, for a game that would rather move its camera than the pixels */ +void kon_screenfxOffset(const kon_screenfx_t *fx, int *x, int *y); + +/* tone and shake, then flash and fade. two halves so a text box can be drawn between them and stay still and clear, + kon_screenfxApply is both for when it should all be covered */ +void kon_screenfxApplyScene(const kon_screenfx_t *fx, kon_framebuffer_t *fb); +void kon_screenfxApplyOverlay(const kon_screenfx_t *fx, kon_framebuffer_t *fb); +void kon_screenfxApply(const kon_screenfx_t *fx, kon_framebuffer_t *fb); + +#endif |
