8 Image *colors[NCOLORS];
13 if(getwindow(display, Refnone) < 0)
14 sysfatal("resize failed");
23 if((fd = open(name, OREAD)) < 0)
25 if((b = readimage(display, fd, 0)) == nil){
29 draw(screen, screen->r, b, 0, b->r.min);
30 flushimage(display, 1);
41 if((fd = create(name, OWRITE|OTRUNC, 0666)) < 0)
43 writeimage(fd, screen, 0);
49 main(int argc, char *argv[])
62 if(initdraw(0, 0, "paint") < 0){
63 fprint(2, "paint: initdraw failed: %r\n");
66 einit(Emouse | Ekeyboard);
67 draw(screen, screen->r, display->white, 0, ZP);
68 flushimage(display, 1);
70 colors[0] = display->black;
71 colors[1] = display->white;
72 colors[2] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DRed);
73 colors[3] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreen);
74 colors[4] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DBlue);
75 colors[5] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DYellow);
84 fprint(2, "Usage: [file]\n");
89 strncpy(file, argv[0], sizeof(argv[0]));
98 if(e.mouse.buttons & 1){
100 line(screen, last, e.mouse.xy, Enddisc, Enddisc, b, colors[c], ZP);
102 fillellipse(screen, e.mouse.xy, b, b, colors[c], ZP);
105 flushimage(display, 1);
111 if(eenter("Brush", brush, sizeof(brush), &e.mouse) <= 0)
116 if(eenter("Color", color, sizeof(color), &e.mouse) <= 0)
119 if(cn >= 0 && cn < NCOLORS)
123 if(eenter("Fill", fill, sizeof(fill), &e.mouse) <= 0)
126 if(f >= 0 && f < NCOLORS)
127 draw(screen, screen->r, colors[f], 0, ZP);
130 if(eenter("Open file", file, sizeof(file), &e.mouse) <= 0)
132 if(loadimg(file) < 0){
133 rerrstr(file, sizeof(file));
134 eenter(file, 0, 0, &e.mouse);
140 if(eenter("Save to", file, sizeof(file), &e.mouse) <= 0)
142 if(saveimg(file) < 0){
143 rerrstr(file, sizeof(file));
144 eenter(file, 0, 0, &e.mouse);