Does anyone off hand have a reference for an LED widget (ideally RGB) where part of the widget is completely opaque (as defined by an SVG e.g. above). Also let’s assume the opaqing SVG is complex enough to make reproducing with custom nvg commands impossible. I’ve needed to do this in a few different contexts previously and always struggled. As a hardware example of the sort of thing I’m talking about see Caster & Pollux (below) (this is not actually what I’m working on just an example ). What I’ve attempted is creating an SVG with transparency where I want light to pass like so:
If the LED has two states, the way I obtain similar results to what I think you want is by switching frames. (Hydra and Gegenees).
If you want RGB, the way I did it for my Dungeon module (that has a massive multicolored and gradiented moon that changes color according to the held voltage) and the way I think Instruo did it for their S&H module is to draw the SVG yourself. You can use gradients to make it prettier and you can even halo it, if you desire and you can use any and all rgb colors you want. It may not be the best approach but it works for me. I guess another approach would be this:
The light is composed of two layers: a background and a foreground.
The background is the “off” or dark part (and is drawn on the regular draw call).
The foreground is an svg without the parts you want to be dark, so the background shows and is, in effect not glowing, the foreground is drawn in drawLayer.
So, the mask is inverted: you draw what you want lit and use that to mask what you want unlit in the background. This approach can be haloed as well.
If the first two approaches make sense, you can look here at SanguineLightUpSwitch and SanguineMultiColoredShapedLight. SanguineShapedLight kind of cheats like the third approach above: the “off” state is part of the faceplate.
SanguineLightUpSwitch is used quite extensively in the modules in that collection, for example superswitch18.cpp. The big light up moon is in use in dungeon.cpp.
So if I rip out svgDraw from Rack/src/window/Svg.cpp, and replace the part that fills the SVG with the SVG defined color with a fill to use the Light object’s color, then it works! In the following, mySvgDraw is a modified version of Rack/src/window/Svg.cpp svgDraw.
That’s a solid flag in the ground, and great to have something working. However I’m keen to find a more cleaner / more idomatic way to do this so I’ll keep looking and report in this thread if I find it. Thanks all so far.
As I was thinking about this in the shower, I realised modifying SVG colour on the fly would make things much easier and lo and behold when I came back you posted exact code, thanks!
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.