Skip to content

Commit cc7fcfc

Browse files
committed
Test widget
1 parent 67cc7d4 commit cc7fcfc

File tree

1 file changed

+75
-3
lines changed

1 file changed

+75
-3
lines changed

Diff for: src/BaconTestModule.cpp

+75-3
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,90 @@ struct BaconTestWidget : bp::BaconModuleWidget
9494
BaconTestWidget(BaconTest *model);
9595
};
9696

97+
struct PolyWidget : public rack::Widget
98+
{
99+
int64_t dc{0};
100+
void draw(const DrawArgs &args) override {
101+
auto s = box.size;
102+
103+
auto vg = args.vg;
104+
105+
auto dcm = dc % (int)(s.x - 40);
106+
107+
nvgBeginPath(vg);
108+
nvgFillColor(vg, nvgRGB(255,0,0));
109+
nvgRect(vg, dcm, dcm, 40 , 40);
110+
nvgFill(vg);
111+
112+
typedef std::vector<std::pair<float, float>> poly_t;
113+
std::vector<poly_t> polys;
114+
115+
std::map<poly_t, NVGcolor> colm;
116+
for (int nsides = 3; nsides < 11; ++nsides)
117+
{
118+
poly_t p;
119+
for (auto i = 0; i < nsides; ++i)
120+
{
121+
auto x = std::sin(-i * 2.0 * M_PI / nsides) + 1;
122+
auto y = std::cos(i * 2.0 * M_PI / nsides) + 1;
123+
p.emplace_back(x, y);
124+
}
125+
polys.push_back(p);
126+
auto idx = nsides - 3;
127+
colm[p] = nvgRGB((255 - dcm * 20) * (idx < 5), idx * 15, dcm * 20);
128+
}
129+
130+
int idx = 0;
131+
for (auto &poly : polys)
132+
{
133+
auto first{true};
134+
nvgBeginPath(vg);
135+
for (const auto &[x,y] : poly)
136+
{
137+
if (first)
138+
{
139+
nvgMoveTo(vg, 15 * x + dcm, 15 * y + dcm + 40 + idx * 18);
140+
}
141+
else
142+
{
143+
nvgLineTo(vg, 15 * x + dcm, 15 * y + dcm + 40 + idx * 18);
144+
}
145+
first = false;
146+
}
147+
nvgClosePath(vg);
148+
// nvgFillColor(vg, nvgRGB((255 - dcm * 20) * (idx < 5), idx * 15, dcm * 20));
149+
nvgFillColor(vg, colm[poly]);
150+
nvgFill(vg);
151+
nvgStrokeColor(vg, nvgRGB(0,0,50));
152+
nvgStroke(vg);
153+
idx ++;
154+
}
155+
156+
dc++;
157+
}
158+
};
159+
97160
BaconTestWidget::BaconTestWidget(BaconTest *model)
98161
{
99162
setModule(model);
100-
box.size = Vec(SCREW_WIDTH * 8, RACK_HEIGHT);
163+
box.size = Vec(SCREW_WIDTH * 15, RACK_HEIGHT);
101164

102165
BaconBackground *bg = new BaconBackground(box.size, "BaconTest");
103166
addChild(bg->wrappedInFramebuffer());
104167

168+
auto layoutSize = box.size;
169+
layoutSize.x /= 2;
170+
105171
Vec cr(5, 35);
106-
auto dSp = (box.size.x - 10) / BaconTest::nPorts;
172+
auto dSp = (layoutSize.x - 10) / BaconTest::nPorts;
107173
for (int i = 0; i < BaconTest::nPorts; ++i)
108174
{
109175
addInput(createInput<PJ301MPort>(cr, module, BaconTest::INPUT_0 + i));
110176
cr.x += dSp;
111177
}
112178

113179
cr = Vec(10, 90);
114-
auto kSp = (box.size.x - 20) / 2;
180+
auto kSp = (layoutSize.x - 20) / 2;
115181
for (int i = 0; i < BaconTest::nParams; ++i)
116182
{
117183
addParam(createParam<RoundLargeBlackKnob>(cr, module, BaconTest::PARAM_0 + i));
@@ -131,6 +197,12 @@ BaconTestWidget::BaconTestWidget(BaconTest *model)
131197
cr.x += dSp;
132198
}
133199

200+
auto p = new PolyWidget();
201+
p->box.pos = rack::Vec(box.size.x / 2, 20);
202+
p->box.size = rack::Vec(box.size.x / 2 - 10, box.size.y - 40);
203+
204+
addChild(p);
205+
134206
#if 0
135207
Vec knobPos = Vec(cr.x + 12, cr.y + 25);
136208
Vec knobCtr = knobPos.plus(Vec(18, 18));

0 commit comments

Comments
 (0)