diff options
author | rsc <devnull@localhost> | 2004-04-24 16:59:47 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2004-04-24 16:59:47 +0000 |
commit | 3f8c70e97c2eb85992424439af56a4dd6412b8c6 (patch) | |
tree | 085330cec19cac9be912bfd67cea5e97a669ec53 | |
parent | e2713e92abdfd2ac5359f5756ffff112e1069c78 (diff) | |
download | plan9port-3f8c70e97c2eb85992424439af56a4dd6412b8c6.tar.gz plan9port-3f8c70e97c2eb85992424439af56a4dd6412b8c6.tar.bz2 plan9port-3f8c70e97c2eb85992424439af56a4dd6412b8c6.zip |
a simple plan 9 image viewer
-rw-r--r-- | src/cmd/draw/img.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/cmd/draw/img.c b/src/cmd/draw/img.c new file mode 100644 index 00000000..b46bcf34 --- /dev/null +++ b/src/cmd/draw/img.c @@ -0,0 +1,63 @@ +#include <u.h> +#include <libc.h> +#include <draw.h> +#include <event.h> + +void +usage(void) +{ + fprint(2, "usage: img [file]\n"); + exits("usage"); +} + +Image *image; + +void +eresized(int new) +{ + if(new && getwindow(display, Refnone) < 0) + sysfatal("can't reattach to window: %r"); + + draw(screen, screen->r, display->white, nil, ZP); + drawop(screen, screen->r, image, nil, image->r.min, S); +} + +void +main(int argc, char **argv) +{ + int fd; + Event e; + + ARGBEGIN{ + default: + usage(); + }ARGEND + + if(argc > 1) + usage(); + + if(argc == 1){ + if((fd = open(argv[0], OREAD)) < 0) + sysfatal("open %s: %r"); + }else + fd = 0; + + if(initdraw(nil, nil, nil) < 0) + sysfatal("initdraw: %r"); + + if((image=readimage(display, fd, 0)) == nil) + sysfatal("readimage: %r"); + + einit(Emouse|Ekeyboard); + eresized(0); + for(;;){ + switch(event(&e)){ + case Ekeyboard: + if(e.kbdc == 'q' || e.kbdc == 0x7F) + exits(nil); + break; + case Emouse: + break; + } + } +} |