Repository navigation
Expand file tree
/
Copy pathChartComponent.h
More file actions
110 lines (87 loc) · 2.93 KB
/
Copy pathChartComponent.h
File metadata and controls
110 lines (87 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#pragma once
#include <stdint.h>
#include <vector>
#include <deki/Component.h>
#include <deki/reflection/Property.h>
namespace Deki
{
class Object;
}
namespace Deki2D
{
/// How a chart draws its points.
enum class ChartKind : uint8_t
{
Line = 0, // Points joined by a line
Bars = 1 // A bar per point
};
/// A chart of a series of values: a frame rate, a temperature, a score over
/// time. AddPoint pushes a value on at the right and, once Point Count is
/// reached, the oldest off at the left, so it scrolls like a monitor.
///
/// The series and the grid are each one mask, baked again only when a value
/// changes. Its parts are children the editor makes: Back, Grid and Series;
/// the series' colour is the Series part's.
DEKI_CATEGORY("2D")
DEKI_DESCRIPTION("A line or bar chart of a series of values.")
class ChartComponent : public Deki::Component
{
public:
DEKI_EXPORT
DEKI_TOOLTIP("A line through the points, or a bar for each.")
ChartKind kind = ChartKind::Line;
DEKI_EXPORT
DEKI_TOOLTIP("The values, oldest first. AddPoint adds to the end.")
std::vector<float> points = { 20.0f, 45.0f, 30.0f, 60.0f, 55.0f, 80.0f, 70.0f };
DEKI_EXPORT
DEKI_TOOLTIP("How many points the chart holds. Past this, adding a point drops the oldest.")
DEKI_RANGE(2, 256)
int32_t pointCount = 16;
DEKI_EXPORT
DEKI_TOOLTIP("The value at the bottom edge.")
float minValue = 0.0f;
DEKI_EXPORT
DEKI_TOOLTIP("The value at the top edge.")
float maxValue = 100.0f;
DEKI_EXPORT
DEKI_TOOLTIP("Horizontal grid lines across the chart. 0 for none.")
DEKI_RANGE(0, 16)
int32_t gridLines = 4;
DEKI_EXPORT
DEKI_TOOLTIP("Thickness of the line in meters.")
DEKI_UNIT(Distance)
float lineWidth = 0.18f;
DEKI_EXPORT
DEKI_TOOLTIP("Width of the chart in meters.")
DEKI_UNIT(Distance)
float width = 12.0f;
DEKI_EXPORT
DEKI_TOOLTIP("Height of the chart in meters.")
DEKI_UNIT(Distance)
float height = 6.0f;
ChartComponent() = default;
~ChartComponent() override = default;
/// Adds a value at the right, dropping the oldest once the chart is full.
void AddPoint(float value);
/// Sets point `index` (from the oldest), when there is one.
void SetPoint(int32_t index, float value);
void Clear();
/// Places and sizes the parts and bakes the masks, making any part the
/// editor is missing.
void SyncParts();
void Start() override;
bool NeedsRuntimeUpdate() const override { return true; }
void RuntimeUpdate(float deltaTime) override;
void OnPropertyChanged(const char* propertyName) override;
private:
Deki::Object* m_Back = nullptr;
Deki::Object* m_Grid = nullptr;
Deki::Object* m_Series = nullptr;
size_t m_KnownChildren = static_cast<size_t>(-1);
uint64_t m_LastGrid = 0;
uint64_t m_LastSeries = 0;
void EnsureParts();
void BakeGrid();
void BakeSeries();
};
} // namespace Deki2D