aboutsummaryrefslogtreecommitdiff
path: root/src/viewport.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2015-11-11 18:06:28 +0000
committerHarry Jeffery <harry@exec64.co.uk>2015-11-11 18:12:05 +0000
commit2df8dcd7b1362456c13ec62798c0538e42e79ca0 (patch)
treefa9f7027bfcdec0c46d49dfadc2179b7093ef667 /src/viewport.c
parent12f6a47b9e42f0841c5b14e8994fac8d6f18988b (diff)
downloadimv-2df8dcd7b1362456c13ec62798c0538e42e79ca0.tar.gz
Improve zooming behaviour
Diffstat (limited to 'src/viewport.c')
-rw-r--r--src/viewport.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/viewport.c b/src/viewport.c
index 5e29a47..5a7621b 100644
--- a/src/viewport.c
+++ b/src/viewport.c
@@ -82,10 +82,17 @@ void imv_viewport_zoom(struct imv_viewport *view, const struct imv_image *img, e
/* Translate mouse coordinates to projected coordinates */
x -= view->x;
y -= view->y;
- } else x = y = 0;
+ } else {
+ x = 0;
+ y = 0;
+ }
- int scaledWidth = img->width * view->scale;
- int scaledHeight = img->height * view->scale;
+ const int scaledWidth = img->width * view->scale;
+ const int scaledHeight = img->height * view->scale;
+ const int ic_x = view->x + scaledWidth/2;
+ const int ic_y = view->y + scaledHeight/2;
+ const int wc_x = ww/2;
+ const int wc_y = wh/2;
view->scale += amount * 0.1;
if(view->scale > 100)
@@ -93,16 +100,24 @@ void imv_viewport_zoom(struct imv_viewport *view, const struct imv_image *img, e
else if (view->scale < 0.01)
view->scale = 0.1;
- /*
- if(amount < 0 && ww > scaledWidth - view->x) {
- }
-
- if(amount < 0 && wh > scaledHeight - view->y) {
+ if(view->scale < prevScale) {
+ if(scaledWidth < ww) {
+ x = scaledWidth/2 - (ic_x - wc_x)*2;
+ }
+ if(scaledHeight < wh) {
+ y = scaledHeight/2 - (ic_y - wc_y)*2;
+ }
+ } else {
+ if(scaledWidth < ww) {
+ x = scaledWidth/2;
+ }
+ if(scaledHeight < wh) {
+ y = scaledHeight/2;
+ }
}
- */
- double changeX = x - (x * (view->scale / prevScale));
- double changeY = y - (y * (view->scale / prevScale));
+ const double changeX = x - (x * (view->scale / prevScale));
+ const double changeY = y - (y * (view->scale / prevScale));
view->x += changeX;
view->y += changeY;