I am probably expecting too much from NanoVG here, but does anyone know if it is possible to draw lines of different colours in a single path?
I want the lines to be the same path so that they are connected and respect the nvgLineJoin
property, but I would like the lines to be different colours.
Here is what I am currently at code-wise:
rack::math::Vec panelTL{rack::math::Vec(0.0f, 0.0f)};
rack::math::Vec panelBR{rack::math::Vec(widget->box.size.x, widget->box.size.y)};
rack::math::Vec borderTL{rack::math::Vec(panelTL.x + 2.5f, panelTL.y + 2.5f)};
rack::math::Vec borderBR{rack::math::Vec(panelBR.x - 2.5f, panelBR.y - 2.5f)};
nvgSave(vg);
nvgBeginPath(vg);
nvgRect(vg, panelTL.x, panelTL.y, panelBR.x, panelBR.y);
nvgFillColor(vg, panelColour);
nvgFill(vg);
nvgStrokeWidth(vg, 5.0f);
nvgMoveTo(vg, borderTL.x, borderTL.y);
nvgLineTo(vg, borderBR.x, borderTL.y);
nvgStrokeColor(vg, borderColourT);
nvgStroke(vg);
nvgLineTo(vg, borderBR.x, borderBR.y);
nvgStrokeColor(vg, borderColourR);
nvgStroke(vg);
nvgLineTo(vg, borderTL.x, borderBR.y);
nvgStrokeColor(vg, borderColourB);
nvgStroke(vg);
nvgLineTo(vg, borderTL.x, borderTL.y);
nvgStrokeColor(vg, borderColourL);
nvgStroke(vg);
nvgRestore(vg);
This doesn’t work because the final call to nvgStroke
applies the last set nvgStrokeColor
to all the lines.
I have achieved the four lines being different colours by using multiple nvgBeginPath
and nvgClosePath
, but this is also not correct, because the lines are not joined (you will have to excuse the ugly debug colour choice )