aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/draw
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/draw')
-rw-r--r--src/cmd/draw/clock.c104
-rw-r--r--src/cmd/draw/cmapcube.c5
-rw-r--r--src/cmd/draw/crop.c2
-rw-r--r--src/cmd/draw/gview.c4
-rw-r--r--src/cmd/draw/mc.c1
-rw-r--r--src/cmd/draw/stats.c7
-rw-r--r--src/cmd/draw/statusbar.c13
-rw-r--r--src/cmd/draw/tcolors.c1
-rw-r--r--src/cmd/draw/tweak.c30
9 files changed, 134 insertions, 33 deletions
diff --git a/src/cmd/draw/clock.c b/src/cmd/draw/clock.c
new file mode 100644
index 00000000..b804e1f4
--- /dev/null
+++ b/src/cmd/draw/clock.c
@@ -0,0 +1,104 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <event.h>
+
+Image *hrhand, *minhand;
+Image *dots, *back;
+
+Point
+circlept(Point c, int r, int degrees)
+{
+ double rad;
+ rad = (double) degrees * PI/180.0;
+ c.x += cos(rad)*r;
+ c.y -= sin(rad)*r;
+ return c;
+}
+
+void
+redraw(Image *screen)
+{
+ static int tm, ntm;
+ static Rectangle r;
+ static Point c;
+ static int rad;
+ int i;
+ int anghr, angmin;
+ static Tm tms;
+ static Tm ntms;
+
+ ntm = time(0);
+ if(ntm == tm && eqrect(screen->r, r))
+ return;
+
+ ntms = *localtime(ntm);
+ anghr = 90-(ntms.hour*5 + ntms.min/12)*6;
+ angmin = 90-ntms.min*6;
+ tm = ntm;
+ tms = ntms;
+ r = screen->r;
+ c = divpt(addpt(r.min, r.max), 2);
+ rad = Dx(r) < Dy(r) ? Dx(r) : Dy(r);
+ rad /= 2;
+ rad -= 8;
+
+ draw(screen, screen->r, back, nil, ZP);
+ for(i=0; i<12; i++)
+ fillellipse(screen, circlept(c, rad, i*(360/12)), 2, 2, dots, ZP);
+
+ line(screen, c, circlept(c, (rad*3)/4, angmin), 0, 0, 1, minhand, ZP);
+ line(screen, c, circlept(c, rad/2, anghr), 0, 0, 1, hrhand, ZP);
+
+ flushimage(display, 1);
+}
+
+void
+eresized(int new)
+{
+ if(new && getwindow(display, Refnone) < 0)
+ fprint(2,"can't reattach to window");
+ redraw(screen);
+}
+
+void
+main(int argc, char **argv)
+{
+ Event e;
+ Mouse m;
+ Menu menu;
+ char *mstr[] = {"exit", 0};
+ int key, timer;
+ int t;
+
+ USED(argc);
+ USED(argv);
+
+ if (initdraw(0, 0, "clock") < 0)
+ sysfatal("initdraw failed");
+ back = allocimagemix(display, DPalebluegreen, DWhite);
+
+ hrhand = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DDarkblue);
+ minhand = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPaleblue);
+ dots = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DBlue);
+ redraw(screen);
+
+ einit(Emouse);
+ t = (30*1000);
+ timer = etimer(0, t);
+
+ menu.item = mstr;
+ menu.lasthit = 0;
+ for(;;) {
+ key = event(&e);
+ if(key == Emouse) {
+ m = e.mouse;
+ if(m.buttons & 4) {
+ if(emenuhit(3, &m, &menu) == 0)
+ exits(0);
+ }
+ } else if(key == timer) {
+ redraw(screen);
+ }
+ }
+}
diff --git a/src/cmd/draw/cmapcube.c b/src/cmd/draw/cmapcube.c
index 3d0e14e8..fd234d60 100644
--- a/src/cmd/draw/cmapcube.c
+++ b/src/cmd/draw/cmapcube.c
@@ -109,7 +109,7 @@ redraw(void)
line3(v[0x36], v[0x32]);
line3(v[0x32], v[0x3F]);
line3(v[0x3F], v[0]);
-
+
line3(v[0xF0], v[0xF3]);
line3(v[0xF3], v[0xFF]);
line3(v[0xFF], v[0xFC]);
@@ -185,7 +185,8 @@ void main(int argc, char **argv){
break;
}ARGEND
- initdraw(0,0,0);
+ if(initdraw(0,0,0) < 0)
+ sysfatal("initdraw: %r");
ncolor=256;
for(i=0;i!=ncolor;i++)
color[i] = allocimage(display, Rect(0, 0, 1, 1), CMAP8, 1, cmap2rgba(i));
diff --git a/src/cmd/draw/crop.c b/src/cmd/draw/crop.c
index 10a08f77..d6d89722 100644
--- a/src/cmd/draw/crop.c
+++ b/src/cmd/draw/crop.c
@@ -76,7 +76,7 @@ crop(Memimage *m, uint32 c)
bottom = y;
}
}
-
+
if(n != nil)
freememimage(n);
return Rect(left, top, right+1, bottom+1);
diff --git a/src/cmd/draw/gview.c b/src/cmd/draw/gview.c
index 0794f100..0f5e6905 100644
--- a/src/cmd/draw/gview.c
+++ b/src/cmd/draw/gview.c
@@ -1547,7 +1547,7 @@ void all_set_clr(fpolygons* fps, Image* clr)
for (p=fps->p; p!=0; p=p->link)
p->clr = clr;
}
-
+
void do_recolor(int but, Mouse* m, int alluniv)
{
@@ -1819,7 +1819,7 @@ e_action* do_undo(e_action* a0) /* pop off an e_action and (un)do it */
case Erecolor: a->fp->clr = a->clr;
eresized(0);
break;
- case Edelete:
+ case Edelete:
a->fp->link = univ.p;
univ.p = a->fp;
grow_bb(&univ.bb, &a->fp->bb);
diff --git a/src/cmd/draw/mc.c b/src/cmd/draw/mc.c
index ea36e28d..ee112194 100644
--- a/src/cmd/draw/mc.c
+++ b/src/cmd/draw/mc.c
@@ -337,4 +337,3 @@ getwidth(void)
}else
linewidth = ws.ws_col;
}
-
diff --git a/src/cmd/draw/stats.c b/src/cmd/draw/stats.c
index 74b8b76c..3b6471b7 100644
--- a/src/cmd/draw/stats.c
+++ b/src/cmd/draw/stats.c
@@ -50,7 +50,7 @@ enum
};
char*
-labels[Nvalue] =
+labels[Nvalue] =
{
"802.11",
"battery",
@@ -70,7 +70,7 @@ labels[Nvalue] =
"sys",
"syscall",
"user"
-};
+};
struct Graph
{
@@ -435,7 +435,7 @@ newvalue(Machine *m, int i, ulong *v, ulong *vmax)
if(m->last[i] == 0)
m->last[i] = m->val[i][0];
-
+
if(i == Vload){
/*
* Invert the ewma to obtain the 5s load statistics.
@@ -928,4 +928,3 @@ initmach(Machine *m, char *name)
*q = 0;
return 1;
}
-
diff --git a/src/cmd/draw/statusbar.c b/src/cmd/draw/statusbar.c
index fef6d2dd..f67b1041 100644
--- a/src/cmd/draw/statusbar.c
+++ b/src/cmd/draw/statusbar.c
@@ -108,7 +108,7 @@ resize()
p.x = r.min.x+4;
p.y += display->defaultfont->height+4;
-
+
q = subpt(r.max, Pt(4,4));
rbar = Rpt(p, q);
border(screen, rbar, -2, dark, ZP);
@@ -116,12 +116,12 @@ resize()
lastp = -1;
flushimage(display, 1);
- drawbar();
+ drawbar();
}
void
keyboardthread(void *v)
-{
+{
Rune r;
while(recv(kc->c , &r) == 1){
@@ -132,9 +132,9 @@ keyboardthread(void *v)
void
mousethread(void *v)
-{
+{
USED(v);
-
+
while(recv(mc->c, 0) == 1); /* to unblock mc->c */
}
@@ -188,7 +188,7 @@ threadmain(int argc, char **argv)
int lfd;
p = "300x40@100,100";
-
+
ARGBEGIN{
case 'W':
p = ARGF();
@@ -231,4 +231,3 @@ threadmain(int argc, char **argv)
}
proccreate(updateproc, nil, STACK);
}
-
diff --git a/src/cmd/draw/tcolors.c b/src/cmd/draw/tcolors.c
index caac0be6..9aa4de79 100644
--- a/src/cmd/draw/tcolors.c
+++ b/src/cmd/draw/tcolors.c
@@ -232,4 +232,3 @@ resizethread(void *v)
while(recv(mousectl->resizec, &x) >= 0)
eresized(1);
}
-
diff --git a/src/cmd/draw/tweak.c b/src/cmd/draw/tweak.c
index 89fdef32..29e2b3d7 100644
--- a/src/cmd/draw/tweak.c
+++ b/src/cmd/draw/tweak.c
@@ -112,32 +112,32 @@ Cursor sight = {
Cursor pixel = {
{-7, -7},
{0x1f, 0xf8, 0x3f, 0xfc, 0x7f, 0xfe, 0xf8, 0x1f,
- 0xf0, 0x0f, 0xe0, 0x07, 0xe0, 0x07, 0xfe, 0x7f,
- 0xfe, 0x7f, 0xe0, 0x07, 0xe0, 0x07, 0xf0, 0x0f,
+ 0xf0, 0x0f, 0xe0, 0x07, 0xe0, 0x07, 0xfe, 0x7f,
+ 0xfe, 0x7f, 0xe0, 0x07, 0xe0, 0x07, 0xf0, 0x0f,
0x78, 0x1f, 0x7f, 0xfe, 0x3f, 0xfc, 0x1f, 0xf8, },
- {0x00, 0x00, 0x0f, 0xf0, 0x31, 0x8c, 0x21, 0x84,
- 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x40, 0x02,
- 0x40, 0x02, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82,
+ {0x00, 0x00, 0x0f, 0xf0, 0x31, 0x8c, 0x21, 0x84,
+ 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x40, 0x02,
+ 0x40, 0x02, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82,
0x21, 0x84, 0x31, 0x8c, 0x0f, 0xf0, 0x00, 0x00, }
};
Cursor busy = {
{-7, -7},
- {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0c, 0x00, 0x8e, 0x1d, 0xc7,
- 0xff, 0xe3, 0xff, 0xf3, 0xff, 0xff, 0x7f, 0xfe,
+ 0xff, 0xe3, 0xff, 0xf3, 0xff, 0xff, 0x7f, 0xfe,
0x3f, 0xf8, 0x17, 0xf0, 0x03, 0xe0, 0x00, 0x00,},
- {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, 0x82,
- 0x04, 0x41, 0xff, 0xe1, 0x5f, 0xf1, 0x3f, 0xfe,
+ 0x04, 0x41, 0xff, 0xe1, 0x5f, 0xf1, 0x3f, 0xfe,
0x17, 0xf0, 0x03, 0xe0, 0x00, 0x00, 0x00, 0x00,}
};
Cursor skull = {
{-7,-7},
- {0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xe7, 0xe7,
- 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0x1f, 0xf8,
- 0x0f, 0xf0, 0x3f, 0xfc, 0xff, 0xff, 0xff, 0xff,
+ {0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xe7, 0xe7,
+ 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0x1f, 0xf8,
+ 0x0f, 0xf0, 0x3f, 0xfc, 0xff, 0xff, 0xff, 0xff,
0xef, 0xf7, 0xc7, 0xe3, 0x00, 0x00, 0x00, 0x00,},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x03,
0xE7, 0xE7, 0x3F, 0xFC, 0x0F, 0xF0, 0x0D, 0xB0,
@@ -372,7 +372,7 @@ stext(Thing *t, char *l0, char *l1)
char buf[256];
l1[0] = 0;
- sprint(buf, "depth:%d r:%d %d %d %d ",
+ sprint(buf, "depth:%d r:%d %d %d %d ",
t->b->depth, t->b->r.min.x, t->b->r.min.y,
t->b->r.max.x, t->b->r.max.y);
if(t->parent)
@@ -1142,7 +1142,7 @@ textedit(Thing *t, char *tag)
fc = f->info;
for(i=0; i<=w && i<=f->n; i++)
nfc[i] = fc[i];
- if(w+1 < i)
+ if(i < w+1)
memset(nfc+i, 0, ((w+1)-i)*sizeof(Fontchar));
x = fc[f->n].x;
for(; i<=w; i++)
@@ -1397,7 +1397,7 @@ openedit(Thing *t, Point pt, int c)
}
br = t->b->r;
if(t->s == 0){
- c = -1;
+ c = -1;
/* if big enough to bother, sweep box */
if(Dx(br)<=16 && Dy(br)<=16)
r = br;