diff options
author | stanley lieber <stanley.lieber@gmail.com> | 2012-02-27 20:15:37 -0600 |
---|---|---|
committer | stanley lieber <stanley.lieber@gmail.com> | 2012-02-27 20:15:37 -0600 |
commit | cb3fdfb70fef1a06e902e1993e9f09774acc4238 (patch) | |
tree | d3f64ae677fa4819fe0d402fd514370aa206e99b /sys/src/cmd/paint.c | |
parent | cbb83c4fcee19d89d7b4927dcad734af02d24f24 (diff) |
paint: open existing files for editing
Diffstat (limited to 'sys/src/cmd/paint.c')
-rw-r--r-- | sys/src/cmd/paint.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/sys/src/cmd/paint.c b/sys/src/cmd/paint.c index f09a597c0..46c89608f 100644 --- a/sys/src/cmd/paint.c +++ b/sys/src/cmd/paint.c @@ -10,6 +10,22 @@ eresized(int) sysfatal("resize failed"); } +void +loadimg(char *name) +{ + Image *b; + int fd; + + fd=open(name, OREAD); + if(fd==-1) + sysfatal("can't open file"); + if((b=readimage(display, fd, 0)) == nil) + sysfatal("can't read image"); + draw(screen, screen->r, b, 0, b->r.min); + flushimage(display, 1); + close(fd); +} + /* stolen from mothra */ void screendump(char *name, int full) @@ -35,7 +51,7 @@ screendump(char *name, int full) } void -main() +main(int argc, char *argv[]) { Event e; Point last; @@ -52,6 +68,23 @@ main() einit(Emouse | Ekeyboard); draw(screen, screen->r, display->white, 0, ZP); flushimage(display, 1); + + ARGBEGIN{ + default: + goto Usage; + }ARGEND + switch(argc){ + default: + Usage: + fprint(2, "Usage: [file]\n"); + exits("usage"); + case 0: + break; + case 1: + loadimg(argv[0]); + break; + } + while(1){ switch(event(&e)){ case Emouse: @@ -79,6 +112,11 @@ main() } if(e.kbdc == 'c') draw(screen, screen->r, display->white, 0, ZP); + if(e.kbdc == 'o'){ + if(eenter("Open file", file, sizeof(file), &e.mouse) <= 0) + break; + loadimg(file); + } if(e.kbdc == 'q') exits(nil); if(e.kbdc == 's'){ |