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

◆ level_meter()

MAYAFLUX_API GeometryFn< 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 234 of file Geometry.cpp.

239{
240 return [bounds, horizontal, fill_color, track_color](
241 float v, std::vector<uint8_t>& out, Element& el) {
242 const float t = std::clamp(v, 0.F, 1.F);
243
244 Kinesis::AABB2D fill {}, remainder {};
245 if (horizontal) {
246 const float split = bounds.min.x + t * bounds.width();
247 fill = { .min = bounds.min, .max = { split, bounds.max.y } };
248 remainder = { .min = { split, bounds.min.y }, .max = bounds.max };
249 } else {
250 const float split = bounds.min.y + t * bounds.height();
251 fill = { .min = bounds.min, .max = { bounds.max.x, split } };
252 remainder = { .min = { bounds.min.x, split }, .max = bounds.max };
253 }
254
255 auto verts = Kakshya::to_mesh_vertices(Kinesis::filled_rect(fill, fill_color));
256 auto rest = Kakshya::to_mesh_vertices(Kinesis::filled_rect(remainder, track_color));
257 verts.insert(verts.end(), rest.begin(), rest.end());
258
259 write_verts(out, verts);
260
261 el.bounds_hint = bounds;
262 el.contains = {};
263 };
264}
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
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::Kinesis::AABB2D::width(), and write_verts().

+ Here is the call graph for this function: