diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2015-11-09 23:45:34 +0000 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2015-11-09 23:45:34 +0000 |
commit | cedaf52814022806b37500ec9a19a487a4f0d33a (patch) | |
tree | 4927204f8d23de456fdba1895f1ada456911f5b1 /main.c | |
parent | 99d16ae8d06e92a59639ba3bcb1c56e8b76f775e (diff) | |
download | imv-cedaf52814022806b37500ec9a19a487a4f0d33a.tar.gz |
Improve view centering
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -112,6 +112,15 @@ void zoom_view(int amount) g_view.redraw = 1; } +void center_view() +{ + int wx, wy; + SDL_GetWindowSize(g_window, &wx, &wy); + g_view.x = (wx - g_img.width * g_view.scale) / 2; + g_view.y = (wy - g_img.height * g_view.scale) / 2; + g_view.redraw = 1; +} + void scale_to_window() { int ww, wh; @@ -127,8 +136,7 @@ void scale_to_window() g_view.scale = (double)ww/(double)g_img.width; } //Also center image - g_view.x = 0; - g_view.y = 0; + center_view(); g_view.redraw = 1; } |