diff options
author | rodri <rgl@antares-labs.eu> | 2020-06-13 21:35:02 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2020-06-13 21:35:02 +0000 |
commit | e3e16e2fb021b61e45b01113cb1654cd7e4911c6 (patch) | |
tree | 0cdacaf28fd552a137b2e4ea70d5af003bcdee55 | |
parent | 0b0726f3a990ee241fd93b5c3f53631bfbb4c455 (diff) | |
download | puppeteer-e3e16e2fb021b61e45b01113cb1654cd7e4911c6.tar.gz puppeteer-e3e16e2fb021b61e45b01113cb1654cd7e4911c6.tar.bz2 puppeteer-e3e16e2fb021b61e45b01113cb1654cd7e4911c6.zip |
added basic canvas and layer management.
-rw-r--r-- | canvas.c | 30 | ||||
-rw-r--r-- | dat.h | 13 | ||||
-rw-r--r-- | layer.c | 26 | ||||
-rw-r--r-- | main.c | 44 |
4 files changed, 106 insertions, 7 deletions
diff --git a/canvas.c b/canvas.c new file mode 100644 index 0000000..a017fb0 --- /dev/null +++ b/canvas.c @@ -0,0 +1,30 @@ +#include <u.h> +#include <libc.h> +#include <draw.h> +#include <geometry.h> +#include "dat.h" +#include "fns.h" + +static int +alphachan(ulong chan) +{ + for(; chan; chan >>= 8) + if(TYPE(chan) == CAlpha) + return 1; + return 0; +} + +Canvas* +newcanvas(Point2 p, Rectangle r, ulong chan) +{ + Canvas *c; + + c = emalloc(sizeof(Canvas)); + c->p = p; + c->bx = Vec2(1,0); + c->by = Vec2(0,1); + c->image = eallocimage(display, r, chan, 0, alphachan(chan)? DTransparent: DNofill); + memset(&c->layers, 0, sizeof(Layer)); + c->layers.next = &c->layers; + c->layers.prev = &c->layers; +} @@ -1,7 +1,16 @@ typedef struct Layer Layer; +typedef struct Canvas Canvas; struct Layer { - RFrame rf; - Image *canvas; + RFrame; + Image *image; + Layer *prev, *next; +}; + +struct Canvas +{ + RFrame; + Image *image; + Layer layers; }; @@ -2,4 +2,30 @@ #include <libc.h> #include <draw.h> #include <geometry.h> +#include "dat.h" +#include "fns.h" +Layer* +newlayer(Canvas *c) +{ + Layer *l; + + l = emalloc(sizeof(Layer)); + l->p = Pt2(0,0,1); + l->bx = c->bx; + l->by = c->by; + l->image = eallocimage(display, c->image->r, c->image->chan, 0, DNofill); + l->prev = c->layers.prev; + l->next = &c->layers; + c->layers.prev->next = l; + c->layers.prev = l; +} + +void +rmlayer(Layer *l) +{ + l->prev->next = l->next; + l->next->prev = l->prev; + freeimage(l->image); + free(l); +} @@ -8,14 +8,17 @@ #include "dat.h" #include "fns.h" +/* palette colors */ enum { - CBlack, - CWhite, + PCBlack, + PCWhite, NCOLOR }; RFrame worldrf; Image *pal[NCOLOR]; +Image *background; +Canvas *curcanvas; Point toscreen(Point2 p) @@ -33,15 +36,46 @@ fromscreen(Point p) void initpalette(void) { - pal[CBlack] = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, DBlack); - pal[CWhite] = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, DWhite); + pal[PCBlack] = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, DBlack); + pal[PCWhite] = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, DWhite); +} + +Image* +gencheckerboard(int w, int h) +{ + Image *i, *dark, *light; + int x, y; + + i = eallocimage(display, Rect(0,0,2*w,2*h), screen->chan, 1, DNofill); + dark = eallocimage(display, Rect(0,0,w,h), screen->chan, 0, DBlack&~0x7f); + light = eallocimage(display, Rect(0,0,w,h), screen->chan, 0, DBlack&~0xdf); + + for(y = 0; y < h; y += h) + for(x = 0; x < w; x += w) + draw(i, Rect(x,y,x+w,y+h), (x+y) % 2? light: dark, ZP); + + freeimage(dark); + freeimage(light); + return i; +} + +void +drawlayer(Canvas *c, Layer *l) +{ + draw(c->image, c->image->r, l->image, nil, ZP); +} + +void +drawcanvas(Canvas *c) +{ + } void redraw(void) { lockdisplay(display); - draw(screen, screen->r, pal[CBlack], nil, ZP); + draw(screen, screen->r, pal[PCBlack], nil, ZP); flushimage(display, 1); unlockdisplay(display); } |