zoom scrolledwindow whilst keepPointInPlace

I want to improve my zoom function on a scrolled window so that it stays viewing the same object as I zoom.

It’s presumably something like the ZoomWithMouseWheel ‘keepPointInPlace’ feature of floatcanvas, but I’m not using floatwindow - just a plain old OGL canvas (ScrolledWindow) and setting the virtualcanvas with a call to ScrolledWindow.SetScrollbars(…noUnitsX, noUnitsY…) where I multiply noUnitsX and noUnitsY by my ScrolledWindow.scalex and scaley values to achieve the proper virtualcanvas size in response to the zoom. The zoom and virtual canvas setting all works fine.

Can anyone suggest a suitable algorithm to achieve a more ‘keepPointInPlace’ zoom? I tried setting the scrollbar positions in the call to SetScrollbars(…xPos, yPos…) to retain the same relative scrollbar positions before and after the zoom, which helps - but OGL shape objects in the scrolled window are still drifting slowly out of view after a few zoom increments.

I suspect I need to do something with GetViewStart() or something? I can create a short code sample if needed, but some initial ideas would be helpful.

Andy

PyNSource - Python UML tool

well, you could take a look at the FloatCanvas code

(https://github.com/wxWidgets/wxPython/blob/master/wx/lib/floatcanvas/FloatCanvas.py#L3040)

– though it’s pretty simple, due to features that FloatCanvas already has, like:

self.MoveImage(-delta, ‘world’)

that “world” is pretty handy :slight_smile:

I’m not familiar with OGL, but you may be able to do something similar. The trick is to figure out where the mouse is relative to the main coordinates, (or the center point of the window) and then call SetScrollbars to make sure it’s in the same place.

-CHB

···

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov