diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2015-11-09 14:33:39 +0000 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2015-11-09 14:33:39 +0000 |
commit | 984f35cb724b3d298c75a857a4deec4183cd7a72 (patch) | |
tree | a640c0511148ed58d7af22e47b605763b94c27eb /main.c | |
parent | 6df6d18a31c74db3677a2dfd8bc3ecfda45dd6a2 (diff) | |
download | imv-984f35cb724b3d298c75a857a4deec4183cd7a72.tar.gz |
Add 's' hotkey to scale image to fit window
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -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: |