开发者

Zooming at mouse position without messing up scrollbars?

I'开发者_JAVA百科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


It looks like you need to scale your shift to your current zoom level in the code. So this line:

shift_x = self->zoom_point_x * (self->zoom_level / .9 - self->zoom_level);

Should be:
shift_x = self->zoom_point_x * (self->zoom_level / .9 - self->zoom_level)/(self->zoom_level);

Note that your approximation worked at a zoom level of one but as you move away you either under or overcorrect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜