Is it possible to load a static panel image?

Thanks. But, to be clear, I am not trying to embed bitmaps in SVG files here.

If you know the panel size and background color, you could not bother with the SVG at all. Is it your intention that the svg file might vary?

Since your png capable widget has to draw a rectangle and fill it with the png texture. It could also have a background color property. Fill with a solid color, and then fill with the png texture.

1 Like

Rather than open up a new topic, I’ll ask this here as it is part of this topic.

How is loadImage() intended to be used? Is it compatible with nanoVG through the image handle member. The return type is Image. Image has a “handle” attribute.

Yes, I haven’t decided what I will end up. It somewhat depends on what I get working. For right now I am just leaving the SVG in place as an easy way to define the panel size. The background in the SVG is not really needed.

Yes, the handle member of Image, is the value that nanovg uses. The same as with Font.

1 Like

Here’s how I use a PNG as a panel with loadImage and nvgImagePattern in the MSM experimental oscillator

1 Like

Thanks for a working model example. But, I’m doing exactly what you are doing and it crashes Rack. Obviously, must not be “exactly”. I should be able to figure it out.

Crashes are almost always issues with dereferencing null pointers. Notice how I only pass a string to the panel with the image file path and actually loadImage inside draw() (a requirement in V2) and I always verify that the pointer is not null around a call that dereferences it. You might want to load your plugin into GDB. It makes finding those misbehaving little buggers much easier.

MSM does this for the VCO panels.

Declared here: MSM-vcvrack-plugin/MSMComponentLibrary.hpp at da38052ab9bc846a7d0ed40471a39f943bef89c2 ¡ netboy3/MSM-vcvrack-plugin ¡ GitHub

Usage in widget: MSM-vcvrack-plugin/ExperimentalVCO.cpp at da38052ab9bc846a7d0ed40471a39f943bef89c2 ¡ netboy3/MSM-vcvrack-plugin ¡ GitHub

1 Like

Good points, but in this case the crash was caused by me commenting some code out incorrectly where a curly bracket got missed. I’m not even sure how it compiled without error.

Thanks, I’ll take a look. This will make 4 working examples for me to reference.

I’ve quoted the same code that netboy did, for some reason I didn’t see those posts. Never mind.

That’s okay. I realized it was a repeat, after I wrote my reference to “4” examples.

I now have the static PNG images displaying on the panel so I have a proof of concept and now need to flesh this all out. The static images should only render when in the module browser.

If you copy the code from the widget, along with the header code, you shouldn’t get any crashes.

1 Like

The more the merrier! :slightly_smiling_face:

2 Likes

I should note here that I ended up using the loadImage() functionality which in the end is almost trivial to get working with nanoVG since no other “bitmap” functionality has to be added. Care does have to be given to not caching the image and checking for image pointer validity before using it. So, it all works just like loadFont(), more or less.

My development version of Meander now draws the panel procedurally as long as there is a module. If there is not a module (e.g. in the browser), it loads and draws a static PNG file which is a screen capture of the executing Meander panel for both light and dark themes.

This will simplify my code where I currently have to do some procedural drawing even in the browser view.

2 Likes

Turns out Rack renders paramWidgets, lightWidgets and portWidgets last, perhaps in a layer(?). As a result, after I render my static PNG file image as the panel image, Rack renders all of the above widgets on top of the panel image “layer” . This makes sense for using image files rather than SVG files, but makes less sense for what I am doing by only rendering the static PNG image when in the browser.

This is a subtle result since the widgets align with the panel image and it is working fine except for that.

Does anyone know if I can suppress the rendering of the above widgets if my module is null? I see some mention of “layers” here in the development discussions, but I cannot find anything in the API documentation.

In that case, surely you don’t need to attach your paramWidgets, lightWidgets or portWidgets if you are in the browser.

1 Like

If you really want to add them as children, but not show them, they probably have a visible property. But it would be easier not to add them in the first place.

1 Like