aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2020-06-12 21:57:48 +0000
committerrodri <rgl@antares-labs.eu>2020-06-12 21:57:48 +0000
commit0b0726f3a990ee241fd93b5c3f53631bfbb4c455 (patch)
tree72942206518cf8f2da7ed1b744077d4a5343fa29
parent60bbfc0e2353b834409ecefd10ae3985f5cbf111 (diff)
downloadpuppeteer-0b0726f3a990ee241fd93b5c3f53631bfbb4c455.tar.gz
puppeteer-0b0726f3a990ee241fd93b5c3f53631bfbb4c455.tar.bz2
puppeteer-0b0726f3a990ee241fd93b5c3f53631bfbb4c455.zip
layout done. implemented some error-checking wrappers and started work on layers.
-rw-r--r--alloc.c44
-rw-r--r--dat.h7
-rw-r--r--fns.h3
-rw-r--r--layer.c5
-rw-r--r--main.c114
-rw-r--r--mkfile20
6 files changed, 193 insertions, 0 deletions
diff --git a/alloc.c b/alloc.c
new file mode 100644
index 0000000..2589e89
--- /dev/null
+++ b/alloc.c
@@ -0,0 +1,44 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+
+void*
+emalloc(ulong n)
+{
+ void *p;
+
+ p = malloc(n);
+ if(p == nil)
+ sysfatal("malloc: %r");
+ setmalloctag(p, getcallerpc(&n));
+ return p;
+}
+
+void*
+erealloc(void *p, ulong n)
+{
+ void *np;
+
+ np = realloc(p, n);
+ if(np == nil){
+ if(n == 0)
+ return nil;
+ sysfatal("realloc: %r");
+ }
+ if(p == nil)
+ setmalloctag(np, getcallerpc(&p));
+ else
+ setrealloctag(np, getcallerpc(&p));
+ return np;
+}
+
+Image*
+eallocimage(Display *d, Rectangle r, ulong chan, int repl, ulong col)
+{
+ Image *i;
+
+ i = allocimage(d, r, chan, repl, col);
+ if(i == nil)
+ sysfatal("allocimage: %r");
+ return i;
+}
diff --git a/dat.h b/dat.h
new file mode 100644
index 0000000..5426da9
--- /dev/null
+++ b/dat.h
@@ -0,0 +1,7 @@
+typedef struct Layer Layer;
+
+struct Layer
+{
+ RFrame rf;
+ Image *canvas;
+};
diff --git a/fns.h b/fns.h
new file mode 100644
index 0000000..ece9b68
--- /dev/null
+++ b/fns.h
@@ -0,0 +1,3 @@
+void *emalloc(ulong);
+void *erealloc(void*, ulong);
+Image *eallocimage(Display*, Rectangle, ulong, int, ulong);
diff --git a/layer.c b/layer.c
new file mode 100644
index 0000000..5673183
--- /dev/null
+++ b/layer.c
@@ -0,0 +1,5 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <geometry.h>
+
diff --git a/main.c b/main.c
index 42c2869..67b2832 100644
--- a/main.c
+++ b/main.c
@@ -4,6 +4,74 @@
#include <draw.h>
#include <mouse.h>
#include <keyboard.h>
+#include <geometry.h>
+#include "dat.h"
+#include "fns.h"
+
+enum {
+ CBlack,
+ CWhite,
+ NCOLOR
+};
+
+RFrame worldrf;
+Image *pal[NCOLOR];
+
+Point
+toscreen(Point2 p)
+{
+ p = invrframexform(p, worldrf);
+ return Pt(p.x,p.y);
+}
+
+Point2
+fromscreen(Point p)
+{
+ return rframexform(Pt2(p.x,p.y,1), worldrf);
+}
+
+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);
+}
+
+void
+redraw(void)
+{
+ lockdisplay(display);
+ draw(screen, screen->r, pal[CBlack], nil, ZP);
+ flushimage(display, 1);
+ unlockdisplay(display);
+}
+
+void
+resized(void)
+{
+ lockdisplay(display);
+ if(getwindow(display, Refnone) < 0)
+ sysfatal("resize failed");
+ unlockdisplay(display);
+ worldrf.p = Pt2(screen->r.min.x,screen->r.max.y,1);
+ redraw();
+}
+
+void
+mouse(Mousectl *mc, Keyboardctl *)
+{
+
+}
+
+void
+key(Rune r)
+{
+ switch(r){
+ case Kdel:
+ case 'q':
+ threadexitsall(nil);
+ }
+}
void
usage(void)
@@ -15,7 +83,53 @@ usage(void)
void
threadmain(int argc, char *argv[])
{
+ Mousectl *mc;
+ Keyboardctl *kc;
+ Rune r;
+
ARGBEGIN{
default: usage();
}ARGEND;
+ if(argc > 0)
+ usage();
+
+ if(initdraw(nil, nil, nil) < 0)
+ sysfatal("initdraw: %r");
+ if((mc = initmouse(nil, screen)) == nil)
+ sysfatal("initmouse: %r");
+ if((kc = initkeyboard(nil)) == nil)
+ sysfatal("initkeyboard: %r");
+
+ worldrf.p = Pt2(screen->r.min.x,screen->r.max.y,1);
+ worldrf.bx = Vec2(1, 0);
+ worldrf.by = Vec2(0,-1);
+ initpalette();
+
+ display->locking = 1;
+ unlockdisplay(display);
+ redraw();
+
+ for(;;){
+ enum { MOUSE, RESIZE, KEYBOARD };
+ Alt a[] = {
+ {mc->c, &mc->Mouse, CHANRCV},
+ {mc->resizec, nil, CHANRCV},
+ {kc->c, &r, CHANRCV},
+ {nil, nil, CHANEND}
+ };
+
+ switch(alt(a)){
+ case MOUSE:
+ mouse(mc, kc);
+ break;
+ case RESIZE:
+ resized();
+ break;
+ case KEYBOARD:
+ key(r);
+ break;
+ }
+
+ redraw();
+ }
}
diff --git a/mkfile b/mkfile
index 28d904b..90d5b2e 100644
--- a/mkfile
+++ b/mkfile
@@ -3,6 +3,26 @@
BIN=/$objtype/bin
TARG=puppeteer
OFILES=\
+ alloc.$O\
+ layer.$O\
main.$O\
+HFILES=\
+ dat.h\
+ fns.h\
+ libgeometry/geometry.h\
+
+LIB=\
+ libgeometry/libgeometry.a$O\
+
+CFLAGS=$CFLAGS -Ilibgeometry
+
</sys/src/cmd/mkone
+
+libgeometry/libgeometry.a$O:
+ cd libgeometry
+ mk install
+
+clean nuke:V:
+ rm -f *.[$OS] [$OS].??* $TARG
+ @{cd libgeometry; mk $target}