TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_curve_types.h
Go to the documentation of this file.
1#pragma once
2
4#include <gui_core/gui_id.h>
6#include <gui_controls/gui_widget_state_types.h> // DoubleClickTracker
8
9#include <cstdint>
10#include <functional>
11#include <span>
12#include <string>
13#include <unordered_set>
14#include <vector>
15
16namespace tachyon
17{
18 class IDManager;
19
22
23 // =========================================================================
24 // Curves
25 // =========================================================================
26
28 enum class CurveTangentMode : uint8_t
29 {
34 };
35
37 enum class CurveInterpolation : uint8_t
38 {
40 Linear,
42 };
43
45 enum class CurveWrapMode : uint8_t
46 {
50 };
51
54 struct CurveKey
55 {
57 float time = 0.0f;
58 float value = 0.0f;
59 float inSlope = 0.0f;
60 float outSlope = 0.0f;
63
64 bool operator==(const CurveKey&) const = default;
65 };
66
70 struct Curve
71 {
72 std::vector<CurveKey> keys;
75
76 bool operator==(const Curve&) const = default;
77 };
78
81 float EvaluateCurve(const Curve& curve, float time);
82
86
88 Curve MakeCurve(std::span<const float2> points, CurveTangentMode mode = CurveTangentMode::Auto,
90
92 enum class CurveChannelColor : uint8_t
93 {
99 };
100
103 {
104 std::string name;
107 std::string path;
109 bool visible = true;
111
112 bool operator==(const CurveChannel&) const = default;
113 };
114
117 {
118 float timeMin = 0.0f;
119 float timeMax = 1.0f;
120 float valueMin = 0.0f;
121 float valueMax = 1.0f;
122
123 bool operator==(const CurveRange&) const = default;
124 };
125
128 {
129 std::string name;
131 };
132
135 std::span<const CurvePreset> DefaultCurvePresets();
136
140 {
141 struct Change { int channel = -1; Curve from, to; };
142 std::vector<Change> changes;
143
144 bool empty() const { return changes.empty(); }
145 };
146
152 {
153 std::vector<CurveChannel> channels;
157 bool clampValues = false;
159 std::vector<CurvePreset> presets;
160
164 float fps = 0.0f;
167 float playhead = 0.0f;
169 std::function<void(float time)> onPlayheadChanged;
170
172 std::function<void(const CurveEdit&)> onEdit;
173
175 uint32_t revision = 0;
176 };
177
224
227 {
228 };
229
233
235 void ApplyCurveEdit(CurveData& data, const CurveEdit& edit, bool undo = false);
238 void CommitCurveEdit(CurveViewRef view, const CurveEdit& edit);
242 void ReleaseCurveEditIDs(IDManager& ids, const CurveEdit& edit, bool undone);
247
250 CurveEdit AddCurveKeyEdit(const CurveData& data, int channel, float time, float value, ID keyID);
252 float SnapToFrame(const CurveData& data, float time);
261 CurveEdit ApplyCurvePresetEdit(const CurveData& data, int channel, const CurvePreset& preset,
262 const std::function<ID()>& makeID);
264 CurveEdit SetCurveWrapEdit(const CurveData& data, int channel, CurveWrapMode pre, CurveWrapMode post);
265
267}
Makes element IDs: per-frame dynamic / ranged IDs (hashed from the call site or a hint and the parent...
Definition gui_id_manager.h:31
void ReleaseCurveEditIDs(IDManager &ids, const CurveEdit &edit, bool undone)
Releases the static IDs of the keys only the side of edit not in effect holds: done,...
CurveEdit SetCurveWrapEdit(const CurveData &data, int channel, CurveWrapMode pre, CurveWrapMode post)
A channel's wrap modes set.
float SnapToFrame(const CurveData &data, float time)
With fps set, time on the nearest frame; as it is without.
Curve MakeCurve(std::span< const float2 > points, CurveTangentMode mode=CurveTangentMode::Auto, CurveInterpolation interpolation=CurveInterpolation::Bezier)
A curve, with its keys' tangents worked out: one key at each points (time, value).
std::span< const CurvePreset > DefaultCurvePresets()
The built-in presets: constant, linear, ease in, ease out, ease in and out, and their mirror images.
float EvaluateCurve(const Curve &curve, float time)
The curve's value at time; 0 without keys.
bool PruneCurveSelection(CurveViewRef view)
After an edit (through this view or another): lets go of the selected keys that are gone,...
void ApplyCurveEdit(CurveData &data, const CurveEdit &edit, bool undo=false)
Does (or with undo, undoes) edit on the curves, and raises their revision.
CurveEdit AddCurveKeyEdit(const CurveData &data, int channel, float time, float value, ID keyID)
A key on channel at time with value, kept in the curves' range; none on a hidden channel,...
CurveTangentMode
How a key's slopes are set: worked out from its neighbors, or by the user.
Definition gui_curve_types.h:29
CurveInterpolation
How a curve runs from a key to the next.
Definition gui_curve_types.h:38
BasicViewRef< const CurveData, const CurveViewState > ConstCurveViewRef
Definition gui_curve_types.h:232
CurveEdit DeleteSelectedCurveKeysEdit(ConstCurveViewRef view)
The view's selected keys gone, from every channel.
CurveWrapMode
What a curve does before its first key or after its last.
Definition gui_curve_types.h:46
CurveEdit SetCurveTangentModeEdit(ConstCurveViewRef view, CurveTangentMode mode)
The selected keys' tangent mode set; to Free or Aligned, each side keeps its slope.
void CommitCurveEdit(CurveViewRef view, const CurveEdit &edit)
Applies edit, lets go of what it took from the view's selection, and hands it to view....
CurveEdit ApplyCurvePresetEdit(const CurveData &data, int channel, const CurvePreset &preset, const std::function< ID()> &makeID)
channel's curve made preset stretched over the curves' range, with new key IDs from makeID.
CurveChannelColor
The color a channel is drawn in.
Definition gui_curve_types.h:93
void UpdateCurveTangents(Curve &curve)
Works out the slopes their mode sets: Auto from the neighbors, Flat level, Aligned the leaving slope ...
BasicViewRef< CurveData, CurveViewState > CurveViewRef
Curves and one view of them, as CurveField, CurveEditor and the helpers take them.
Definition gui_curve_types.h:231
CurveEdit SetCurveInterpolationEdit(ConstCurveViewRef view, CurveInterpolation interpolation)
The selected keys' interpolation to the next key set.
@ Auto
smooth through the key, without overshooting its neighbors (the default)
Definition gui_curve_types.h:30
@ Aligned
one slope the user sets, the same on both sides
Definition gui_curve_types.h:31
@ Flat
level on both sides
Definition gui_curve_types.h:33
@ Free
each side its own slope, the user's
Definition gui_curve_types.h:32
@ Bezier
a curve shaped by the two keys' slopes (the default)
Definition gui_curve_types.h:39
@ Clamp
holds the end key's value
Definition gui_curve_types.h:47
@ Loop
repeats the curve
Definition gui_curve_types.h:48
@ PingPong
repeats it, every other time backwards
Definition gui_curve_types.h:49
@ Value
one value: the warning color, as a scalar channel in the design
Definition gui_curve_types.h:94
@ Alpha
Definition gui_image.h:33
@ Blue
Definition gui_image.h:33
@ Green
Definition gui_image.h:33
@ Red
Definition gui_image.h:33
@ Constant
the stop's color all the way to the next stop: a step
Definition gui_style_gradient.h:280
@ Auto
align-self only: inherit from container's align-items
Definition gui_style.h:182
Definition gui_logging.h:24
What a control shows and one view of it, as the control takes them.
Definition gui_view_ref.h:20
One of a CurveView's curves, such as the red one of a color's.
Definition gui_curve_types.h:103
bool visible
drawn; a hidden channel's keys can't be picked
Definition gui_curve_types.h:109
bool operator==(const CurveChannel &) const =default
Curve curve
Definition gui_curve_types.h:110
std::string name
shown in the editor when there are several: "R", "Alpha"
Definition gui_curve_types.h:104
std::string path
The groups it's in, outermost first, split by '/': "Sphere/Position".
Definition gui_curve_types.h:107
CurveChannelColor color
Definition gui_curve_types.h:108
A CurveField's curves, kept by the app from frame to frame.
Definition gui_curve_types.h:152
std::vector< CurvePreset > presets
The thumbnails under the plot; empty: DefaultCurvePresets().
Definition gui_curve_types.h:159
std::function< void(float time)> onPlayheadChanged
The user moved the playhead on the ruler (already set): sync your timeline.
Definition gui_curve_types.h:169
bool clampValues
Definition gui_curve_types.h:157
CurveRange range
What the field shows, and where the editor opens.
Definition gui_curve_types.h:156
float playhead
The playhead, in seconds, with fps set: on the ruler and through the plot, and each channel's value t...
Definition gui_curve_types.h:167
std::vector< CurveChannel > channels
one for a plain curve; four for a color's R, G, B and A
Definition gui_curve_types.h:153
uint32_t revision
Raised by each edit applied, so every view of the curves can tell they changed.
Definition gui_curve_types.h:175
std::function< void(const CurveEdit &)> onEdit
A change the user made, already applied: put it in the undo history.
Definition gui_curve_types.h:172
float fps
Frames a second, for animation curves: times show as frames, keys land on them, and the editor lays o...
Definition gui_curve_types.h:164
Definition gui_curve_types.h:141
Curve from
Definition gui_curve_types.h:141
Curve to
Definition gui_curve_types.h:141
int channel
Definition gui_curve_types.h:141
A change to a CurveView, for undo: what each changed channel's curve was before and after.
Definition gui_curve_types.h:140
bool empty() const
Definition gui_curve_types.h:144
std::vector< Change > changes
Definition gui_curve_types.h:142
A key: a time where the curve has a value, its slopes on either side, and how the curve runs on to th...
Definition gui_curve_types.h:55
ID stableID
assigned once on creation, for its selection
Definition gui_curve_types.h:56
float outSlope
the slope leaving
Definition gui_curve_types.h:60
float value
Definition gui_curve_types.h:58
CurveInterpolation interpolation
to the next key
Definition gui_curve_types.h:62
CurveTangentMode tangents
Definition gui_curve_types.h:61
bool operator==(const CurveKey &) const =default
float time
Definition gui_curve_types.h:57
float inSlope
the slope arriving, value per time
Definition gui_curve_types.h:59
A named curve the editor offers to start from, as a thumbnail under the plot.
Definition gui_curve_types.h:128
std::string name
its tooltip
Definition gui_curve_types.h:129
Curve curve
over 0 to 1, both ways; stretched to the range when used
Definition gui_curve_types.h:130
The span a CurveField shows, from timeMin to timeMax and valueMin to valueMax.
Definition gui_curve_types.h:117
bool operator==(const CurveRange &) const =default
float valueMax
Definition gui_curve_types.h:121
float valueMin
Definition gui_curve_types.h:120
float timeMin
Definition gui_curve_types.h:118
float timeMax
Definition gui_curve_types.h:119
What's under the pointer, for its hover look: a key, else a handle, else a curve.
Definition gui_curve_types.h:202
int channel
the channel whose curve it is, away from keys and handles
Definition gui_curve_types.h:206
bool handleOut
... and which side
Definition gui_curve_types.h:205
ID handleKey
the key whose handle it is ...
Definition gui_curve_types.h:204
bool operator==(const HoverTarget &) const =default
ID key
a key
Definition gui_curve_types.h:203
How one CurveField or CurveEditor shows a CurveData: the channel worked on, the selection,...
Definition gui_curve_types.h:182
uint32_t menuOpening
the context menu opening the menu was built for
Definition gui_curve_types.h:215
IntRect plotRect
the plot's grid last frame, in screen pixels
Definition gui_curve_types.h:216
ID menuKey
the key a right click opened the menu for
Definition gui_curve_types.h:213
DoubleClickTracker plotClicks
a double click on the plot adds a key
Definition gui_curve_types.h:217
bool shownSet
false until the editor first opens: then range
Definition gui_curve_types.h:189
bool keyMoved
the part of the plot in view
Definition gui_curve_types.h:196
float2 boxTo
in time and value
Definition gui_curve_types.h:211
float2 keyDragFrom
the time and value under the press
Definition gui_curve_types.h:195
uint32_t editsSeen
the count CurveField last saw
Definition gui_curve_types.h:220
int activeChannel
the one whose keys can be picked and added to
Definition gui_curve_types.h:183
CurveRange shown
the part of the plot in view
Definition gui_curve_types.h:188
float2 menuAt
where the right click was, in time and value
Definition gui_curve_types.h:214
HoverPart< HoverTarget > hover
the part of the plot in view
Definition gui_curve_types.h:209
Gesture< std::vector< Curve > > keyDrag
moving the selected keys; the curves as they were
Definition gui_curve_types.h:194
float2 lastClick
where the last click on the plot was, in pixels
Definition gui_curve_types.h:218
ID popupID
the part of the plot in view
Definition gui_curve_types.h:193
float2 boxFrom
the part of the plot in view
Definition gui_curve_types.h:211
bool popupOpen
the field's editor window is open
Definition gui_curve_types.h:192
std::unordered_set< std::string > collapsedGroups
the tree's closed groups, by path
Definition gui_curve_types.h:190
ID tangentKey
the part of the plot in view
Definition gui_curve_types.h:198
std::unordered_set< ID > selectedKeys
by stableID
Definition gui_curve_types.h:184
uint32_t seenRevision
the curves' revision this view last built
Definition gui_curve_types.h:221
uint32_t edits
counts the edits committed through this view, for CurveField's return
Definition gui_curve_types.h:219
Gesture< std::vector< Curve > > tangentDrag
a handle; the curves as they were
Definition gui_curve_types.h:197
Gesture< std::unordered_set< ID > > boxSelect
the selection to go back to: before a Shift / Ctrl box, else none
Definition gui_curve_types.h:210
Gesture< CurveRange > pan
the middle button (or Alt + left) held over the plot; the view as it was
Definition gui_curve_types.h:212
Gesture playheadDrag
the ruler pressed
Definition gui_curve_types.h:191
bool tangentOut
the leaving side's handle
Definition gui_curve_types.h:199
Curves shown in one place: the curves and the one view of them together.
Definition gui_curve_types.h:227
A curve: keys in time order, joined by segments as each key's interpolation says: a cubic (Hermite) o...
Definition gui_curve_types.h:71
std::vector< CurveKey > keys
Definition gui_curve_types.h:72
CurveWrapMode postWrap
after the last
Definition gui_curve_types.h:74
bool operator==(const Curve &) const =default
CurveWrapMode preWrap
before the first key
Definition gui_curve_types.h:73
Click-gesture tracker, owned per widget instance so instances (and tests) don't share it.
Definition gui_widget_state_types.h:77
One press that may become a drag, with what every control does around it: the focus and the capture o...
Definition gui_gesture.h:60
The part of a drawn control under the pointer (a key, a handle, a clip's end), for its hover look.
Definition gui_gesture.h:115
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
static constexpr ID Invalid()
The "no element" ID (all bits zero); also the default for optional ID parameters.
Definition gui_id.h:66
Definition gui_base_types.h:406
Definition gui_base_types.h:120