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
5
namespace
MayaFlux::Portal::Forma
{
6
7
class
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
*/
31
struct
ColorPicker
{
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().
42
LayoutCursor
cursor_out
;
43
44
/// @brief NDC region occupied by the picker. Valid after place().
45
Kinesis::AABB2D
picker_bounds
{};
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
LayoutCursor.hpp
height
uint32_t height
Definition
VolumeFieldProcessor.cpp:17
MayaFlux::Portal::Forma::LayoutCursor
Reactive Y-position accumulator for vertical primitive stacking.
Definition
LayoutCursor.hpp:20
MayaFlux::Portal::Forma::Surface
Named owner of a (Window, Layer, Context) triple: the Forma canvas.
Definition
Surface.hpp:121
MayaFlux::Portal::Forma
Definition
Bridge.cpp:16
MayaFlux::Kinesis::AABB2D
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition
Bounds.hpp:63
MayaFlux::Portal::Forma::ColorPicker::picker_id
uint32_t picker_id
Element id of the drawn picker. Valid after place().
Definition
ColorPicker.hpp:33
MayaFlux::Portal::Forma::ColorPicker::cursor_out
LayoutCursor cursor_out
Cursor positioned below the picker. Valid after place().
Definition
ColorPicker.hpp:42
MayaFlux::Portal::Forma::ColorPicker::place
MAYAFLUX_API ColorPicker & place(Surface &surface, LayoutCursor &cursor, float x_min, float x_max, float height)
Register the picker and wire its input.
Definition
ColorPicker.cpp:44
MayaFlux::Portal::Forma::ColorPicker::bounds
Kinesis::AABB2D bounds() const noexcept
Picker region, satisfying Kinesis::HasBounds.
Definition
ColorPicker.hpp:48
MayaFlux::Portal::Forma::ColorPicker::hsv
std::shared_ptr< MappedState< glm::vec3 > > hsv
Chosen colour as hue, saturation and value. Valid after place().
Definition
ColorPicker.hpp:39
MayaFlux::Portal::Forma::ColorPicker::on_change
ColorPicker & on_change(std::function< void(glm::vec3)> fn)
Definition
ColorPicker.hpp:62
MayaFlux::Portal::Forma::ColorPicker::m_initial
glm::vec3 m_initial
Colour shown before any interaction, as red, green and blue. Default: red.
Definition
ColorPicker.hpp:51
MayaFlux::Portal::Forma::ColorPicker::m_on_change
std::function< void(glm::vec3)> m_on_change
Called with the new red, green and blue on every pick.
Definition
ColorPicker.hpp:54
MayaFlux::Portal::Forma::ColorPicker::color
std::shared_ptr< MappedState< glm::vec3 > > color
Chosen colour as red, green and blue. Valid after place().
Definition
ColorPicker.hpp:36
MayaFlux::Portal::Forma::ColorPicker::picker_bounds
Kinesis::AABB2D picker_bounds
NDC region occupied by the picker. Valid after place().
Definition
ColorPicker.hpp:45
MayaFlux::Portal::Forma::ColorPicker::initial
ColorPicker & initial(glm::vec3 rgb)
Definition
ColorPicker.hpp:56
MayaFlux::Portal::Forma::ColorPicker
A saturation and value square, a hue strip and a swatch, drawn into one buffer.
Definition
ColorPicker.hpp:31
src
MayaFlux
Portal
Forma
Primitives
ColorPicker.hpp
Generated by
1.9.8