diff options
author | Sebastian Parborg <darkdefende@gmail.com> | 2019-08-25 13:58:49 +0200 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2019-08-25 21:35:15 +0100 |
commit | 498c35c28831cf89cc60a773a5c2513c97bc08a3 (patch) | |
tree | a706d16e5deaf2019d24830269986d437a61300b /src/imv.c | |
parent | cd67aca62d1c1169bb35e580e3f4d9ddf708235d (diff) | |
download | imv-498c35c28831cf89cc60a773a5c2513c97bc08a3.tar.gz |
Added crop scaling method
Added a method that scales and crop the image so that the image will
fill the whole window.
Also made viewport update respect the current scaling mode.
Diffstat (limited to 'src/imv.c')
-rw-r--r-- | src/imv.c | 29 |
1 files changed, 9 insertions, 20 deletions
@@ -29,17 +29,11 @@ #define PATH_MAX 4096 #endif -enum scaling_mode { - SCALING_NONE, - SCALING_DOWN, - SCALING_FULL, - SCALING_MODE_COUNT -}; - static const char *scaling_label[] = { "actual size", "shrink to fit", - "scale to fit" + "scale to fit", + "crop" }; enum background_type { @@ -435,7 +429,7 @@ static void event_handler(void *data, const struct imv_event *e) const int wh = e->data.resize.height; const int bw = e->data.resize.buffer_width; const int bh = e->data.resize.buffer_height; - imv_viewport_update(imv->view, ww, wh, bw, bh, imv->current_image); + imv_viewport_update(imv->view, ww, wh, bw, bh, imv->current_image, imv->scaling_mode); imv_canvas_resize(imv->canvas, bw, bh); break; } @@ -651,6 +645,11 @@ static bool parse_scaling_mode(struct imv *imv, const char *mode) return true; } + if (!strcmp(mode, "crop")) { + imv->scaling_mode = SCALING_CROP; + return true; + } + if (!strcmp(mode, "none")) { imv->scaling_mode = SCALING_NONE; return true; @@ -960,18 +959,8 @@ int imv_run(struct imv *imv) } if (imv->need_rescale) { - int ww, wh; - imv_window_get_size(imv->window, &ww, &wh); - imv->need_rescale = false; - if (imv->scaling_mode == SCALING_NONE || - (imv->scaling_mode == SCALING_DOWN - && ww > imv_image_width(imv->current_image) - && wh > imv_image_height(imv->current_image))) { - imv_viewport_scale_to_actual(imv->view, imv->current_image); - } else { - imv_viewport_scale_to_window(imv->view, imv->current_image); - } + imv_viewport_rescale(imv->view, imv->current_image, imv->scaling_mode); } current_time = cur_time(); |