V2 problem with custom drawn area (extends LightWidget)

Hi, I’m porting my plugin to V2, but on the CyclicCA module where I draw the cellular automata on the central part of the module, I get the first frame with correct colors (e.g. when I reload the .vcv patch), but then the whole area becomes “almost white”.

ca

This is an excerpt of the code:

struct CyclicCADisplay : LightWidget {   // class extends LightWidget (is it ok in V2?)
...
    img = nvgCreateImageRGBA(vg, DISPLAY_WIDTH, DISPLAY_HEIGHT, 0, pimg );  // the image buffer (pimg is a pointer to the "pixels" array
...
    void drawLight(const DrawArgs &args) override {
        ...
        int w = DISPLAY_WIDTH;
        int h = DISPLAY_HEIGHT;
        nvgBeginPath(vg);
        NVGpaint imgPaint = nvgImagePattern(vg, x, y, w,h, 0, img, 1.0f);
        nvgRect(vg, x, y, w, h);
        nvgFillPaint(vg, imgPaint);
        nvgFill(vg);   
        ...
    }
...

I’m not a C++ expert and found the above technique on another module. Is LightWidget the correct superclass ?

Thanks in advance!

No, you can just subclass Widget. LightWidget is for LEDs/bulbs, not LCD screens.

See Migrating v1 Plugins to v2 - VCV Rack Manual if you want your widget to appear at full brightness when the room brightness is turned down.

1 Like