aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2015-11-09 14:33:39 +0000
committerHarry Jeffery <harry@exec64.co.uk>2015-11-09 14:33:39 +0000
commit984f35cb724b3d298c75a857a4deec4183cd7a72 (patch)
treea640c0511148ed58d7af22e47b605763b94c27eb /main.c
parent6df6d18a31c74db3677a2dfd8bc3ecfda45dd6a2 (diff)
downloadimv-984f35cb724b3d298c75a857a4deec4183cd7a72.tar.gz
Add 's' hotkey to scale image to fit window
Diffstat (limited to 'main.c')
-rw-r--r--main.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/main.c b/main.c
index 13a0334..b24b159 100644
--- a/main.c
+++ b/main.c
@@ -90,13 +90,30 @@ void move_view(int x, int y)
void zoom_view(int amount)
{
g_view.scale += amount * 0.1;
- if(g_view.scale > 10)
+ if(g_view.scale > 100)
g_view.scale = 10;
- else if (g_view.scale < 0.1)
+ else if (g_view.scale < 0.01)
g_view.scale = 0.1;
g_view.redraw = 1;
}
+void scale_to_window()
+{
+ int ww, wh;
+ SDL_GetWindowSize(g_window, &ww, &wh);
+ double window_aspect = (double)ww/(double)wh;
+ double image_aspect = (double)g_img.width/(double)g_img.height;
+
+ if(window_aspect > image_aspect) {
+ //Image will become too tall before it becomes too wide
+ g_view.scale = (double)wh/(double)g_img.height;
+ } else {
+ //Image will become too wide before it becomes too tall
+ g_view.scale = (double)ww/(double)g_img.width;
+ }
+ g_view.redraw = 1;
+}
+
void add_path(const char* path)
{
struct loop_item_s *new_path =
@@ -362,6 +379,7 @@ int main(int argc, char** argv)
case SDLK_f: toggle_fullscreen(); break;
case SDLK_PERIOD: next_frame(); break;
case SDLK_SPACE: toggle_playing(); break;
+ case SDLK_s: scale_to_window(); break;
}
break;
case SDL_MOUSEWHEEL: