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.
+ font
example : "<font name=\"MyBold\" size=48>Big bold text</font>"
example : "<font size=32>Larger text, same face</font>"
name : (optional string) - Name of a font previously loaded with `cf_make_font` (or `font` as an alias key). Omit to keep the current face and only change size.
size : (optional number) - Pixel size to use for this span. A line's height, baseline, and measured
size (see `cf_text_size`) grow to fit the largest size on that line, so large spans stay inside
the reported bounds and successive lines don't collide. Animated effects (wave/shake) are not
counted in measurement. Note: vertical text (`cf_push_text_vertical_layout`) uses base-face columns.
<color=#2c5ee8 metadata=\"Just some string.\">blue text</color>,
where the color markup contains a parameter called metadata and a string value of "Just some string.".
For bold/italic style tags, load the corresponding font faces and map them with cf_text_effect_set_font (bold/italic are separate fonts, not runtime styles). Example:
cf_make_font("fonts/Calibri-Bold.ttf", "Calibri Bold");
cf_text_effect_set_font("b", "Calibri Bold");
cf_draw_text("Hello <b>bold</b> world", pos, -1);
Related Pages¶
CF_TextEffect
CF_TextEffectFn
cf_text_effect_get_string
cf_text_effect_set_font
cf_text_effect_get_number
cf_text_effect_get_color