From 7ef59ee989938c85e9cd3890c70e83309c9bf442 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 16 Feb 2009 23:35:05 -0800 Subject: switched to using state to keep track of image --- src/main.c | 45 ++++++++++++++++++++------------------------- src/meh.h | 18 +++++++++--------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/main.c b/src/main.c index 9519e77..49b4cef 100644 --- a/src/main.c +++ b/src/main.c @@ -50,7 +50,6 @@ struct image *newimage(FILE *f){ if((img = (*fmt)->open(f))){ img->fmt = *fmt; img->ximg = NULL; - img->redraw = 1; img->state = NONE; return img; } @@ -133,11 +132,10 @@ void handleevent(XEvent *event){ if(img->ximg) XDestroyImage(img->ximg); img->ximg = NULL; - img->redraw = 1; - if(img->state == LINEARDRAWN) - img->state = LINEAR; - else if(img->state == BILINEARDRAWN) - img->state = BILINEAR; + if(img->state >= LOADED) + img->state = LOADED; + else if(img->state > FASTLOADED) + img->state = FASTLOADED; } /* Some window managers need reminding */ @@ -147,11 +145,10 @@ void handleevent(XEvent *event){ break; case Expose: if(img){ - img->redraw = 1; - if(img->state == LINEARDRAWN) - img->state = LINEAR; - else if(img->state == BILINEARDRAWN) - img->state = BILINEAR; + if(img->state >= LOADED) + img->state = LOADED; + else if(img->state > FASTLOADED) + img->state = FASTLOADED; } break; case KeyPress: @@ -192,8 +189,6 @@ int doredraw(struct image **i){ if((*i = imageopen2(images[imageidx]))){ break; } - if(mode == MODE_CTL) - return 0; direction(); if(imageidx == firstimg){ fprintf(stderr, "No valid images to view\n"); @@ -211,18 +206,19 @@ int doredraw(struct image **i){ } TDEBUG_END("read") (*i)->fmt->close(*i); - return 1; + (*i)->state = LOADED; }else if(width && height){ - if(!(*i)->ximg){ + imgstate state = (*i)->state; + if(state == LOADED){ (*i)->ximg = getimage(*i, width, height); - return 1; - }else if((*i)->redraw){ /* TODO */ + (*i)->state = SCALED; + }else if(state == SCALED){ + assert((*i)->ximg); drawimage((*i)->ximg, width, height); - (*i)->redraw = 0; - return 1; + (*i)->state = DRAWN; } } - return 0; + return (*i)->state != DRAWN; } void run(){ @@ -266,11 +262,10 @@ void run(){ }while(XPending(display)); }else if(ret == 0){ if(mode == MODE_CTL && images[0] == NULL){ - tv = NULL; - }else if(!img || img->state != BILINEARDRAWN){ - if(!doredraw(&img)){ - tv = NULL; - } + tv = NULL; + }else if(!doredraw(&img)){ + /* If we get here everything has been drawn in full or we need more input to continue */ + tv = NULL; } } } diff --git a/src/meh.h b/src/meh.h index 7d62347..a17d730 100644 --- a/src/meh.h +++ b/src/meh.h @@ -13,20 +13,20 @@ struct imageformat{ typedef enum{ NONE, - IMG, - ALLOC, - LINEAR, - LINEARDRAWN, - BILINEAR, - BILINEARDRAWN, -} drawstate; + FASTLOADED, + FASTSCALED, + FASTDRAWN, + LOADED, + SCALED, + DRAWN, + NOOP +} imgstate; struct image{ unsigned char *buf; unsigned int bufwidth, bufheight; struct imageformat *fmt; - int redraw; - drawstate state; + imgstate state; XImage *ximg; }; -- cgit v1.2.3