-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwidget.h
169 lines (149 loc) · 3.97 KB
/
widget.h
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <vector>
#include <string>
#include <algorithm>
#include <yaml-cpp/yaml.h>
#include "nanovg/nanovg.h"
#include "layout.h"
#include "draw.h"
using std::string;
using std::vector;
typedef YAML::Node Properties;
struct Widget
{
Widget(NVGcontext *vg)
:vg(vg) {}
virtual void draw(float*){};
NVGcontext *vg;
};
struct Parent:public Widget
{
Parent(NVGcontext *vg)
:Widget(vg) {}
std::vector<Widget*> children;
std::vector<string> labels;
~Parent(void) { for(auto w:children) delete w; }
};
struct Knob:public Widget
{
Knob(NVGcontext *vg, Properties &)
:Widget(vg) {}
virtual void draw(float *pos)
{
drawAltDial(vg, 0.2, SPLAT(pos));
}
};
struct KnobDetail:public Widget
{
KnobDetail(NVGcontext *vg, Properties &)
:Widget(vg) {}
virtual void draw(float *pos)
{
drawDial(vg, SPLAT(pos));
drawDialValue(vg, 27, SPLAT(pos));
}
};
struct DropDown:public Widget
{
DropDown(NVGcontext *vg, Properties &p)
:Widget(vg), text(p["text"].as<string>())
{}
virtual void draw(float*pos)
{
drawOptButton(vg, text.c_str(), SPLAT(pos));
};
string text;
};
struct Button:public Widget
{
Button(NVGcontext *vg, Properties &p)
:Widget(vg), label(p["label"].as<string>()) {}
virtual void draw(float *pos)
{
drawButton(vg, label.c_str(), SPLAT(pos));
}
string label;
};
//Assumes simple 1D Flow right now
struct Group:public Parent
{
float pad_factor;
layout_t layout;
Group(NVGcontext *vg)
:Parent(vg),pad_factor(1.0), layout(layoutCreate(LAYOUT_LABELS)){}
~Group(void) {layoutDestroy(layout);}
virtual void draw(float *pos)
{
layoutFlow(layout, SPLAT(pos));
int N = children.size();
for(int i=0; i<N; ++i) {
float pos2[4];
layoutGet(layout, i, pos2);
pad(pad_factor, pos2);
children[i]->draw(pos2);
if(!labels[i].empty()) {
layoutGetLabel(layout, i, pos2);
pad(pad_factor, pos2);
drawLabel(vg, labels[i].c_str(), SPLAT(pos2));
}
}
}
void add(Widget *w, float aspect, float weight, string label="")
{
for(int i=0; i<(int)label.size();++i)
label[i] = std::toupper(label[i]);
children.push_back(w);
labels.push_back(label);
layoutBoundBox(layout, aspect, weight);
}
void flow(float x, float y, float w, float h)
{
layoutFlow(layout, x,y,w,h);
}
};
struct Module:public Parent
{
string label;
Module(NVGcontext *vg, Properties &p)
:Parent(vg), inner(vg), upper(vg), label(p["label"].as<string>())
{
layoutDummyBox(upper.layout);
}
virtual void draw(float*pos_)
{
//Paint the Whole thing black
nvgBeginPath(vg);
nvgRect(vg, SPLAT(pos_));
nvgFillColor(vg, nvgRGBA(0, 0, 0, 255));
nvgFill(vg);
{
////paint the top half
float pos[4] = {SPLAT(pos_)};
pos[3] *= 0.2;
nvgBeginPath(vg);
boarder(pos_[3]*0.01, pos);
nvgRect(vg, SPLAT(pos));
nvgFillColor(vg, nvgRGBA(0xa, 0x2e, 0x4c, 255));
nvgFill(vg);
float upperspace[4] = {pos[0]+pos[2]*2.0f/3.0f,
pos[1], pos[2]/3.0f, pos[3]};
upper.draw(upperspace);
float pos2[4] = {SPLAT(pos)};
pos2[2] /= 3;
pad(0.9, pos2);
drawLeftLabel(vg, label.c_str(), SPLAT(pos2));
}
{
SMAP(pos_);
float innerspace[4] = {x, y+h*0.2f, w, h*0.8f};
boarder(h*0.01, innerspace);
//paint the inner panel
nvgBeginPath(vg);
nvgRect(vg, SPLAT(innerspace));
nvgFillColor(vg, nvgRGBA(0x6, 0x27, 0x37, 255));
nvgFill(vg);
inner.draw(innerspace);
}
}
Group upper;
Group inner;
};