MayaFlux 0.4.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 std::shared_ptr<Buffers::FormaBuffer> buf,
18 const LabelSpec& spec,
19 uint32_t relate_to)
20{
21 const auto render_bounds = spec.render_bounds.x > 0 && spec.render_bounds.y > 0
22 ? spec.render_bounds
24 { spec.bounds.width(), spec.bounds.height() },
25 surface.window()->get_state().current_width,
26 surface.window()->get_state().current_height);
27
28 Element el;
29 el.with_buffer(std::move(buf))
30 .with_bounds(spec.bounds)
31 .with_name(spec.name)
32 .with_text(spec.text,
34 .color = spec.color,
35 .render_bounds = render_bounds,
36 },
37 spec.bounds);
38
39 if (!spec.interactive)
40 el.non_interactive();
41
42 const uint32_t id = surface.layer().add(std::move(el));
43 if (relate_to != 0)
44 surface.layer().relate(relate_to, id);
45
46 return id;
47}
48
49// =============================================================================
50// place_rect
51// =============================================================================
52
53uint32_t place_rect(
54 Surface& surface,
55 std::shared_ptr<Buffers::FormaBuffer> buf,
56 const RectSpec& spec,
57 uint32_t relate_to)
58{
59 const auto verts = Kinesis::filled_rect(spec.bounds, spec.color);
60 buf->submit(verts);
61
62 Element el;
63 el.with_buffer(std::move(buf))
64 .with_bounds(spec.bounds)
65 .with_name(spec.name);
66
67 if (!spec.interactive)
68 el.non_interactive();
69
70 const uint32_t id = surface.layer().add(std::move(el));
71 if (relate_to != 0)
72 surface.layer().relate(relate_to, id);
73
74 return id;
75}
76
77// =============================================================================
78// place
79// =============================================================================
80
82 Surface& surface,
83 std::shared_ptr<Buffers::FormaBuffer> buf,
84 SeriesSpec spec,
85 std::shared_ptr<Kakshya::PlotContainer> container)
86{
87 auto mapped = make_mapped<std::shared_ptr<Kakshya::PlotContainer>>(
88 std::move(container), std::move(spec.fn), std::move(buf));
89
90 mapped.element.id = surface.layer().add(mapped.element);
91 mapped.state->id = mapped.element.id;
92 mapped.force_redraw_on_sync = true;
93 mapped.sync();
94
95 return mapped;
96}
97
98} // namespace MayaFlux::Portal::Forma::Plot
uint32_t id() const noexcept
Explicit id accessor, for clarity in chained expressions.
Definition Layer.hpp:70
bool relate(uint32_t primary_id, uint32_t related_id)
Record that related_id belongs with primary_id.
Definition Layer.cpp:152
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:126
Layer & layer() noexcept
Access the spatial registry.
Definition Surface.hpp:107
Named owner of a (Window, Layer, Context) triple - the Forma canvas.
Definition Surface.hpp:58
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:443
std::array< Kakshya::Vertex, 4 > filled_rect(Kinesis::AABB2D region, glm::vec3 color)
Generate a filled TRIANGLE_STRIP quad from an AABB2D.
uint32_t place_label(Surface &surface, std::shared_ptr< Buffers::FormaBuffer > buf, const LabelSpec &spec, uint32_t relate_to)
Place a text label element onto surface using a pre-built buffer.
Definition Plot.cpp:15
Mapped< std::shared_ptr< Kakshya::PlotContainer > > place(Surface &surface, std::shared_ptr< Buffers::FormaBuffer > buf, SeriesSpec spec, std::shared_ptr< Kakshya::PlotContainer > container)
Place a plot element onto a Surface using a pre-built FormaBuffer.
Definition Plot.cpp:81
uint32_t place_rect(Surface &surface, std::shared_ptr< Buffers::FormaBuffer > buf, const RectSpec &spec, uint32_t relate_to)
Place a filled rectangle element onto surface using a pre-built buffer.
Definition Plot.cpp:53
float height() const noexcept
Definition Bounds.hpp:38
float width() const noexcept
Definition Bounds.hpp:37
Element & with_buffer(std::shared_ptr< Buffers::FormaBuffer > buf)
Attach a FormaBuffer as the rendered output for this region.
Definition Element.hpp:180
Element & with_bounds(Kinesis::AABB2D b)
Set the fast-reject AABB.
Definition Element.hpp:95
Element & non_interactive()
Exclude from hit testing.
Definition Element.hpp:253
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) })
Press text into a new GPU texture and bind it to the attached FormaBuffer.
Definition Element.cpp:51
uint32_t id
Stable id assigned by Layer::add. Never zero.
Definition Element.hpp:60
Element & with_name(std::string n)
Set the human-readable name used in Lila introspection and debug output.
Definition Element.hpp:278
A bounded, renderable region on a window surface.
Definition Element.hpp:58
Element element
The Element registered with the Layer.
Definition Mapped.hpp:98
Infrastructure for a continuously-mapped value whose GPU geometry tracks it.
Definition Mapped.hpp:89
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
Construction parameters for press().
Definition InkPress.hpp:48