ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
FilterRegistry.hpp
Go to the documentation of this file.
1#pragma once
2
23
24#include "Common.hpp"
25#include "CoreTypes.hpp"
26#include "Style.hpp"
27
28#include <functional>
29
30namespace ZenitUI
31{
32
36
37 class Layout;
38 class IRenderer;
39 struct UIContext;
40
49
51 enum class FilterParamType
52 {
53 Float,
54 Vec2,
55 Vec3,
56 Vec4,
57 Color
58 };
59
68 struct FilterParam
69 {
70 std::string uniform;
71 FilterParamType type{FilterParamType::Float};
72 int argIndex{0};
73 float fdef{0.0f};
74 Vec2 vdef{};
75 Color cdef{Colors::White};
76
77 FilterParam() = default;
78
79 FilterParam(std::string u, FilterParamType t, int ai, float fd)
80 : uniform(std::move(u)), type(t), argIndex(ai), fdef(fd) {}
81
82 FilterParam(std::string u, FilterParamType t, int ai, Color cd)
83 : uniform(std::move(u)), type(t), argIndex(ai), cdef(cd) {}
84 };
85
104
106 using FilterCustomFn = std::function<void(const FilterContext &)>;
107
113 {
114 std::string name;
115 std::string shader;
117 std::vector<FilterParam> params;
118 FilterCustomFn custom;
119 int downscale{1};
120 };
121
130 {
131 public:
134
136 void add(FilterDef def);
137
139 void addCustom(std::string name, FilterCustomFn fn);
140
142 const FilterDef *find(const std::string &name) const;
143
146
148 void clear();
149
151 void reset();
152
153 private:
154 std::unordered_map<std::string, FilterDef> defs_;
155 };
156
162 void applyFilter(const FilterDef &def, const FilterContext &ctx);
163
165} // namespace ZenitUI
Centralized standard library includes used throughout ZenitUI.
Small value types shared by the layout, rendering and input layers.
The Style / ComputedStyle pair and all style-related value types.
void clear()
Remove all registered filters, including builtins.
FilterRegistry()
Construct the registry and populate builtin filters.
void add(FilterDef def)
Register or replace a filter definition.
void registerBuiltins()
Register the builtin filters (blur, drop-shadow) if absent.
void reset()
Clear all filters and re-register only the builtins.
void addCustom(std::string name, FilterCustomFn fn)
Register a custom (shader-less) filter.
const FilterDef * find(const std::string &name) const
Look up a filter by name; returns nullptr if not found.
Abstract 2D rendering backend.
Definition UIContext.hpp:106
The base node type: tree, style, layout, input, scroll, render.
Definition Layout.hpp:154
std::function< void(const FilterContext &)> FilterCustomFn
Callback signature for FilterPattern::Custom filters.
Definition FilterRegistry.hpp:106
FilterParamType
Type of a filter parameter.
Definition FilterRegistry.hpp:52
void applyFilter(const FilterDef &def, const FilterContext &ctx)
Execute one filter against the given context.
FilterPattern
Execution pattern for a filter definition.
Definition FilterRegistry.hpp:43
@ Separable
Two shader passes (H then V), using the scratch target.
Definition FilterRegistry.hpp:45
@ Custom
Invoke the custom callback directly.
Definition FilterRegistry.hpp:47
@ Silhouette
Offset silhouette draw + original draw, for drop-shadows.
Definition FilterRegistry.hpp:46
@ SinglePass
One shader, one draw.
Definition FilterRegistry.hpp:44
8-bit-per-channel RGBA color, non-premultiplied.
Definition CoreTypes.hpp:78
Per-invocation state passed to applyFilter and to custom filters.
Definition FilterRegistry.hpp:91
TargetHandle scratch
Intermediate target for full-res separable/custom passes.
Definition FilterRegistry.hpp:96
Vec2 texSize
Backing texture dimensions of src in logical pixels.
Definition FilterRegistry.hpp:100
UIContext * ui
Owning UI context (assets, target pool, render stats).
Definition FilterRegistry.hpp:92
IRenderer * renderer
Active renderer backend.
Definition FilterRegistry.hpp:93
TargetHandle write_target
Destination off-screen target, or invalid when drawing to screen.
Definition FilterRegistry.hpp:97
const FilterRef * ref
Parsed CSS filter reference supplying parameter arguments.
Definition FilterRegistry.hpp:102
Layout * node
Filtered node currently being rendered.
Definition FilterRegistry.hpp:94
float opacity
Final compositing opacity (applied on the screen pass).
Definition FilterRegistry.hpp:101
Rect dst
Logical content sub-rectangle inside off-screen targets.
Definition FilterRegistry.hpp:99
Rect region
Screen-space destination rectangle.
Definition FilterRegistry.hpp:98
TargetHandle src
Source off-screen target for this pass.
Definition FilterRegistry.hpp:95
Complete description of one filter.
Definition FilterRegistry.hpp:113
int downscale
1, 2, or 4 (Separable filters only).
Definition FilterRegistry.hpp:119
One filter in the filters list of a Style.
Definition Style.hpp:679
Axis-aligned rectangle in screen coordinates.
Definition CoreTypes.hpp:46
Opaque handle to an off-screen render target.
Definition CoreTypes.hpp:155
Per-instance UI context: backends, theme, text engine, frame state, and routing.
Definition UIContext.hpp:725
2D vector with component-wise arithmetic.
Definition CoreTypes.hpp:25
3D vector.
Definition CoreTypes.hpp:34
4D vector with an implicit w = 1 default.
Definition CoreTypes.hpp:40