Creating a custom SVG masked RGB LED

For completeness, this is what the final thing looks like (stock halo will be round but that’s fine for my use case). This naturally uses the color as defined for the RGB light (including the alpha channel, which the surge example didn’t need to use). For my use case, I have the background (led off state) on the panel itself though would be easy to generalise to include in the struct itself.

struct MyLed : TSvgLight<RedGreenBlueLight> {

	MyLed() {		
		this->setSvg(Svg::load(asset::plugin(pluginInstance, "res/components/my_led.svg")));		

	}

	void draw(const DrawArgs& args) override {}
	void drawLayer(const DrawArgs& args, int layer) override {
		if (layer == 1) {

			if (!sw->svg)
				return;

			if (module && !module->isBypassed()) {

				for (auto s = sw->svg->handle->shapes; s; s = s->next) {
					s->fill.color = ((int)(color.a * 255) << 24) + (((int)(color.b * 255)) << 16) + (((int)(color.g * 255)) << 8) + (int)(color.r * 255);
					s->fill.type = NSVG_PAINT_COLOR;
				}

				nvgGlobalCompositeBlendFunc(args.vg, NVG_ONE_MINUS_DST_COLOR, NVG_ONE);
				svgDraw(args.vg, sw->svg->handle);
				drawHalo(args);
			}
		}
		Widget::drawLayer(args, layer);
	}
};

Thanks all for the help!

5 Likes