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

◆ drawable_canvas()

MAYAFLUX_API Form< std::vector< float > > MayaFlux::Portal::Forma::Geometry::drawable_canvas ( Kinesis::AABB2D  bounds,
glm::vec3  color = glm::vec3(0.8F),
float  thickness = 1.5F,
const std::function< glm::vec2()> &  live_offset = {},
size_t  samples = 0 
)

Geometry function for a drawable curve canvas in NDC space.

Renders the sample vector as a LINE_LIST polyline. Each adjacent sample pair becomes one segment. The hit region covers the full canvas bounds.

Parameters
boundsCanvas extent in NDC.
colorLine color.
thicknessLineVertex thickness value.
live_offsetOptional. Current translation of the drawn canvas - geometry only. paint_over()/wire_canvas_drag() do their own inline cursor math, not routed through Kinesis::Projection, and are not offset-aware here.
samplesSample count the canvas will hold. Sizes the buffer so the first draw does not reallocate. Zero keeps the default capacity.

Definition at line 386 of file FormFactory.cpp.

392{
393 GeometryFn<std::vector<float>> fn = [bounds, color, thickness, live_offset](
394 const std::vector<float>& v, std::vector<uint8_t>& out, Element& el) {
395 const glm::vec2 shift = live_offset ? live_offset() : glm::vec2(0.F);
396 const Kinesis::AABB2D live = bounds.translated(shift);
397
398 if (v.size() < 2) {
399 out.clear();
400 el.bounds_hint = live;
401 el.contains = Kinesis::polygon_bounds(std::span<const glm::vec2> {
402 std::array<glm::vec2, 4> {
403 live.min,
404 glm::vec2(live.max.x, live.min.y),
405 live.max,
406 glm::vec2(live.min.x, live.max.y) } });
407 return;
408 }
409
410 const auto n = v.size();
411 const float x_step = live.width() / static_cast<float>(n - 1);
412
413 std::vector<Kakshya::LineVertex> verts;
414 verts.reserve((n - 1) * 2);
415
416 for (size_t i = 0; i + 1 < n; ++i) {
417 const float xa = live.min.x + static_cast<float>(i) * x_step;
418 const float xb = live.min.x + static_cast<float>(i + 1) * x_step;
419 const float ya = live.min.y + std::clamp(v[i], 0.F, 1.F) * live.height();
420 const float yb = live.min.y + std::clamp(v[i + 1], 0.F, 1.F) * live.height();
421
422 verts.push_back({ .position = { xa, ya, 0.F }, .color = color, .thickness = thickness });
423 verts.push_back({ .position = { xb, yb, 0.F }, .color = color, .thickness = thickness });
424 }
425
426 write_verts(out, verts);
427
428 el.bounds_hint = live;
429 el.contains = Kinesis::polygon_bounds(std::span<const glm::vec2> {
430 std::array<glm::vec2, 4> {
431 live.min,
432 glm::vec2(live.max.x, live.min.y),
433 live.max,
434 glm::vec2(live.min.x, live.max.y) } });
435 };
436
437 Form<std::vector<float>> form { std::move(fn) };
438 form.topology = Graphics::PrimitiveTopology::LINE_LIST;
439 if (samples > 1)
440 form.capacity = (samples - 1) * 2 * sizeof(Kakshya::LineVertex);
441 form.wire = paint_over(bounds);
442 return form;
443}
glm::vec3 color
Definition Decoder.cpp:97
std::vector< float > * out
auto paint_over(Kinesis::AABB2D bounds)
Produce a Form::wire that registers canvas painting over bounds.
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::function< void(T value, std::vector< uint8_t > &out_bytes, Element &element)> GeometryFn
Geometry function signature.
Definition Mapped.hpp:71
float height() const noexcept
Definition Bounds.hpp:80
bool contains(glm::vec2 p) const noexcept
Definition Bounds.hpp:67
AABB2D translated(glm::vec2 offset) const noexcept
Definition Bounds.hpp:84
float width() const noexcept
Definition Bounds.hpp:79
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:63
A bounded, renderable region on a window surface.
Definition Element.hpp:61

References color, MayaFlux::Kinesis::AABB2D::contains(), MayaFlux::Kinesis::AABB2D::height(), MayaFlux::Portal::Graphics::LINE_LIST, MayaFlux::Kinesis::AABB2D::max, MayaFlux::Kinesis::AABB2D::min, out, paint_over(), MayaFlux::Kinesis::polygon_bounds(), MayaFlux::Portal::Forma::Geometry::Form< T >::topology, MayaFlux::Kinesis::AABB2D::translated(), MayaFlux::Kinesis::AABB2D::width(), and write_verts().

+ Here is the call graph for this function: