Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
sdf_effects.hpp
Go to the documentation of this file.
1#pragma once
2
3// SDF text effects: `glow`, `shadow`, `outline`, `bevel`. These mirror
4// the uniforms exposed by `core/canvas/shaders/sdf_text_effects.sksl`
5// so host code and SkSL shader share a single source of truth for the
6// effect parameters.
7
8#include <array>
9#include <cstdint>
10
11namespace pulp::canvas {
12
13enum class SdfEffect : std::uint8_t {
14 None = 0,
15 Outline = 1u << 0,
16 Glow = 1u << 1,
17 Shadow = 1u << 2,
18 Bevel = 1u << 3,
19};
20
21inline std::uint8_t operator|(SdfEffect a, SdfEffect b) {
22 return static_cast<std::uint8_t>(a) | static_cast<std::uint8_t>(b);
23}
24inline bool has_effect(std::uint8_t mask, SdfEffect e) {
25 return (mask & static_cast<std::uint8_t>(e)) != 0;
26}
27
29 // Outline
30 float outline_width = 0.0f; // pixels
31 std::array<float, 4> outline_color{0, 0, 0, 1};
32
33 // Glow
34 float glow_radius = 0.0f; // pixels of falloff
35 std::array<float, 4> glow_color{1, 1, 1, 1};
36
37 // Shadow
38 float shadow_offset_x = 0.0f;
39 float shadow_offset_y = 0.0f;
40 float shadow_softness = 0.0f;
41 std::array<float, 4> shadow_color{0, 0, 0, 0.5f};
42
43 // Bevel — normalized light direction in image space.
44 float bevel_light_x = 0.7071f;
45 float bevel_light_y = -0.7071f;
46 float bevel_mix = 0.0f; // 0 = off, 1 = full
47
48 // Active effect mask (bitset of SdfEffect values).
49 std::uint8_t active = 0;
50};
51
52// Design-token friendly presets. Matches the style-guide tiers in the
53// Pulp design system: subtle (UI accents), bold (splash text),
54// neon (callouts), pressed (tactile buttons).
57 p.active = static_cast<std::uint8_t>(SdfEffect::Shadow);
58 p.shadow_offset_x = 0.0f;
59 p.shadow_offset_y = 1.0f;
60 p.shadow_softness = 0.5f;
61 p.shadow_color = {0, 0, 0, 0.25f};
62 return p;
63}
64
65inline SdfEffectParams preset_outline(float width = 2.0f) {
67 p.active = static_cast<std::uint8_t>(SdfEffect::Outline);
68 p.outline_width = width;
69 p.outline_color = {0, 0, 0, 1};
70 return p;
71}
72
73inline SdfEffectParams preset_glow(float radius = 6.0f,
74 std::array<float, 4> color = {0.3f, 0.6f, 1.0f, 1.0f}) {
75 SdfEffectParams p;
76 p.active = static_cast<std::uint8_t>(SdfEffect::Glow);
77 p.glow_radius = radius;
78 p.glow_color = color;
79 return p;
80}
81
84 p.active = static_cast<std::uint8_t>(SdfEffect::Bevel);
85 p.bevel_mix = 0.5f;
86 p.bevel_light_x = 0.0f;
87 p.bevel_light_y = 1.0f; // light from below = pressed look
88 return p;
89}
90
91} // namespace pulp::canvas
Definition affine_transform.hpp:24
std::uint8_t operator|(SdfEffect a, SdfEffect b)
Definition sdf_effects.hpp:21
bool has_effect(std::uint8_t mask, SdfEffect e)
Definition sdf_effects.hpp:24
SdfEffectParams preset_pressed_bevel()
Definition sdf_effects.hpp:82
SdfEffectParams preset_subtle_shadow()
Definition sdf_effects.hpp:55
SdfEffectParams preset_glow(float radius=6.0f, std::array< float, 4 > color={0.3f, 0.6f, 1.0f, 1.0f})
Definition sdf_effects.hpp:73
SdfEffect
Definition sdf_effects.hpp:13
@ Bevel
Definition sdf_effects.hpp:18
@ Shadow
Definition sdf_effects.hpp:17
@ Outline
Definition sdf_effects.hpp:15
@ Glow
Definition sdf_effects.hpp:16
@ None
Definition font_options.hpp:73
SdfEffectParams preset_outline(float width=2.0f)
Definition sdf_effects.hpp:65
Definition sdf_effects.hpp:28
float bevel_light_y
Definition sdf_effects.hpp:45
float bevel_light_x
Definition sdf_effects.hpp:44
float shadow_offset_y
Definition sdf_effects.hpp:39
float outline_width
Definition sdf_effects.hpp:30
std::array< float, 4 > glow_color
Definition sdf_effects.hpp:35
float bevel_mix
Definition sdf_effects.hpp:46
float shadow_softness
Definition sdf_effects.hpp:40
std::array< float, 4 > shadow_color
Definition sdf_effects.hpp:41
float glow_radius
Definition sdf_effects.hpp:34
std::array< float, 4 > outline_color
Definition sdf_effects.hpp:31
float shadow_offset_x
Definition sdf_effects.hpp:38
std::uint8_t active
Definition sdf_effects.hpp:49