diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2017-08-06 20:15:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-06 20:15:05 +0100 |
commit | 167f1280ce974247dfce30dac840f4b3130bd12d (patch) | |
tree | 7a9dcc420a109d01166b5857dc75148a539dae31 /src/viewport.c | |
parent | cf0baaa9778b842c4d2ed3c2f560906bce800eb9 (diff) | |
parent | 69cc94ef23ea2b11c65a4c06e5e17aaea95a973e (diff) | |
download | imv-167f1280ce974247dfce30dac840f4b3130bd12d.tar.gz |
Merge pull request #112 from SirCmpwn/limit_scrolling
Prevent scrolling images indefinitely off-screen
Diffstat (limited to 'src/viewport.c')
-rw-r--r-- | src/viewport.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/viewport.c b/src/viewport.c index d096a45..036749f 100644 --- a/src/viewport.c +++ b/src/viewport.c @@ -57,12 +57,29 @@ void imv_viewport_scale_to_actual(struct imv_viewport *view, const struct imv_te imv_viewport_center(view, tex); } -void imv_viewport_move(struct imv_viewport *view, int x, int y) +void imv_viewport_move(struct imv_viewport *view, int x, int y, + const struct imv_texture *tex) { view->x += x; view->y += y; view->redraw = 1; view->locked = 1; + int w = (int)((double)tex->width * view->scale); + int h = (int)((double)tex->height * view->scale); + int ww, wh; + SDL_GetWindowSize(view->window, &ww, &wh); + if (view->x < -w) { + view->x = -w; + } + if (view->x > ww) { + view->x = ww; + } + if (view->y < -h) { + view->y = -h; + } + if (view->y > wh) { + view->y = wh; + } } void imv_viewport_zoom(struct imv_viewport *view, const struct imv_texture *tex, enum imv_zoom_source src, int amount) |