MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Plot.cpp
Go to the documentation of this file.
1#include "Plot.hpp"
2
8
10
11// =============================================================================
12// place_label
13// =============================================================================
14
15uint32_t place_label(
16 Surface& surface,
17 FormaTarget buf,
18 const LabelSpec& spec,
19 uint32_t relate_to)
20{
21 const bool auto_render_bounds = spec.render_bounds.x <= 0 || spec.render_bounds.y <= 0;
22
23 const auto render_bounds = auto_render_bounds
25 { spec.bounds.width(), spec.bounds.height() },
26 surface.window()->get_state().current_width,
27 surface.window()->get_state().current_height)
28 : spec.render_bounds;
29
30 Element el;
31 el.with_buffer(buf)
32 .with_bounds(spec.bounds)
33 .with_name(spec.name)
34 .with_text(spec.text,
36 .color = spec.color,
37 .render_bounds = render_bounds,
38 },
39 spec.bounds);
40
41 if (!spec.interactive)
42 el.non_interactive();
43
44 const uint32_t id = surface.layer().add(std::move(el));
45 if (relate_to != 0)
46 surface.layer().relate(relate_to, id);
47
48 if (auto_render_bounds) {
49 surface.ctx().on_resize(id,
50 [surface, id, text = spec.text, color = spec.color, bounds = spec.bounds](uint32_t, uint32_t) mutable {
51 const auto dims = Kinesis::ndc_size_to_pixels(
52 { bounds.width(), bounds.height() },
53 surface.window()->get_state().current_width,
54 surface.window()->get_state().current_height);
55
56 if (auto* element = surface.layer().get(id))
57 element->set_text(text, Portal::Text::PressParams { .color = color, .render_bounds = dims });
58 });
59 }
60
61 return id;
62}
63
64// =============================================================================
65// place_rect
66// =============================================================================
67
68uint32_t place_rect(
69 Surface& surface,
70 FormaTarget buf,
71 const RectSpec& spec,
72 uint32_t relate_to)
73{
74 const auto verts = Kinesis::filled_rect(spec.bounds, spec.color);
75 buf.submit(verts);
76
77 Element el;
78 el.with_buffer(std::move(buf))
79 .with_bounds(spec.bounds)
80 .with_name(spec.name);
81
82 if (!spec.interactive)
83 el.non_interactive();
84
85 const uint32_t id = surface.layer().add(std::move(el));
86 if (relate_to != 0)
87 surface.layer().relate(relate_to, id);
88
89 return id;
90}
91
92// =============================================================================
93// place
94// =============================================================================
95
97 Surface& surface,
98 FormaTarget buf,
99 SeriesSpec spec,
100 std::shared_ptr<Kakshya::PlotContainer> container)
101{
102 auto mapped = make_mapped<std::shared_ptr<Kakshya::PlotContainer>>(
103 std::move(container), std::move(spec.fn), std::move(buf));
104
105 mapped.element.id = surface.layer().add(mapped.element);
106 mapped.state->id = mapped.element.id;
107 mapped.force_redraw_on_sync = true;
108 mapped.sync(&surface.layer());
109
110 return mapped;
111}
112
113} // namespace MayaFlux::Portal::Forma::Plot
glm::vec3 color
Definition Decoder.cpp:97
void on_resize(uint32_t id, ResizeFn fn)
Called on every window resize.
Definition Context.cpp:136
void submit(const std::vector< uint8_t > &bytes) const
Replace this target's geometry.
Definition Target.cpp:51
Where an element's geometry and texture are written.
Definition Target.hpp:22
uint32_t id() const noexcept
Explicit id accessor, for clarity in chained expressions.
Definition Layer.hpp:73
bool relate(uint32_t primary_id, uint32_t related_id)
Record that related_id belongs with primary_id.
Definition Layer.cpp:205
const Element * get(uint32_t id) const
Definition Layer.cpp:272
Slot add(Element element)
Add an element to the layer.
Definition Layer.cpp:9
const std::shared_ptr< Core::Window > & window() const noexcept
Access the rendering target window.
Definition Surface.hpp:178
Context & ctx() noexcept
Access the event router.
Definition Surface.hpp:170
Layer & layer() noexcept
Access the spatial registry.
Definition Surface.hpp:159
Named owner of a (Window, Layer, Context) triple: the Forma canvas.
Definition Surface.hpp:121
glm::uvec2 ndc_size_to_pixels(const AABB2D &region, uint32_t width, uint32_t height)
Convert an NDC AABB's extent to integer pixel dimensions.
Definition Bounds.hpp:488
uint32_t place_label(Surface &surface, FormaTarget buf, const LabelSpec &spec, uint32_t relate_to)
Place a text label element onto surface using a text-capable target.
Definition Plot.cpp:15
uint32_t place_rect(Surface &surface, FormaTarget buf, const RectSpec &spec, uint32_t relate_to)
Place a filled rectangle element onto surface using a target.
Definition Plot.cpp:68
float height() const noexcept
Definition Bounds.hpp:80
float width() const noexcept
Definition Bounds.hpp:79
Element & with_bounds(Kinesis::AABB2D b)
Set the fast-reject AABB.
Definition Element.hpp:109
Element & non_interactive()
Exclude from hit testing.
Definition Element.hpp:279
Element & with_buffer(FormaTarget target)
Attach a FormaBuffer, or a slice of one, as the rendered output for this region.
Definition Element.hpp:195
Element & with_text(std::string_view text, std::optional< Portal::Text::PressParams > params, Kinesis::AABB2D region={ .min=glm::vec2(-1.F),.max=glm::vec2(1.F) })
Draw text as glyph quads into the attached buffer.
Definition Element.cpp:41
Element & with_name(std::string n)
Set the human-readable name used in Lila introspection and debug output.
Definition Element.hpp:304
A bounded, renderable region on a window surface.
Definition Element.hpp:61
Infrastructure for a continuously-mapped value whose GPU geometry tracks it.
Definition Mapped.hpp:96
std::string name
Optional logical name for the eventual Element.
Definition PlotSpec.hpp:43
glm::uvec2 render_bounds
Optional text pixel/render size override.
Definition PlotSpec.hpp:56
bool interactive
Whether the eventual Element should participate in hit testing.
Definition PlotSpec.hpp:49
Construction-free text label description.
Definition PlotSpec.hpp:35
Lightweight filled rectangle description.
Definition PlotSpec.hpp:65
Forma::GeometryFn< std::shared_ptr< Kakshya::PlotContainer > > fn
glm::vec4 color
RGBA color applied to all glyphs not covered by a span in spans.
Definition InkPress.hpp:70
Construction parameters for press().
Definition InkPress.hpp:65