MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ scale_form()

MAYAFLUX_API std::optional< Geometry::Form< float > > MayaFlux::Portal::Forma::scale_form ( const ScaleInputs & input,
const RectPlacementInputs & placement,
std::string & error )
nodiscard

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.

Definition at line 9 of file DragGeometry.cpp.

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
20 const auto triangles = Kinesis::triangulate_polygon(input.points, {});
21 if (triangles.empty()) {
22 error = "the outline does not form a valid region";
23 return std::nullopt;
24 }
25
26 const size_t capacity = triangles.size() * 3 * sizeof(Kakshya::MeshVertex);
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 },
46 rect_containment(*region));
47
48 Geometry::Form<float> form { std::move(fn), Graphics::PrimitiveTopology::TRIANGLE_LIST, capacity };
50 Kinesis::axis_fraction(*region, 0.F, input.horizontal));
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.
auto drag_with(std::function< T(glm::vec2)> project, IO::MouseButtons btn=IO::MouseButtons::Left)
Produce a Form::wire that registers a drag writing a projected cursor position.
void write_verts(std::vector< uint8_t > &out, const std::vector< V > &verts)
Write a vertex array into a GeometryFn output buffer.
Definition Geometry.hpp:35
std::optional< Kinesis::AABB2D > region_of(const RectPlacementInputs &placement, std::string &error)
The surface region a rect placement covers.
GeometryFn< T > geometry_with_containment(std::function< void(const T &, std::vector< uint8_t > &)> draw, Containment region)
A geometry function that draws a value and claims a fixed containment.
Containment rect_containment(Kinesis::AABB2D region)
The rectangle itself as bounds, with no containment test.
Vertex type for indexed triangle mesh primitives (TRIANGLE_LIST topology).

References MayaFlux::Portal::Forma::ScaleInputs::color, geometry_with_containment(), MayaFlux::Portal::Forma::ScaleInputs::horizontal, MayaFlux::Portal::Forma::ScaleInputs::points, region_of(), MayaFlux::Kakshya::to_mesh_vertices(), MayaFlux::Kinesis::triangulate_polygon(), and MayaFlux::Portal::Forma::Geometry::write_verts().

Referenced by expose_scale().

Here is the call graph for this function:
Here is the caller graph for this function: