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

◆ level_meter()

MAYAFLUX_API Form< float > MayaFlux::Portal::Forma::Geometry::level_meter ( Kinesis::AABB2D  bounds,
bool  horizontal = true,
glm::vec3  fill_color = glm::vec3(0.2F, 0.7F, 0.3F),
glm::vec3  track_color = glm::vec3(0.15F),
const std::function< glm::vec2()> &  live_offset = {} 
)

Geometry function for a level meter in NDC space.

No interaction. Drive from a node via bridge().at(el.state).bind(node).

Parameters
boundsFull extent of the meter in NDC.
horizontalTrue for left-to-right fill, false for bottom-to-top.
fill_colorColor of the active (filled) portion.
track_colorColor of the inactive remainder.
live_offsetOptional. Current translation of the drawn meter.

Definition at line 320 of file FormFactory.cpp.

326{
327 GeometryFn<float> fn = [bounds, horizontal, fill_color, track_color, live_offset](
328 float v, std::vector<uint8_t>& out, Element& el) {
329 const glm::vec2 shift = live_offset ? live_offset() : glm::vec2(0.F);
330 const Kinesis::AABB2D live = bounds.translated(shift);
331
332 const float t = std::clamp(v, 0.F, 1.F);
333
334 Kinesis::AABB2D fill {}, remainder {};
335 if (horizontal) {
336 const float split = live.min.x + t * live.width();
337 fill = { .min = live.min, .max = { split, live.max.y } };
338 remainder = { .min = { split, live.min.y }, .max = live.max };
339 } else {
340 const float split = live.min.y + t * live.height();
341 fill = { .min = live.min, .max = { live.max.x, split } };
342 remainder = { .min = { live.min.x, split }, .max = live.max };
343 }
344
345 auto verts = Kakshya::to_mesh_vertices(Kinesis::filled_rect(fill, fill_color));
346 auto rest = Kakshya::to_mesh_vertices(Kinesis::filled_rect(remainder, track_color));
347 verts.insert(verts.end(), rest.begin(), rest.end());
348
349 write_verts(out, verts);
350
351 el.bounds_hint = live;
352 el.contains = {};
353 };
354
355 return { std::move(fn),
356 Graphics::PrimitiveTopology::TRIANGLE_STRIP,
357 static_cast<size_t>(8) * sizeof(Kakshya::MeshVertex) };
358}
std::vector< float > * out
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 MayaFlux::Kinesis::AABB2D::contains(), MayaFlux::Kinesis::filled_rect(), MayaFlux::Kinesis::AABB2D::height(), MayaFlux::Kinesis::AABB2D::max, MayaFlux::Kinesis::AABB2D::min, out, MayaFlux::Kakshya::to_mesh_vertices(), MayaFlux::Kinesis::AABB2D::translated(), MayaFlux::Portal::Graphics::TRIANGLE_STRIP, MayaFlux::Kinesis::AABB2D::width(), and write_verts().

+ Here is the call graph for this function: