Add a text effect

Writes a line or several over its input in a chosen family, weight, size
and colour, optionally on a box filled with a colour or with a picture
from disk. Like the blur and the overlay it needs no sources of its own,
so it can lead a chain; given sources it fills the canvas from a randomly
chosen one first.

Two param types rather than effect-specific branches in the front-ends:
Text, free-form text the user types, and Color, a colour written
"#rrggbb". Both travel as strings, so the interface gets an entry and a
colour button, the command line gets a flag (a colour that does not parse
is refused there rather than drawn as black), and a project keeps them
across a round trip.

The glyphs come from Pango, which draws through Cairo without a display,
so the core stays headless — but they are the one thing here that is not
byte-identical across machines: a machine without the chosen family
renders the substitute its fontconfig picks. Everything the effect is
handed, the rng included, is used exactly as every other effect uses it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Si
2026-09-18 20:31:24 +02:00
co-authored by Claude Opus 5
parent c34bc426fc
commit 1d0343b90a
12 changed files with 725 additions and 6 deletions
+20 -1
View File
@@ -1,5 +1,6 @@
#pragma once
#include <cstdint>
#include <map>
#include <string>
#include <variant>
@@ -10,7 +11,7 @@ namespace effector {
// Declarative description of one effect knob. The GUI turns these into widgets
// and the CLI turns them into flags, so neither knows about any effect.
struct ParamSpec {
enum class Type { Int, Double, Bool, Choice, Path };
enum class Type { Int, Double, Bool, Choice, Path, Text, Color };
Type type = Type::Int;
std::string key;
@@ -39,6 +40,14 @@ struct ParamSpec {
// flag taking any string on the command line, written relative to the
// project folder so that a folder still opens after it is moved.
static ParamSpec makePath(std::string key, std::string label, std::string help = {});
// Free-form text the user types: an entry in the interface, a flag taking
// any string on the command line.
static ParamSpec makeText(std::string key, std::string label, std::string defaultText,
std::string help = {});
// A colour written "#rrggbb": a colour button in the interface, the same
// spelling as a flag value.
static ParamSpec makeColor(std::string key, std::string label, std::string defaultColor,
std::string help = {});
};
using ParamValue = std::variant<long, double, bool, std::string>;
@@ -52,4 +61,14 @@ std::string paramChoice(const ParamValues& values, const std::string& key,
std::string paramText(const ParamValues& values, const std::string& key,
const std::string& fallback);
// Reads "#rgb" or "#rrggbb" (the leading hash optional) into three bytes.
// Returns false and leaves `rgb` untouched for anything else, so a malformed
// value falls back to the default rather than painting an arbitrary colour.
bool parseColor(const std::string& text, std::uint8_t rgb[3]);
std::string formatColor(const std::uint8_t rgb[3]);
// The colour of a param, or `fallback` when the value does not parse.
void paramColor(const ParamValues& values, const std::string& key, const std::string& fallback,
std::uint8_t rgb[3]);
} // namespace effector