Browse Source

Add SegmentDisplay to component library. Fix huge light halo issue with non-square lights.

tags/v1.1.5
Andrew Belt 5 years ago
parent
commit
f68a981d11
2 changed files with 56 additions and 2 deletions
  1. +54
    -0
      include/componentlibrary.hpp
  2. +2
    -2
      src/app/LightWidget.cpp

+ 54
- 0
include/componentlibrary.hpp View File

@@ -635,6 +635,20 @@ struct CL1362Port : app::SvgPort {
// Switches
////////////////////

template <typename TSwitch>
struct LatchingSwitch : TSwitch {
LatchingSwitch() {
this->momentary = false;
}
};

template <typename TSwitch>
struct MomentarySwitch : TSwitch {
MomentarySwitch() {
this->momentary = true;
}
};

struct NKK : app::SvgSwitch {
NKK() {
addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/NKK_0.svg")));
@@ -745,6 +759,46 @@ struct ScrewBlack : app::SvgScrew {
}
};

struct SegmentDisplay : widget::Widget {
int lightsLen = 0;
bool vertical = false;
float margin = app::mm2px(0.5);

void draw(const DrawArgs& args) override {
// Background
nvgBeginPath(args.vg);
nvgRect(args.vg, 0, 0, box.size.x, box.size.y);
nvgFillColor(args.vg, color::BLACK);
nvgFill(args.vg);
Widget::draw(args);
}

template <typename TLightBase = WhiteLight>
void setLights(engine::Module* module, int firstLightId, int lightsLen) {
clearChildren();
this->lightsLen = lightsLen;
float r = (vertical ? box.size.y : box.size.x) - margin;
for (int i = 0; i < lightsLen; i++) {
float p = float(i) / lightsLen;
app::ModuleLightWidget* light = new RectangleLight<TLightBase>;
if (vertical) {
light->box.pos.y = p * r + margin;
light->box.size.y = r / lightsLen - margin;
light->box.size.x = box.size.x;
}
else {
light->box.pos.x = p * r + margin;
light->box.size.x = r / lightsLen - margin;
light->box.size.y = box.size.y;
}
light->module = module;
light->firstLightId = firstLightId;
firstLightId += light->baseColors.size();
addChild(light);
}
}
};


} // namespace componentlibrary
} // namespace rack

+ 2
- 2
src/app/LightWidget.cpp View File

@@ -12,7 +12,7 @@ void LightWidget::draw(const DrawArgs& args) {
}

void LightWidget::drawLight(const DrawArgs& args) {
float radius = box.size.x / 2.0;
float radius = std::min(box.size.x, box.size.y) / 2.0;

nvgBeginPath(args.vg);
nvgCircle(args.vg, radius, radius, radius);
@@ -38,7 +38,7 @@ void LightWidget::drawLight(const DrawArgs& args) {
}

void LightWidget::drawHalo(const DrawArgs& args) {
float radius = box.size.x / 2.0;
float radius = std::min(box.size.x, box.size.y) / 2.0;
float oradius = 4.0 * radius;

nvgBeginPath(args.vg);


Loading…
Cancel
Save