diff options
author | rodri <rgl@antares-labs.eu> | 2020-07-01 21:44:44 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2020-07-01 21:44:44 +0000 |
commit | bfacf5a78ddf09baa32c8d6c23d2dfb89d59c15d (patch) | |
tree | a0e3be0418d8859b4097043105907095174f440d | |
parent | 26c7bae49165a78f3e58e0dd45244c8942a1fe22 (diff) | |
download | puppeteer-master.tar.gz puppeteer-master.tar.bz2 puppeteer-master.zip |
add better brush color management. fix issues with procrfork. replace procexecl with execl.HEADmaster
fclamp is now part of libgeometry so get rid of it.
-rw-r--r-- | color.c | 24 | ||||
-rw-r--r-- | dat.h | 7 | ||||
-rw-r--r-- | fns.h | 5 | ||||
-rw-r--r-- | main.c | 17 | ||||
-rw-r--r-- | mkfile | 1 | ||||
-rw-r--r-- | utils.c | 6 |
6 files changed, 45 insertions, 15 deletions
@@ -0,0 +1,24 @@ +#include <u.h> +#include <libc.h> +#include <draw.h> +#include <geometry.h> +#include "dat.h" +#include "fns.h" + +Color* +newcolor(ulong col) +{ + Color *c; + + c = emalloc(sizeof(Color)); + c->v = col; + c->i = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, col); + return c; +} + +void +rmcolor(Color *c) +{ + freeimage(c->i); + free(c); +} @@ -9,11 +9,18 @@ enum { MAXZOOM = 8 }; +typedef struct Color Color; typedef struct Layer Layer; typedef struct Canvas Canvas; typedef struct HUD HUD; typedef struct HUDWidget HUDWidget; +struct Color +{ + ulong v; + Image *i; +}; + struct Layer { RFrame; @@ -13,7 +13,10 @@ Layer *getlayer(Canvas*, char*); Layer *newlayer(char*, Rectangle, ulong); void rmlayer(Layer*); +/* color */ +Color *newcolor(ulong); +void rmcolor(Color*); + /* utils */ int clamp(int, int, int); -double fclamp(double, double, double); int alphachan(ulong); @@ -16,7 +16,7 @@ enum { RFrame worldrf; Image *background; Canvas *curcanvas; -Image *brushcolor; +Color *brushcolor; Image *pal[NCOLOR]; int zoom = 1; @@ -235,7 +235,7 @@ pickerproc(void *arg) snprint(mntdesc, sizeof mntdesc, "-pid %d -dx %d -dy %d", getpid(), 384, 320); newwindow(mntdesc); - procexecl(nil, "/bin/picker", "picker", "-e", nil); + execl("/bin/picker", "picker", "-e", nil); threadexits("procexecl: %r"); } @@ -323,9 +323,9 @@ rmb(Mousectl *mc, Keyboardctl *kc) case SETCOLOR: if(pipe(pfd) < 0) sysfatal("pipe: %r"); - procrfork(pickerproc, pfd, 4096, RFFDG|RFNAMEG); + procrfork(pickerproc, pfd, 4096, RFFDG|RFNAMEG|RFNOTEG); close(pfd[0]); - fprint(pfd[1], "0 %08ux\n", 0x000000ff); + fprint(pfd[1], "0 %08ulx\n", brushcolor->v); n = read(pfd[1], buf, sizeof(buf)-1); close(pfd[1]); if(n < 0) @@ -334,7 +334,8 @@ rmb(Mousectl *mc, Keyboardctl *kc) s = buf; while(*s && *s++ != '\t') ; - brushcolor = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, strtoul(s, nil, 16)); + rmcolor(brushcolor); + brushcolor = newcolor(strtoul(s, nil, 16)); break; case SAVE: if(curcanvas == nil) @@ -401,7 +402,7 @@ lmb(Mousectl *mc, Keyboardctl *) mpos = rframexform(mpos, *curcanvas); p = Pt(mpos.x,mpos.y); - draw(curcanvas->curlayer->image, rectaddpt(r, p), brushcolor, nil, ZP); + draw(curcanvas->curlayer->image, rectaddpt(r, p), brushcolor->i, nil, ZP); redraw(); for(;;){ oldp = p; @@ -415,7 +416,7 @@ lmb(Mousectl *mc, Keyboardctl *) p = Pt(mpos.x,mpos.y); if(eqpt(p, oldp)) continue; - line(curcanvas->curlayer->image, oldp, p, Endsquare, Endsquare, 0, brushcolor, ZP); + line(curcanvas->curlayer->image, oldp, p, Endsquare, Endsquare, 0, brushcolor->i, ZP); redraw(); } } @@ -499,7 +500,7 @@ threadmain(int argc, char *argv[]) worldrf.by = Vec2(0,1); initpalette(); background = mkcheckerboard(4, 4); - brushcolor = pal[PCBlack]; + brushcolor = newcolor(DBlack); display->locking = 1; unlockdisplay(display); @@ -6,6 +6,7 @@ OFILES=\ utils.$O\ hud.$O\ alloc.$O\ + color.$O\ layer.$O\ canvas.$O\ main.$O\ @@ -8,12 +8,6 @@ clamp(int n, int min, int max) return n < min? min: n > max? max: n; } -double -fclamp(double n, double min, double max) -{ - return n < min? min: n > max? max: n; -} - int alphachan(ulong chan) { |