aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2009-02-16 23:35:05 -0800
committerJohn Hawthorn <jhawthor@uvic.ca>2009-02-16 23:35:05 -0800
commit7ef59ee989938c85e9cd3890c70e83309c9bf442 (patch)
tree9798ab712eac81967d61f55fe5eb198a4e1dd1d0 /src
parent23b19c4213dfb780f1a2a1ca3ea05b34aed2dbc1 (diff)
downloadmirror-meh-7ef59ee989938c85e9cd3890c70e83309c9bf442.tar.gz
mirror-meh-7ef59ee989938c85e9cd3890c70e83309c9bf442.tar.bz2
mirror-meh-7ef59ee989938c85e9cd3890c70e83309c9bf442.zip
switched to using state to keep track of image
Diffstat (limited to 'src')
-rw-r--r--src/main.c45
-rw-r--r--src/meh.h18
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;
};