cf_text_effect_register¶
Category: text
GitHub: cute_draw.h
Registers a custom text effect.
Parameters | Description |
---|---|
name | A unique name for your text effect. |
fn | The CF_TextEffectFn function you must implement to perform the custom effect. |
Code Example¶
Internally the text shake effect is implemented something like this.
// Given a string like this:
"Some <shake freq=50 x=2.5 y=1>shaking text</shake> drawing!"
static bool s_text_fx_shake(TextEffect effect)
{
double freq = effect->get_number("freq", 35);
int seed = (int)(effect->elapsed freq);
float x = (float)effect->get_number("x", 2);
float y = (float)effect->get_number("y", 2);
CF_Rnd rnd = cf_rnd_seed(seed);
v2 offset = V2(rnd_next_range(rnd, -x, y), rnd_next_range(rnd, -x, y));
effect->q0 += offset;
effect->q1 += offset;
return true;
}
// Register it like so:
cf_text_effect_register("shake", s_text_fx_shake);
Remarks¶
The name
of the text effect will be used within the string text codes. For example, for the "shake" effect in the above
example, the text code + color
example : "Here's some <color=#2c5ee8>blue text</color>."
: default (white) - The color to render text with.
+ shake
example : "<shake freq=30 x=3 y=3>This text is all shaky.</shake>"
example : "<shake y=20>Shake this text with default values, but override for a big height.</shake>"
freq : default (35) - Number of times per second to shake.
x : default (2) - Max +/- distance to shake on x-axis.
y : default (2) - Max +/- distance to shake on y-axis.
+ fade
example : "<fade speed=10 span=3>Fading some text like a ghost~</fade>"
example : "<fade>Fading some text like a ghost~</fade>"
speed : default (2) - Number of times per second to find in and then out.
span : default (5) - Number of characters long for the fade to loop.
+ wave
example : "<wave>Wobbly wave text.</wave>"
speed : default (5) - Number of times per second to bob up and down.
span : default (10) - Number of characters long for the wave to loop.
height : default (5) - How many characters high the wave will go.
+ strike
example : "<strike>Strikethrough</strike>"
example : "<strike=10>Thick Strikethrough</strike>"
: default (font_height / 20) - The thickness of the strike line.
<color=#2c5ee8 metadata=\"Just some string.\">blue text</color>
,
where the color
markup contains a parameter called metadata
and a strinf value of "Just some string."
.
Related Pages¶
CF_TextEffect
CF_TextEffectFn
cf_text_effect_get_string
cf_text_effect_get_number
cf_text_effect_get_color