/* 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" #ifdef __cplusplus extern "C" { #endif /*** 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); /* the RPG Maker screen commands the way mzscript writes them: 221 fadeout, 222 fadein, 223 tint, 224 flash, 225 shake. returns -1 when the code is not one of those, 0 when it is done, 1 when the script is meant to wait. that wait is over when kon_screenfxBusy says 0, so the host function returns 1 and you call kon_scriptResume then */ int kon_screenfxHost(kon_screenfx_t *fx, int code, int b, int c, int d, const char *text); #ifdef __cplusplus } #endif #endif