MayaFlux 0.5.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) 
)

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.

Definition at line 273 of file FormFactory.cpp.

278{
279 GeometryFn<float> fn = [bounds, horizontal, fill_color, track_color](
280 float v, std::vector<uint8_t>& out, Element& el) {
281 const float t = std::clamp(v, 0.F, 1.F);
282
283 Kinesis::AABB2D fill {}, remainder {};
284 if (horizontal) {
285 const float split = bounds.min.x + t * bounds.width();
286 fill = { .min = bounds.min, .max = { split, bounds.max.y } };
287 remainder = { .min = { split, bounds.min.y }, .max = bounds.max };
288 } else {
289 const float split = bounds.min.y + t * bounds.height();
290 fill = { .min = bounds.min, .max = { bounds.max.x, split } };
291 remainder = { .min = { bounds.min.x, split }, .max = bounds.max };
292 }
293
294 auto verts = Kakshya::to_mesh_vertices(Kinesis::filled_rect(fill, fill_color));
295 auto rest = Kakshya::to_mesh_vertices(Kinesis::filled_rect(remainder, track_color));
296 verts.insert(verts.end(), rest.begin(), rest.end());
297
298 write_verts(out, verts);
299
300 el.bounds_hint = bounds;
301 el.contains = {};
302 };
303
304 return { std::move(fn),
305 Graphics::PrimitiveTopology::TRIANGLE_STRIP,
306 static_cast<size_t>(8) * sizeof(Kakshya::MeshVertex) };
307}
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:64
float height() const noexcept
Definition Bounds.hpp:38
bool contains(glm::vec2 p) const noexcept
Definition Bounds.hpp:25
float width() const noexcept
Definition Bounds.hpp:37
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:21
A bounded, renderable region on a window surface.
Definition Element.hpp:58

References MayaFlux::Kinesis::AABB2D::contains(), MayaFlux::Kinesis::filled_rect(), MayaFlux::Kinesis::AABB2D::height(), MayaFlux::Kinesis::AABB2D::max, MayaFlux::Kinesis::AABB2D::min, MayaFlux::Kakshya::to_mesh_vertices(), MayaFlux::Portal::Graphics::TRIANGLE_STRIP, MayaFlux::Kinesis::AABB2D::width(), and write_verts().

+ Here is the call graph for this function: