I'm creating an image editing program in GTK\C, and I can't figure out how to make zoom work; I need to zoom my Cairo-based canvas to the mouse cursor's position, but Cairo only zooms to center of the image it displays. The normal way to get around this is to transform, zoom, and then transform back; but that messes up the scrollbars surrounding my canvas.
My idea was to slide the scrollbars back to compensate for the movement caused by zooming. Moving the scrollbars by mouse_position * (new_zoom - old_zoom)
ought to work, but it doesn't; it under-corrects at low zoom levels, then over-corrects at high levels.
How can I zoom correctly?
My code is visible here, if it helps: ScreenSnap on Github