Added command to toggle gif animations

This commit is contained in:
Bert 2011-08-19 18:46:17 +02:00
parent 8b3ae5027e
commit bb577d274d
5 changed files with 38 additions and 18 deletions

View File

@ -41,7 +41,7 @@ extern int filecnt, fileidx;
extern int timo_cursor; extern int timo_cursor;
extern int timo_redraw; extern int timo_redraw;
extern int timo_delay; extern int timo_adelay;
int it_quit(arg_t a) { int it_quit(arg_t a) {
cleanup(); cleanup();
@ -149,7 +149,24 @@ int it_last(arg_t a) {
} }
int i_navigate_frame(arg_t a) { int i_navigate_frame(arg_t a) {
if (mode == MODE_IMAGE && !img.multi.animate)
return img_frame_navigate(&img, (int) a); return img_frame_navigate(&img, (int) a);
else
return 0;
}
int i_toggle_animation(arg_t a) {
if (mode != MODE_IMAGE)
return 0;
if (img.multi.animate) {
timo_adelay = 0;
img.multi.animate = 0;
return 0;
} else {
timo_adelay = img_frame_animate(&img, 1);
return 1;
}
} }
int it_move(arg_t a) { int it_move(arg_t a) {
@ -239,6 +256,7 @@ int i_zoom(arg_t a) {
if (mode != MODE_IMAGE) if (mode != MODE_IMAGE)
return 0; return 0;
if (scale > 0) if (scale > 0)
return img_zoom_in(&img, &win); return img_zoom_in(&img, &win);
else if (scale < 0) else if (scale < 0)

View File

@ -48,6 +48,7 @@ int i_navigate(arg_t);
int it_first(arg_t); int it_first(arg_t);
int it_last(arg_t); int it_last(arg_t);
int i_navigate_frame(arg_t); int i_navigate_frame(arg_t);
int i_toggle_animation(arg_t);
int it_move(arg_t); int it_move(arg_t);
int i_pan_screen(arg_t); int i_pan_screen(arg_t);
int i_pan_edge(arg_t); int i_pan_edge(arg_t);

View File

@ -29,7 +29,7 @@ static const float zoom_levels[] = {
100.0, 150.0, 200.0, 400.0, 800.0 100.0, 150.0, 200.0, 400.0, 800.0
}; };
/* default settings for gif images: */ /* default settings for multi-frame gif images: */
enum { enum {
GIF_DELAY = 100, /* delay time (in ms) */ GIF_DELAY = 100, /* delay time (in ms) */
GIF_AUTOPLAY = 1, /* autoplay when loaded [0/1] */ GIF_AUTOPLAY = 1, /* autoplay when loaded [0/1] */
@ -64,8 +64,9 @@ static const keymap_t keys[] = {
{ False, XK_g, it_first, (arg_t) None }, { False, XK_g, it_first, (arg_t) None },
{ False, XK_G, it_last, (arg_t) None }, { False, XK_G, it_last, (arg_t) None },
{ False, XK_N, i_navigate_frame, (arg_t) +1 }, { True, XK_n, i_navigate_frame, (arg_t) +1 },
{ False, XK_P, i_navigate_frame, (arg_t) -1 }, { True, XK_p, i_navigate_frame, (arg_t) -1 },
{ True, XK_space, i_toggle_animation, (arg_t) None },
{ False, XK_h, it_move, (arg_t) DIR_LEFT }, { False, XK_h, it_move, (arg_t) DIR_LEFT },
{ False, XK_Left, it_move, (arg_t) DIR_LEFT }, { False, XK_Left, it_move, (arg_t) DIR_LEFT },

16
image.c
View File

@ -596,22 +596,18 @@ int img_frame_animate(img_t *img, int restart) {
if (!img || !img->multi.cnt) if (!img || !img->multi.cnt)
return 0; return 0;
if (!img->multi.animate && !restart) if (img->multi.sel + 1 >= img->multi.cnt) {
return 0; if (restart || GIF_LOOP) {
if (restart) {
img_frame_goto(img, 0); img_frame_goto(img, 0);
img->multi.animate = 1; } else {
} else if (img->multi.sel + 1 >= img->multi.cnt) {
if (!GIF_LOOP) {
img->multi.animate = 0; img->multi.animate = 0;
return 0; return 0;
} else {
img_frame_goto(img, 0);
} }
} else { } else if (!restart) {
img_frame_goto(img, img->multi.sel + 1); img_frame_goto(img, img->multi.sel + 1);
} }
img->multi.animate = 1;
return img->multi.frames[img->multi.sel].delay; return img->multi.frames[img->multi.sel].delay;
} }

6
main.c
View File

@ -142,8 +142,12 @@ void load_image(int new) {
else else
filesize = 0; filesize = 0;
if (img.multi.cnt && img.multi.animate) if (img.multi.cnt) {
if (img.multi.animate)
timo_adelay = img.multi.frames[img.multi.sel].delay; timo_adelay = img.multi.frames[img.multi.sel].delay;
else
timo_adelay = 0;
}
} }
void update_title() { void update_title() {