Skip to content

Commit

Permalink
Wrap up the Contrast Editor widget (#96)
Browse files Browse the repository at this point in the history
Ready for library really
  • Loading branch information
baconpaul authored Jan 4, 2023
1 parent e7104e2 commit 435d146
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 53 deletions.
56 changes: 35 additions & 21 deletions src/Components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ struct InternalRoundedBorder : virtual TransparentWidget, baconpaul::rackplugs::
{
auto style = baconpaul::rackplugs::BaconStyle::get();
nvgBeginPath(args.vg);
nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, baconpaul::rackplugs::StyleConstants::rectRadius);
nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y,
baconpaul::rackplugs::StyleConstants::rectRadius);
if (doFill)
{
nvgFillColor(args.vg,style->getColor(fillColor));
nvgFillColor(args.vg, style->getColor(fillColor));
nvgFill(args.vg);
}

nvgStrokeColor(args.vg, style->getColor(baconpaul::rackplugs::BaconStyle::SECTION_RULE_LINE));
nvgStrokeColor(args.vg,
style->getColor(baconpaul::rackplugs::BaconStyle::SECTION_RULE_LINE));
nvgStroke(args.vg);
}

Expand All @@ -56,7 +58,8 @@ struct InternalTextLabel : virtual TransparentWidget, baconpaul::rackplugs::Styl

void draw(const DrawArgs &args) override
{
memFont = InternalFontMgr::get(args.vg, baconpaul::rackplugs::BaconStyle::get()->fontName());
memFont =
InternalFontMgr::get(args.vg, baconpaul::rackplugs::BaconStyle::get()->fontName());

auto col = baconpaul::rackplugs::BaconStyle::get()->getColor(color);
nvgBeginPath(args.vg);
Expand All @@ -67,11 +70,9 @@ struct InternalTextLabel : virtual TransparentWidget, baconpaul::rackplugs::Styl
nvgText(args.vg, 0, 0, label.c_str(), NULL);
}

void onStyleChanged() override
{}
void onStyleChanged() override {}
};


struct InternalPlugLabel : virtual TransparentWidget
{
int memFont = -1;
Expand Down Expand Up @@ -145,6 +146,10 @@ void BaconBackground::draw(const DrawArgs &args)
{
x0 = box.size.x - 2 - svgu->handle->width * scaleFactor;
}
if (box.size.x <= 2 * SCREW_WIDTH)
{
x0 = box.size.x * 0.5 - svgu->handle->width * scaleFactor * 0.5;
}

endB = x0 - 2;
startM = x0 + svgu->handle->width * scaleFactor + 2;
Expand All @@ -171,6 +176,9 @@ void BaconBackground::draw(const DrawArgs &args)
nvgTextAlign(args.vg, NVG_ALIGN_LEFT | NVG_ALIGN_BOTTOM);
nvgText(args.vg, startM, box.size.y - 3, "Music", NULL);
}
else if (box.size.x <= 2 * SCREW_WIDTH)
{
}
else
{
nvgBeginPath(args.vg);
Expand Down Expand Up @@ -274,37 +282,43 @@ void InternalPlugLabel::draw(const DrawArgs &args)
{
auto style = baconpaul::rackplugs::BaconStyle::get();
if (memFont < 0)
memFont = InternalFontMgr::get(args.vg, baconpaul::rackplugs::BaconStyle::get()->fontName());
memFont =
InternalFontMgr::get(args.vg, baconpaul::rackplugs::BaconStyle::get()->fontName());

auto txtCol = style->getColor(baconpaul::rackplugs::BaconStyle::DEFAULT_LABEL);
switch (st)
{
case (BaconBackground::SIG_IN):
{
nvgBeginPath(args.vg);
nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, baconpaul::rackplugs::StyleConstants::rectRadius);
NVGpaint vgr = nvgLinearGradient(args.vg, 0, 0, 0, box.size.y,
style->getColor(baconpaul::rackplugs::BaconStyle::INPUT_BG),
style->getColor(baconpaul::rackplugs::BaconStyle::INPUT_BG_END));
nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y,
baconpaul::rackplugs::StyleConstants::rectRadius);
NVGpaint vgr =
nvgLinearGradient(args.vg, 0, 0, 0, box.size.y,
style->getColor(baconpaul::rackplugs::BaconStyle::INPUT_BG),
style->getColor(baconpaul::rackplugs::BaconStyle::INPUT_BG_END));
nvgFillPaint(args.vg, vgr);
nvgFill(args.vg);
nvgStrokeColor(args.vg, style->getColor(baconpaul::rackplugs::BaconStyle::SECTION_RULE_LINE));
nvgStrokeColor(args.vg,
style->getColor(baconpaul::rackplugs::BaconStyle::SECTION_RULE_LINE));
nvgStroke(args.vg);
break;
}
case (BaconBackground::SIG_OUT):
{
nvgBeginPath(args.vg);
nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, baconpaul::rackplugs::StyleConstants::rectRadius);
NVGpaint vgr = nvgLinearGradient(args.vg, 0, 0, 0, box.size.y,
style->getColor(baconpaul::rackplugs::BaconStyle::HIGHLIGHT_BG),
style->getColor(baconpaul::rackplugs::BaconStyle::HIGHLIGHT_BG_END));
nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y,
baconpaul::rackplugs::StyleConstants::rectRadius);
NVGpaint vgr =
nvgLinearGradient(args.vg, 0, 0, 0, box.size.y,
style->getColor(baconpaul::rackplugs::BaconStyle::HIGHLIGHT_BG),
style->getColor(baconpaul::rackplugs::BaconStyle::HIGHLIGHT_BG_END));

nvgFillPaint(args.vg, vgr);
nvgFill(args.vg);


nvgStrokeColor(args.vg, style->getColor(baconpaul::rackplugs::BaconStyle::SECTION_RULE_LINE));
nvgStrokeColor(args.vg,
style->getColor(baconpaul::rackplugs::BaconStyle::SECTION_RULE_LINE));
nvgStroke(args.vg);

txtCol = style->getColor(baconpaul::rackplugs::BaconStyle::DEFAULT_HIGHLIGHT_LABEL);
Expand All @@ -313,7 +327,8 @@ void InternalPlugLabel::draw(const DrawArgs &args)
case (BaconBackground::OTHER):
{
nvgBeginPath(args.vg);
nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, baconpaul::rackplugs::StyleConstants::rectRadius);
nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y,
baconpaul::rackplugs::StyleConstants::rectRadius);
nvgStrokeColor(args.vg, componentlibrary::SCHEME_RED);
nvgStroke(args.vg);
break;
Expand Down Expand Up @@ -354,7 +369,6 @@ BaconBackground *BaconBackground::addRoundedBorder(Vec pos, Vec sz,
return this;
}


BaconBackground::BaconBackground(Vec size, const char *lab) : title(lab)
{
box.pos = Vec(0, 0);
Expand Down
51 changes: 46 additions & 5 deletions src/ContrastBNDEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct ContrastBNDEditorWidget : bp::BaconModuleWidget
q.menuItemTheme.textSelectedColor = nvgRGB(dl, dl, dl);
q.menuItemTheme.innerSelectedColor = nvgRGB(wl, wl, wl);

q.menuTheme.textColor = nvgRGB(0, 0, 20);
q.menuTheme.textColor = nvgRGB(40, 40, 0);
q.menuTheme.innerColor = nvgRGB(dl, dl, dl);
q.menuTheme.textSelectedColor = nvgRGB(dl * 0.9, dl * 0.9, dl);

Expand All @@ -103,7 +103,7 @@ struct ContrastBNDEditorWidget : bp::BaconModuleWidget
q.menuItemTheme.textSelectedColor = nvgRGB(dl, dl, dl);
q.menuItemTheme.innerSelectedColor = nvgRGB(wl, wl, wl);

q.menuTheme.textColor = nvgRGB(wl * 0.95, wl * 0.95, wl);
q.menuTheme.textColor = nvgRGB(245, 245, 210);
q.menuTheme.innerColor = nvgRGB(dl, dl, dl);
q.menuTheme.textSelectedColor = nvgRGB(dl, dl, 20);

Expand All @@ -119,7 +119,7 @@ struct ContrastBNDEditorWidget : bp::BaconModuleWidget
if (c)
{
menu->addChild(new rack::ui::MenuSeparator);
menu->addChild(rack::createMenuLabel("Menu Items"));
menu->addChild(rack::createMenuLabel("Menu and Tooltip Contrast"));
menu->addChild(rack::createMenuItem(
"Default", CHECKMARK(c->colorScheme == ContrastBNDEditor::DEFAULT),
[c]() { c->colorScheme = ContrastBNDEditor::ColorScheme::DEFAULT; }));
Expand Down Expand Up @@ -157,20 +157,61 @@ struct ContrastBNDEditorWidget : bp::BaconModuleWidget
hiDark();
break;
}

if (bdw)
bdw->dirty = true;
}
}
}
Widget::step();
}
BufferedDrawFunctionWidget *bdw{nullptr};
void drawLabel(NVGcontext *vg)
{
nvgSave(vg);
nvgRotate(vg, M_PI_2);

auto memFont =
InternalFontMgr::get(vg, baconpaul::rackplugs::BaconStyle::get()->fontName());
auto labelColor = baconpaul::rackplugs::BaconStyle::get()->getColor(
baconpaul::rackplugs::BaconStyle::DEFAULT_MUTED_LABEL);

nvgBeginPath(vg);
nvgFontFaceId(vg, memFont);
nvgFontSize(vg, 18);
nvgFillColor(vg, labelColor);
nvgTextAlign(vg, NVG_ALIGN_MIDDLE | NVG_ALIGN_LEFT);

auto label = std::string("Menu and ToolTip Contrast: ");
switch (lastScheme)
{
default:
label += "Rack Default";
break;
case ContrastBNDEditor::HICONTRAST_LIGHT:
label += "High Contrast Light";
break;
case ContrastBNDEditor::HICONTRAST_DARK:
label += "High Contrast Dark";
break;
}

nvgText(vg, 5, -box.size.x * 0.45, label.c_str(), nullptr);
nvgRestore(vg);
};
};

ContrastBNDEditorWidget::ContrastBNDEditorWidget(ContrastBNDEditor *model) : bp::BaconModuleWidget()
{
setModule(model);
box.size = Vec(SCREW_WIDTH * 4, RACK_HEIGHT);
box.size = Vec(SCREW_WIDTH * 2, RACK_HEIGHT);

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

bdw = new BufferedDrawFunctionWidget(rack::Vec(0, 25), rack::Vec(box.size.x, box.size.y - 50),
[this](auto *vg) { drawLabel(vg); });
addChild(bdw);
}

Model *modelContrastBNDEditor =
Expand Down
47 changes: 22 additions & 25 deletions src/Style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,22 @@ BaconStyle::BaconStyle()
setStyle(LIGHT);
}
}

}
}

NVGcolor getColorLight(baconpaul::rackplugs::BaconStyle::Colors c)
{
switch(c)
switch (c)
{
case BaconStyle::BG:
return nvgRGB(0xF6, 0xF0, 0xED);
return nvgRGB(0xF6, 0xF0, 0xED);
case BaconStyle::DEFAULT_HIGHLIGHT_LABEL:
case BaconStyle::BG_END:
return nvgRGB(0xF6, 0XF5, 0xF3);
case BaconStyle::DEFAULT_LABEL:
return nvgRGB(10,10,15);
return nvgRGB(10, 10, 15);
case BaconStyle::DEFAULT_MUTED_LABEL:
return nvgRGB(70, 70, 75);

case BaconStyle::INPUT_BG:
return nvgRGB(0xE6, 0xE0, 0xDD);
Expand All @@ -74,70 +75,66 @@ NVGcolor getColorLight(baconpaul::rackplugs::BaconStyle::Colors c)

// fixme - make more wheaty
case BaconStyle::HIGHLIGHT_BG:
return nvgRGB(70,70,100);
return nvgRGB(70, 70, 100);

case BaconStyle::HIGHLIGHT_BG_END:
return nvgRGB(60,60,120);
return nvgRGB(60, 60, 120);

case BaconStyle::SLIDER_NOTCH:
case BaconStyle::SLIDER_SLOT:
return nvgRGB(0,0,40);
return nvgRGB(0, 0, 40);

case BaconStyle::LIGHT_BG:
return nvgRGB(200,200,220);

return nvgRGB(200, 200, 220);
}
return nvgRGBA(255,0,0,255);
return nvgRGBA(255, 0, 0, 255);
}

NVGcolor getColorDark(baconpaul::rackplugs::BaconStyle::Colors c)
{
switch(c)
switch (c)
{
case BaconStyle::BG:
return nvgRGB(50,50,55);
return nvgRGB(50, 50, 55);
case BaconStyle::DEFAULT_HIGHLIGHT_LABEL:
return nvgRGB(0xF0, 0xF0, 0xFF);
case BaconStyle::BG_END:
return nvgRGB(60,60,75);
return nvgRGB(60, 60, 75);
case BaconStyle::DEFAULT_LABEL:
return nvgRGB(0xF0, 0xF0, 0xFF);

case BaconStyle::DEFAULT_MUTED_LABEL:
return nvgRGB(0xC0, 0xC0, 0xCF);

case BaconStyle::INPUT_BG:
return nvgRGB(45, 45, 55);
case BaconStyle::INPUT_BG_END:
return nvgRGB(55, 55, 70);

case BaconStyle::LABEL_BG:
return nvgRGB(20,20,25);
return nvgRGB(20, 20, 25);
case BaconStyle::LABEL_BG_END:
return nvgRGB(25,25,30);
return nvgRGB(25, 25, 30);
case BaconStyle::LABEL_RULE:
case BaconStyle::MODULE_OUTLINE:
return nvgRGB(80,80,90);
return nvgRGB(80, 80, 90);
case BaconStyle::SECTION_RULE_LINE:
return nvgRGB(0xA0, 0xA0, 0xA5);


case BaconStyle::HIGHLIGHT_BG:
return nvgRGB(90, 90, 90);

case BaconStyle::HIGHLIGHT_BG_END:
return nvgRGB(90, 90, 100);


case BaconStyle::SLIDER_NOTCH:
return nvgRGB(120,120,140);
return nvgRGB(120, 120, 140);
case BaconStyle::SLIDER_SLOT:
return nvgRGB(0,0,40);

return nvgRGB(0, 0, 40);

case BaconStyle::LIGHT_BG:
return nvgRGB(20, 20, 30);

}
return nvgRGBA(255,0,0,255);
return nvgRGBA(255, 0, 0, 255);
}

NVGcolor BaconStyle::getColor(baconpaul::rackplugs::BaconStyle::Colors c)
Expand Down Expand Up @@ -166,4 +163,4 @@ void BaconStyle::updateJSON()
json_decref(rootJ);
}

}
} // namespace baconpaul::rackplugs
6 changes: 4 additions & 2 deletions src/Style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ struct BaconStyle
friend struct StyleParticipant;
void notifyStyleListeners();

enum Colors : uint32_t {
enum Colors : uint32_t
{
BG,
BG_END,
DEFAULT_LABEL,
DEFAULT_MUTED_LABEL,
DEFAULT_HIGHLIGHT_LABEL,

LABEL_BG,
Expand Down Expand Up @@ -93,6 +95,6 @@ inline void BaconStyle::notifyStyleListeners()
for (auto l : listeners)
l->onStyleChanged();
}
}
} // namespace baconpaul::rackplugs

#endif // BACONPLUGS_RACK_HACK_STYLE_H

0 comments on commit 435d146

Please sign in to comment.