A float state Form: an outline scaled along one axis by the state.
The outline is filled. The hit region is the placement's rect, so a track stays clickable at zero, and a drag along the scaled axis writes the fraction of the rect under the pointer.
11{
12 if (input.
points.size() < 3) {
13 error = "points needs at least three x y pairs";
14 return std::nullopt;
15 }
16 const auto region =
region_of(placement, error);
17 if (!region)
18 return std::nullopt;
19
21 if (triangles.empty()) {
22 error = "the outline does not form a valid region";
23 return std::nullopt;
24 }
25
28 [unit = input.
points, triangles, region = *region, color = input.
color,
29 horizontal = input.
horizontal](
const float& value, std::vector<uint8_t>& out) {
30 const float scale = std::clamp(value, 0.F, 1.F);
31 std::vector<Kakshya::Vertex> verts;
32 verts.reserve(triangles.size() * 3);
33 for (const auto& triangle : triangles) {
34 for (const uint32_t k : triangle) {
35 glm::vec2 point = unit[k];
36 (horizontal ? point.x : point.y) *= scale;
37 const glm::vec2 ndc = region.point_at(point);
38 verts.push_back(Kakshya::Vertex {
39 .position = { ndc.x, ndc.y, 0.F },
40 .color = color,
41 });
42 }
43 }
45 },
47
51 return form;
52}
std::vector< MeshVertex > to_mesh_vertices(std::span< const Vertex > vertices, glm::vec2 weight_range)
Batch-project raw Vertex vector to MeshVertex.
std::vector< std::array< uint32_t, 3 > > triangulate_polygon(std::span< const glm::vec2 > pts, std::span< const uint32_t > hole_starts)
Ear-clipping triangulation of a polygon with optional holes, as index triples.
std::function< float(glm::vec2)> axis_fraction(AABB2D bounds, float handle_extent=0.F, bool horizontal=true, const std::function< glm::vec2()> &live_offset={}) noexcept
Fraction along one axis of bounds, inverse to fader placement.
Vertex type for indexed triangle mesh primitives (TRIANGLE_LIST topology).