aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2017-06-06 20:08:46 +0100
committerHarry Jeffery <harry@exec64.co.uk>2017-06-06 20:08:46 +0100
commit973fe152b5e98ca4e75af41284b00193157043c4 (patch)
treebd1bc7d829f87639305f809b6a534dbdde2b15e2 /src
parent2fbe6678c2a1e8ecc8ed8835d7fa94a70196978a (diff)
downloadimv-973fe152b5e98ca4e75af41284b00193157043c4.tar.gz
Fix animated gif / slideshow support
Diffstat (limited to 'src')
-rw-r--r--src/imv.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/imv.c b/src/imv.c
index 578010d..8a510ce 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -339,6 +339,10 @@ bool imv_run(struct imv *imv)
int iw = 0;
int ih = 0;
+ /* time keeping */
+ unsigned int last_time = SDL_GetTicks();
+ unsigned int current_time;
+
while(!imv->quit) {
SDL_Event e;
@@ -421,6 +425,36 @@ bool imv_run(struct imv *imv)
}
}
+ /* tell the loader time has passed (for gifs) */
+ current_time = SDL_GetTicks();
+
+ /* if we're playing an animated gif, tell the loader how much time has
+ * passed */
+ if(imv->view->playing) {
+ unsigned int dt = current_time - last_time;
+ /* We cap the delta-time to 100 ms so that if imv is asleep for several
+ * seconds or more (e.g. suspended), upon waking up it doesn't try to
+ * catch up all the time it missed by playing through the gif quickly. */
+ if(dt > 100) {
+ dt = 100;
+ }
+ imv_loader_time_passed(imv->loader, dt / 1000.0);
+ }
+
+ /* handle slideshow */
+ if(imv->slideshow_image_duration != 0) {
+ unsigned int dt = current_time - last_time;
+
+ imv->slideshow_time_elapsed += dt;
+ imv->need_redraw = true; /* need to update display */
+ if(imv->slideshow_time_elapsed >= imv->slideshow_image_duration) {
+ imv_navigator_select_rel(imv->navigator, 1);
+ imv->slideshow_time_elapsed = 0;
+ }
+ }
+
+ last_time = current_time;
+
/* check if the viewport needs a redraw */
if(imv_viewport_needs_redraw(imv->view)) {