zoom not a member of rack::settings ?

I’m trying to build the PdArray plugin with the latest v2, I get this error:

src/Array.cpp: In member function ‘virtual void ArrayDisplay::onDragMove(const DragMove&)’:
src/Array.cpp:456:40: error: ‘zoom’ is not a member of ‘rack::settings’
   float zoom = std::pow(2.f, settings::zoom);

The current API tells me that it is a member, so I must be missing something obvious ? Any suggestions ?

The rack zoom level has been removed from global settings, since multiple Rack plugin instances need different zoom levels.

Why would a plugin need to get the rack zoom level…?

Thanks, Andrew. The plugin isn’t mine, I don’t know why it needs the zoom level. I’ll ask the author.

Surprise, I’m modifying zoom, for example in this one:

1 Like

You can get the RackScrollWidget's zoom level with APP->scene->rackScroll->getZoom() and a similar setter. Zoom levels are linear, not exponential like settings::zoom.

Another purpose of zoom I’ve seen plugins use is conditional drawing of fine details to save CPU. For that, plugins should read the NanoVG state in draw() such as

float t[6];
nvgCurrentTransform(args.vg, t);
float zoom = t[3];

Thanks, I‘m reading the commit log on GitHub pretty closely and I noticed these new getters/setters, also the change from exponential to linear :grinning:

Hi, author of PdArray here.

To implement drawing with he mouse for the array, in onDragMove(event::DragMove &e) I need to convert e.mouseDelta into the coordinate system of my widget. If the zoom level is 200%, moving the mouse by 1 pixel corresponds to 2 “pixels” in the widget coordinates. To calculate this, I use e.mouseDelta.div(std::pow(2.f, settings::zoom)) in v1.

Is using APP->scene->rackScroll->getZoom() with the linear scaling the correct way to handle this in v2? I couldn’t find any API function to directly convert between global coordinates and widget coordinates taking the zoom level into account.

I saw that atleast in JW modules XY pad, it’s done by storing the global APP->scene->getMousePos() and calculating all changes relative to that, but I don’t quite understand how the scaling is done there. Voxglitch (in e.g. the XY module) does it the same way I did in v1.

This might help:

For interactions not relating to NanoVG drawing (where you’d want to rely on NanoVG state), you can call getAbsoluteZoom() to get the zoom level of the current widget relative to the global scene.

Thanks! Both APP->scene->rackScroll->getZoom() and getAbsoluteZoom() seems to work well. And also looks like the onDragHover solution suggested in the above thread could work (I somehow didn’t realize that onDragHover is also called while dragging, although it’s right there in the name).

I went with getAbsoluteZoom(), because that feels the simplest. I didn’t quite understand what it does based on the documentation, I would have expected it to always return 1 for my widget.

Absolute zoom is the zoom level relative to the scene’s root. If you called getRelativeZoom(this), that would return 1 because your zoom relative to yourself is always 1.

1 Like