Zoom into mouse cursor position

This commit is contained in:
Bert Münnich 2017-10-16 10:56:53 +02:00
parent 5155d52ab1
commit a5403178e3
2 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,6 @@
# Works best with GNU make 3.80 or later # Works best with GNU make 3.80 or later
VERSION = git-20171012 VERSION = git-20171016
srcdir = . srcdir = .

11
image.c
View File

@ -530,8 +530,15 @@ bool img_zoom(img_t *img, float z)
img->scalemode = SCALE_ZOOM; img->scalemode = SCALE_ZOOM;
if (zoomdiff(z, img->zoom) != 0) { if (zoomdiff(z, img->zoom) != 0) {
img->x = img->win->w / 2 - (img->win->w / 2 - img->x) * z / img->zoom; int x, y;
img->y = img->win->h / 2 - (img->win->h / 2 - img->y) * z / img->zoom;
win_cursor_pos(img->win, &x, &y);
if (x < 0 || x >= img->win->w || y < 0 || y >= img->win->h) {
x = img->win->w / 2;
y = img->win->h / 2;
}
img->x = x - (x - img->x) * z / img->zoom;
img->y = y - (y - img->y) * z / img->zoom;
img->zoom = z; img->zoom = z;
img->checkpan = true; img->checkpan = true;
img->dirty = true; img->dirty = true;