Skip to content

Commit

Permalink
Test widget
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul committed Jan 29, 2024
1 parent 67cc7d4 commit cc7fcfc
Showing 1 changed file with 75 additions and 3 deletions.
78 changes: 75 additions & 3 deletions src/BaconTestModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,90 @@ struct BaconTestWidget : bp::BaconModuleWidget
BaconTestWidget(BaconTest *model);
};

struct PolyWidget : public rack::Widget
{
int64_t dc{0};
void draw(const DrawArgs &args) override {
auto s = box.size;

auto vg = args.vg;

auto dcm = dc % (int)(s.x - 40);

nvgBeginPath(vg);
nvgFillColor(vg, nvgRGB(255,0,0));
nvgRect(vg, dcm, dcm, 40 , 40);
nvgFill(vg);

typedef std::vector<std::pair<float, float>> poly_t;
std::vector<poly_t> polys;

std::map<poly_t, NVGcolor> colm;
for (int nsides = 3; nsides < 11; ++nsides)
{
poly_t p;
for (auto i = 0; i < nsides; ++i)
{
auto x = std::sin(-i * 2.0 * M_PI / nsides) + 1;
auto y = std::cos(i * 2.0 * M_PI / nsides) + 1;
p.emplace_back(x, y);
}
polys.push_back(p);
auto idx = nsides - 3;
colm[p] = nvgRGB((255 - dcm * 20) * (idx < 5), idx * 15, dcm * 20);
}

int idx = 0;
for (auto &poly : polys)
{
auto first{true};
nvgBeginPath(vg);
for (const auto &[x,y] : poly)
{
if (first)
{
nvgMoveTo(vg, 15 * x + dcm, 15 * y + dcm + 40 + idx * 18);
}
else
{
nvgLineTo(vg, 15 * x + dcm, 15 * y + dcm + 40 + idx * 18);
}
first = false;
}
nvgClosePath(vg);
// nvgFillColor(vg, nvgRGB((255 - dcm * 20) * (idx < 5), idx * 15, dcm * 20));
nvgFillColor(vg, colm[poly]);
nvgFill(vg);
nvgStrokeColor(vg, nvgRGB(0,0,50));
nvgStroke(vg);
idx ++;
}

dc++;
}
};

BaconTestWidget::BaconTestWidget(BaconTest *model)
{
setModule(model);
box.size = Vec(SCREW_WIDTH * 8, RACK_HEIGHT);
box.size = Vec(SCREW_WIDTH * 15, RACK_HEIGHT);

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

auto layoutSize = box.size;
layoutSize.x /= 2;

Vec cr(5, 35);
auto dSp = (box.size.x - 10) / BaconTest::nPorts;
auto dSp = (layoutSize.x - 10) / BaconTest::nPorts;
for (int i = 0; i < BaconTest::nPorts; ++i)
{
addInput(createInput<PJ301MPort>(cr, module, BaconTest::INPUT_0 + i));
cr.x += dSp;
}

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

auto p = new PolyWidget();
p->box.pos = rack::Vec(box.size.x / 2, 20);
p->box.size = rack::Vec(box.size.x / 2 - 10, box.size.y - 40);

addChild(p);

#if 0
Vec knobPos = Vec(cr.x + 12, cr.y + 25);
Vec knobCtr = knobPos.plus(Vec(18, 18));
Expand Down

0 comments on commit cc7fcfc

Please sign in to comment.