Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
widget_skin_derive.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <cstdint>
5#include <vector>
6
7namespace pulp::view {
8
24
27struct SkinImage {
28 const uint8_t* pixels = nullptr;
29 int width = 0;
30 int height = 0;
31 bool valid() const { return pixels && width > 0 && height > 0; }
32};
33
36struct FaderSkin {
41 // Outline of the empty track (the lighter edge the captured art draws
42 // around the dark channel above the thumb). Recovered as the brightest
43 // low-saturation column pixel found on a track row, when it is meaningfully
44 // lighter than the track fill itself. Lets the skinned fader stroke the
45 // track so it doesn't read as a flat dark slab.
47 bool has_track = false;
48 bool has_fill = false;
49 bool has_thumb = false;
50 bool has_thumb_border = false;
51 bool has_track_border = false;
52 // Horizontal extents recovered from the captured art, in ASSET PIXELS
53 // (the importer divides by the asset scale to get logical px). The track
54 // is the thin low-saturation central column at a non-thumb row; the thumb
55 // is the widest opaque row (the silver slab).
56 float track_width_px = 0.0f;
57 float thumb_width_px = 0.0f;
58 bool has_track_width = false;
59 bool has_thumb_width = false;
60 // Height of the control housing (the tallest opaque run — the track + thumb),
61 // in ASSET PIXELS. The captured PNG bakes the value-stack text below the
62 // control, so the node's declared height spans control+labels; using it
63 // verbatim stretches the fader to ~2× its real height. This is the real
64 // control extent.
65 float housing_height_px = 0.0f;
66 bool has_housing_height = false;
67 // Normalized thumb position recovered from the capture (0 = bottom, 1 =
68 // top), i.e. where the design actually drew the thumb. An audio fader's
69 // value→position map is non-linear (a taper), so a linear (value-min)/(max-
70 // min) seed lands the thumb in the wrong place; seeding from the captured
71 // position reproduces the design.
72 float thumb_position = 0.0f;
73 bool has_thumb_position = false;
74 bool any() const { return has_track || has_fill || has_thumb || has_thumb_border; }
75};
76
80struct MeterSkin {
81 std::vector<canvas::Color> gradient; // low → high
83 bool has_background = false;
84 // Horizontal extent of the colored bar, in ASSET PIXELS (the importer
85 // divides by the asset scale to get logical px). Recovered from the bar's
86 // own vertical region so faint label glyphs below it don't widen it.
87 float bar_width_px = 0.0f;
88 bool has_bar_width = false;
89 // Height of the meter housing (the tallest opaque run — the dark channel +
90 // colored fill), in ASSET PIXELS. Like the fader, the captured PNG bakes
91 // the value-stack text below the control, so the declared height spans
92 // control+labels; using it verbatim stretches the meter to ~2× its real
93 // height (and doubles the absolute fill). This is the real control extent.
94 float housing_height_px = 0.0f;
95 bool has_housing_height = false;
96 // Fraction of the housing's cross-axis width occupied by the colored fill
97 // (colored-bar width / full housing width, 0..1). The captured meter recesses
98 // a narrow colored bar inside a wider dark housing slot; this ratio lets the
99 // skinned meter reproduce that inset instead of painting edge-to-edge. 1.0
100 // when the fill spans the full housing.
101 float bar_fill_ratio = 1.0f;
102 bool has_bar_fill_ratio = false;
103 // Normalized fill level recovered from the capture (0 = empty, 1 = full):
104 // the height of the contiguous saturated fill from the bottom of the bar.
105 // Like the fader, a meter's dB→position map is non-linear, so seed the
106 // initial level from where the capture actually filled to.
107 float fill_level = 0.0f;
108 bool has_fill_level = false;
109 bool valid() const { return gradient.size() >= 2; }
110};
111
116
120MeterSkin derive_meter_skin(const SkinImage& img, int stop_count = 5);
121
122} // namespace pulp::view
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
FaderSkin derive_fader_skin(const SkinImage &img)
Sample a captured fader PNG → FaderSkin.
MeterSkin derive_meter_skin(const SkinImage &img, int stop_count=5)
Sample a captured meter PNG → MeterSkin.
Definition canvas.hpp:52
Derived fader skin.
Definition widget_skin_derive.hpp:36
bool has_housing_height
Definition widget_skin_derive.hpp:66
canvas::Color track_color
Definition widget_skin_derive.hpp:37
bool has_thumb
Definition widget_skin_derive.hpp:49
canvas::Color fill_color
Definition widget_skin_derive.hpp:38
canvas::Color track_border_color
Definition widget_skin_derive.hpp:46
bool has_thumb_border
Definition widget_skin_derive.hpp:50
bool any() const
Definition widget_skin_derive.hpp:74
bool has_thumb_position
Definition widget_skin_derive.hpp:73
float track_width_px
Definition widget_skin_derive.hpp:56
float housing_height_px
Definition widget_skin_derive.hpp:65
canvas::Color thumb_border_color
Definition widget_skin_derive.hpp:40
bool has_track_border
Definition widget_skin_derive.hpp:51
float thumb_width_px
Definition widget_skin_derive.hpp:57
bool has_track_width
Definition widget_skin_derive.hpp:58
bool has_fill
Definition widget_skin_derive.hpp:48
bool has_track
Definition widget_skin_derive.hpp:47
bool has_thumb_width
Definition widget_skin_derive.hpp:59
float thumb_position
Definition widget_skin_derive.hpp:72
canvas::Color thumb_color
Definition widget_skin_derive.hpp:39
Derived meter skin: gradient stops ordered low→high (bottom→top), plus an optional background color.
Definition widget_skin_derive.hpp:80
canvas::Color background
Definition widget_skin_derive.hpp:82
bool has_background
Definition widget_skin_derive.hpp:83
bool has_bar_width
Definition widget_skin_derive.hpp:88
bool has_housing_height
Definition widget_skin_derive.hpp:95
std::vector< canvas::Color > gradient
Definition widget_skin_derive.hpp:81
float bar_fill_ratio
Definition widget_skin_derive.hpp:101
bool valid() const
Definition widget_skin_derive.hpp:109
float fill_level
Definition widget_skin_derive.hpp:107
bool has_fill_level
Definition widget_skin_derive.hpp:108
float bar_width_px
Definition widget_skin_derive.hpp:87
float housing_height_px
Definition widget_skin_derive.hpp:94
bool has_bar_fill_ratio
Definition widget_skin_derive.hpp:102
Derives native-widget skin styling from a captured design asset (a flat PNG exported by a design tool...
Definition widget_skin_derive.hpp:27
int width
Definition widget_skin_derive.hpp:29
bool valid() const
Definition widget_skin_derive.hpp:31
const uint8_t * pixels
Definition widget_skin_derive.hpp:28
int height
Definition widget_skin_derive.hpp:30