MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ColorPicker.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "LayoutCursor.hpp"
4
6
7class Surface;
8
9/**
10 * @struct ColorPicker
11 * @brief A saturation and value square, a hue strip and a swatch, drawn into one buffer.
12 *
13 * Configure with the setters, then place() once. After place(), picker_id,
14 * color, hsv, picker_bounds and cursor_out are populated. Pressing or dragging
15 * the square sets saturation and value, and the strip sets hue. Hue is kept
16 * in hsv, so it survives picking a grey or black. color holds the same value
17 * as red, green and blue, each in [0, 1].
18 *
19 * color is registered with the Bridge, so Forma::bridge().at(color).write(sink)
20 * receives three floats; hsv is registered the same way and receives hue,
21 * saturation and value. A Bridge inbound write changes the value but does not
22 * move the markers. Forma::destroy(surface, picker_id) removes the picker.
23 *
24 * @code
25 * auto picker = ColorPicker {}
26 * .initial({ 0.9F, 0.4F, 0.1F })
27 * .on_change([](glm::vec3 rgb) { })
28 * .place(surface, cursor, 0.4F);
29 * @endcode
30 */
32 /// @brief Element id of the drawn picker. Valid after place().
33 uint32_t picker_id {};
34
35 /// @brief Chosen colour as red, green and blue. Valid after place().
36 std::shared_ptr<MappedState<glm::vec3>> color;
37
38 /// @brief Chosen colour as hue, saturation and value. Valid after place().
39 std::shared_ptr<MappedState<glm::vec3>> hsv;
40
41 /// @brief Cursor positioned below the picker. Valid after place().
43
44 /// @brief NDC region occupied by the picker. Valid after place().
46
47 /// @brief Picker region, satisfying Kinesis::HasBounds.
48 [[nodiscard]] Kinesis::AABB2D bounds() const noexcept { return picker_bounds; }
49
50 /// @brief Colour shown before any interaction, as red, green and blue. Default: red.
51 glm::vec3 m_initial { 1.F, 0.F, 0.F };
52
53 /// @brief Called with the new red, green and blue on every pick.
54 std::function<void(glm::vec3)> m_on_change;
55
56 ColorPicker& initial(glm::vec3 rgb)
57 {
58 m_initial = rgb;
59 return *this;
60 }
61
62 ColorPicker& on_change(std::function<void(glm::vec3)> fn)
63 {
64 m_on_change = std::move(fn);
65 return *this;
66 }
67
68 /**
69 * @brief Register the picker and wire its input.
70 *
71 * Advances @p cursor by @p height.
72 *
73 * @param surface Surface to register on.
74 * @param cursor Layout cursor. Advanced by height on return.
75 * @param x_min Left edge in NDC.
76 * @param x_max Right edge in NDC.
77 * @param height Picker height in NDC units.
78 * @return *this, with results populated.
79 */
80 MAYAFLUX_API ColorPicker& place(
81 Surface& surface,
82 LayoutCursor& cursor,
83 float x_min, float x_max, float height);
84
85 /**
86 * @brief Register using the cursor's column extents.
87 */
88 MAYAFLUX_API ColorPicker& place(
89 Surface& surface,
90 LayoutCursor& cursor,
91 float height);
92};
93
94} // namespace MayaFlux::Portal::Forma
uint32_t height
Reactive Y-position accumulator for vertical primitive stacking.
Named owner of a (Window, Layer, Context) triple: the Forma canvas.
Definition Surface.hpp:121
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:63
uint32_t picker_id
Element id of the drawn picker. Valid after place().
LayoutCursor cursor_out
Cursor positioned below the picker. Valid after place().
MAYAFLUX_API ColorPicker & place(Surface &surface, LayoutCursor &cursor, float x_min, float x_max, float height)
Register the picker and wire its input.
Kinesis::AABB2D bounds() const noexcept
Picker region, satisfying Kinesis::HasBounds.
std::shared_ptr< MappedState< glm::vec3 > > hsv
Chosen colour as hue, saturation and value. Valid after place().
ColorPicker & on_change(std::function< void(glm::vec3)> fn)
glm::vec3 m_initial
Colour shown before any interaction, as red, green and blue. Default: red.
std::function< void(glm::vec3)> m_on_change
Called with the new red, green and blue on every pick.
std::shared_ptr< MappedState< glm::vec3 > > color
Chosen colour as red, green and blue. Valid after place().
Kinesis::AABB2D picker_bounds
NDC region occupied by the picker. Valid after place().
ColorPicker & initial(glm::vec3 rgb)
A saturation and value square, a hue strip and a swatch, drawn into one buffer.