aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2017-10-16 10:56:53 +0200
committerBert Münnich <ber.t@posteo.de>2017-10-16 10:56:53 +0200
commita5403178e337abeed4168be0cb038a42ab31124c (patch)
tree1f8f157ef44cc58891aecc0fd478ac23468f8baa
parent5155d52ab18c06925046e2f56a87f2765bb515ba (diff)
Zoom into mouse cursor position
-rw-r--r--Makefile2
-rw-r--r--image.c11
2 files changed, 10 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 914b72d..e4a1761 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
# Works best with GNU make 3.80 or later
-VERSION = git-20171012
+VERSION = git-20171016
srcdir = .
diff --git a/image.c b/image.c
index 6ace9bd..5d7f5cf 100644
--- a/image.c
+++ b/image.c
@@ -530,8 +530,15 @@ bool img_zoom(img_t *img, float z)
img->scalemode = SCALE_ZOOM;
if (zoomdiff(z, img->zoom) != 0) {
- img->x = img->win->w / 2 - (img->win->w / 2 - img->x) * z / img->zoom;
- img->y = img->win->h / 2 - (img->win->h / 2 - img->y) * z / img->zoom;
+ int x, y;
+
+ 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->checkpan = true;
img->dirty = true;