Krolyxon
Commit 79b8fef

Branches

Refs →

nsxiv79b8fef

bring back zoom_levels (#156)

this still keeps the shorter zoom logic, but adds back the zoom_levels
array so that stay close to sxiv.

for users who would like to have the zoom step behavior see:
https://github.com/nsxiv/nsxiv/pull/156#issuecomment-975182631
Author
N-R-K
Date
2021-12-01 18:27 +0600
Committer
GitHub · 2021-12-01 12:27 +0000
Parent
5e0b715
Commit
79b8fefcc45d6279c28505ab3d07f539fb9726ff

+18 −6

2 files changed

  1. M config.def.h +7 −4
  2. M image.c +11 −2
M config.def.h View
@@ -32,10 +32,13 @@ static const suffixmode_t TITLE_SUFFIXMODE = SUFFIX_BASENAME;
3232 #endif
3333 #ifdef _IMAGE_CONFIG
3434
35−/* zoom level of 1.0 means 100% */
36−static const float ZOOM_MIN = 0.01;
37−static const float ZOOM_MAX = 20.0;
38−static const float ZOOM_STEP = 1.2599210498948732; /* 2^(1/3) */
35+/* levels (in percent) to use when zooming via '-' and '+':
36+ * (first/last value is used as min/max zoom level)
37+ */
38+static const float zoom_levels[] = {
39+ 12.5, 25.0, 50.0, 75.0,
40+ 100.0, 150.0, 200.0, 400.0, 800.0
41+};
3942
4043 /* default slideshow delay (in sec, overwritten via -S option): */
4144 static const int SLIDESHOW_DELAY = 5;
M image.c View
@@ -43,6 +43,9 @@ enum { DEF_GIF_DELAY = 75 };
4343 enum { DEF_WEBP_DELAY = 75 };
4444 #endif
4545
46+static const float ZOOM_MIN = zoom_levels[0] / 100;
47+static const float ZOOM_MAX = zoom_levels[ARRLEN(zoom_levels)-1] / 100;
48+
4649 void img_init(img_t *img, win_t *win)
4750 {
4851 imlib_context_set_display(win->env.dpy);
@@ -699,8 +702,14 @@ bool img_zoom_to(img_t *img, float z)
699702
700703 bool img_zoom(img_t *img, int d)
701704 {
702− const float z = img->zoom * (d > 0 ? ZOOM_STEP : 1/ZOOM_STEP);
703− return img_zoom_to(img, z);
705+ int i = d > 0 ? 0 : ARRLEN(zoom_levels)-1;
706+ while (i >= 0 && i < ARRLEN(zoom_levels) && (d > 0 ?
707+ zoom_levels[i]/100 <= img->zoom : zoom_levels[i]/100 >= img->zoom))
708+ {
709+ i += d;
710+ }
711+ i = MIN(MAX(i, 0), ARRLEN(zoom_levels)-1);
712+ return img_zoom_to(img, zoom_levels[i]/100);
704713 }
705714
706715 bool img_pos(img_t *img, float x, float y)