aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dat.h27
-rw-r--r--fns.h1
-rw-r--r--main.c23
-rw-r--r--utils.c6
4 files changed, 47 insertions, 10 deletions
diff --git a/dat.h b/dat.h
index ce1cd64..8e42349 100644
--- a/dat.h
+++ b/dat.h
@@ -1,5 +1,18 @@
+/* palette colors */
+enum {
+ PCBlack,
+ PCWhite,
+ NCOLOR
+};
+
+enum {
+ MAXZOOM = 8
+};
+
typedef struct Layer Layer;
typedef struct Canvas Canvas;
+typedef struct HUD HUD;
+typedef struct HUDWidget HUDWidget;
struct Layer
{
@@ -17,3 +30,17 @@ struct Canvas
Layer layers;
Layer *curlayer;
};
+
+struct HUD
+{
+ Point2 p;
+ HUDWidget *widgets;
+};
+
+struct HUDWidget
+{
+ Point2 p;
+ char *fmt;
+ va_arg va;
+ HUDWidget *next;
+};
diff --git a/fns.h b/fns.h
index fe9ca4f..5152daa 100644
--- a/fns.h
+++ b/fns.h
@@ -14,5 +14,6 @@ Layer *newlayer(char*, Rectangle, ulong);
void rmlayer(Layer*);
/* utils */
+int clamp(int, int, int);
double fclamp(double, double, double);
int alphachan(ulong);
diff --git a/main.c b/main.c
index 649be92..3d5d8b5 100644
--- a/main.c
+++ b/main.c
@@ -8,18 +8,12 @@
#include "dat.h"
#include "fns.h"
-/* palette colors */
-enum {
- PCBlack,
- PCWhite,
- NCOLOR
-};
-
RFrame worldrf;
-Image *pal[NCOLOR];
Image *background;
Canvas *curcanvas;
Image *brushcolor;
+Image *pal[NCOLOR];
+int zoom = 1;
void resized(void);
@@ -252,8 +246,7 @@ lmb(Mousectl *mc, Keyboardctl *)
p = Pt(mpos.x,mpos.y);
if(eqpt(p, oldp))
continue;
- //draw(curcanvas->curlayer->image, rectaddpt(r, p), brushcolor, nil, ZP);
- line(curcanvas->curlayer->image, oldp, p, Enddisc, Enddisc, 0, brushcolor, ZP);
+ line(curcanvas->curlayer->image, oldp, p, Endsquare, Endsquare, 0, brushcolor, ZP);
redraw();
}
}
@@ -267,6 +260,10 @@ mouse(Mousectl *mc, Keyboardctl *kc)
mmb(mc, kc);
if((mc->buttons&4) != 0)
rmb(mc, kc);
+ if((mc->buttons&8) != 0)
+ zoom = clamp(++zoom, 0, MAXZOOM);
+ if((mc->buttons&16) != 0)
+ zoom = clamp(--zoom, 0, MAXZOOM);
}
void
@@ -276,6 +273,12 @@ key(Rune r)
case Kdel:
case 'q':
threadexitsall(nil);
+ case '+':
+ zoom = clamp(++zoom, 0, MAXZOOM);
+ break;
+ case '-':
+ zoom = clamp(--zoom, 0, MAXZOOM);
+ break;
}
}
diff --git a/utils.c b/utils.c
index 4f75298..4813da5 100644
--- a/utils.c
+++ b/utils.c
@@ -2,6 +2,12 @@
#include <libc.h>
#include <draw.h>
+int
+clamp(int n, int min, int max)
+{
+ return n < min? min: n > max? max: n;
+}
+
double
fclamp(double n, double min, double max)
{