aboutsummaryrefslogtreecommitdiff
path: root/src/viewport.c
diff options
context:
space:
mode:
authorJose Diez <jose.manuel.diez@gmail.com>2015-11-11 17:21:24 +0000
committerHarry Jeffery <harry@exec64.co.uk>2015-11-11 18:12:05 +0000
commit12f6a47b9e42f0841c5b14e8994fac8d6f18988b (patch)
tree247a959fb314509ffc4c2c683e1fb081e25991ef /src/viewport.c
parentc05412208dd658935ca1126691f0346a558ec425 (diff)
downloadimv-12f6a47b9e42f0841c5b14e8994fac8d6f18988b.tar.gz
Zoom into things
Diffstat (limited to 'src/viewport.c')
-rw-r--r--src/viewport.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/viewport.c b/src/viewport.c
index c3fd9e2..5e29a47 100644
--- a/src/viewport.c
+++ b/src/viewport.c
@@ -74,7 +74,8 @@ void imv_viewport_move(struct imv_viewport *view, int x, int y)
void imv_viewport_zoom(struct imv_viewport *view, const struct imv_image *img, enum imv_zoom_source src, int amount)
{
double prevScale = view->scale;
- int x, y;
+ int x, y, ww, wh;
+ SDL_GetWindowSize(view->window, &ww, &wh);
if(src == MOUSE) {
SDL_GetMouseState(&x, &y);
@@ -85,13 +86,6 @@ void imv_viewport_zoom(struct imv_viewport *view, const struct imv_image *img, e
int scaledWidth = img->width * view->scale;
int scaledHeight = img->height * view->scale;
- if(x > scaledWidth || x < view->x) {
- x = scaledWidth / 2;
- }
-
- if(y > scaledHeight || view->y) {
- y = scaledHeight / 2;
- }
view->scale += amount * 0.1;
if(view->scale > 100)
@@ -99,18 +93,19 @@ 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) {
+ }
+ */
+
double changeX = x - (x * (view->scale / prevScale));
double changeY = y - (y * (view->scale / prevScale));
- if(amount < 0 &&
- (view->x <= 0 && (view->x + changeX > 0 || !changeX))) {
- view->x = 0;
- } else view->x += changeX;
-
- if(amount < 0 &&
- (view->y <= 0 && (view->y + changeY > 0 || !changeY))) {
- view->y = 0;
- } else view->y += changeY;
+ view->x += changeX;
+ view->y += changeY;
view->redraw = 1;
view->locked = 1;