diff options
author | stanley lieber <stanley.lieber@gmail.com> | 2011-10-31 19:39:52 -0500 |
---|---|---|
committer | stanley lieber <stanley.lieber@gmail.com> | 2011-10-31 19:39:52 -0500 |
commit | 13bbe20922d7ca310ea85329225b430fd735cc46 (patch) | |
tree | 3012ce599de47b72a710865b0fae5625672fd5d8 /sys/src | |
parent | 17e170a42df6bb7580008788d8cfbcf113d891a9 (diff) |
add paint(1)
Diffstat (limited to 'sys/src')
-rw-r--r-- | sys/src/cmd/paint.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/sys/src/cmd/paint.c b/sys/src/cmd/paint.c new file mode 100644 index 000000000..dee0f07c2 --- /dev/null +++ b/sys/src/cmd/paint.c @@ -0,0 +1,83 @@ +#include <u.h> +#include <libc.h> +#include <draw.h> +#include <event.h> + +void +eresized(int) +{ + if(getwindow(display, Refnone) < 0) + sysfatal("resize failed"); +} + +/* stolen from mothra */ +void +screendump(char *name, int full) +{ + Image *b; + int fd; + + fd=create(name, OWRITE|OTRUNC, 0666); + if(fd==-1) + sysfatal("can't create file"); + if(full){ + writeimage(fd, screen, 0); + } else { + if((b=allocimage(display, screen->r, screen->chan, 0, DNofill)) == nil){ + close(fd); + sysfatal("can't allocate image"); + } + draw(b, b->r, screen, 0, b->r.min); + writeimage(fd, b, 0); + freeimage(b); + } + close(fd); +} + +void +main() +{ + Event e; + Point last; + int haslast; + char file[128]; + + haslast = 0; + initdraw(0, 0, 0); + einit(Emouse | Ekeyboard); + draw(screen, screen->r, display->white, 0, ZP); + flushimage(display, 1); + while(1){ + switch(event(&e)){ + case Emouse: + if(e.mouse.buttons & 1){ + if(haslast) + line(screen, last, e.mouse.xy, Enddisc, Enddisc, 5, display->black, ZP); + else + fillellipse(screen, e.mouse.xy, 5, 5, display->black, ZP); + + last = e.mouse.xy; + haslast = 1; + flushimage(display, 1); + } else + haslast = 0; + if(e.mouse.buttons & 4){ + fillellipse(screen, e.mouse.xy, 5, 5, display->white, ZP); + flushimage(display, 1); + } + break; + case Ekeyboard: + if(e.kbdc == 'q') + exits(nil); + if(e.kbdc == 'c') + draw(screen, screen->r, display->white, 0, ZP); + if(e.kbdc == 's'){ + snprint(file, sizeof(file), "out.bit"); + if(eenter("Save to", file, sizeof(file), &e.mouse) <= 0) + break; + screendump(file, 0); + } + break; + } + } +} |