aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2015-11-09 23:45:34 +0000
committerHarry Jeffery <harry@exec64.co.uk>2015-11-09 23:45:34 +0000
commitcedaf52814022806b37500ec9a19a487a4f0d33a (patch)
tree4927204f8d23de456fdba1895f1ada456911f5b1 /main.c
parent99d16ae8d06e92a59639ba3bcb1c56e8b76f775e (diff)
downloadimv-cedaf52814022806b37500ec9a19a487a4f0d33a.tar.gz
Improve view centering
Diffstat (limited to 'main.c')
-rw-r--r--main.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/main.c b/main.c
index 198d871..2b73f8c 100644
--- a/main.c
+++ b/main.c
@@ -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;
}