Hello! I’m stuck on a simple problem and could use a second set of eyes. This is for my Groovebox module. I’m refactoring how some of the code is organized. I’ve created a class called “LCDWidget”, which is a TransparentWidget, which all the other LCDWidget displays inherit from:
Both the RatchetDisplay and SampleDisplay widgets have a drawLayer method that looks something like this:
void drawLayer(const DrawArgs &args, int layer) override
{
if (layer == 1)
{
TransparentWidget::draw(args);
const auto vg = args.vg;
if (module)
{
nvgSave(vg);
// draw stuff here
The TrackDisplay widget is a little bit different. It doesn’t have a draw method. Instead, it’s essentially a container for other widgets and adds them in the constructor, using code like:
for (unsigned int i = 0; i < NUMBER_OF_TRACKS; i++)
{
// x and y are computed here
// then...
TrackLabelDisplay *track_label_display = new TrackLabelDisplay(i, track_label_width, track_label_height);
track_label_display->setPosition(Vec(x, y));
track_label_display->module = module;
addChild(track_label_display);
What I’m trying to do next is have the base class, LCDWidget, draw the background of the display so that I don’t repeat that code in all of the child widgets. I don’t wish to add the background directly to the module’s SVG panel because I’m adding the ability to change the color of the background, so it must be drawn separately.
Any suggestions? I tried adding a draw() method in the base class, but it didn’t work and would sometimes crash rack. Maybe I was doing it wrong?
Thanks!