commit 9c4bcfd

ohmu  ·  2026-09-07 03:59:16 +0300 MSK
parent 6ed47b6
added clock(just made mkfile lol)
2 files changed,  +106, -0
+99, -0
  1@@ -0,0 +1,99 @@
  2+#include <u.h>
  3+#include <libc.h>
  4+#include <draw.h>
  5+#include <event.h>
  6+
  7+Image *hrhand, *minhand;
  8+Image *dots, *back;
  9+
 10+Point
 11+circlept(Point c, int r, int degrees)
 12+{
 13+	double rad;
 14+	rad = (double) degrees * PI/180.0;
 15+	c.x += cos(rad)*r;
 16+	c.y -= sin(rad)*r;
 17+	return c;
 18+}
 19+
 20+void
 21+redraw(Image *screen)
 22+{
 23+	static int tm, ntm;
 24+	static Rectangle r;
 25+	static Point c;
 26+	static int rad;
 27+	int i;
 28+	int anghr, angmin;
 29+	static Tm ntms;
 30+
 31+	ntm = time(0);
 32+	if(ntm == tm && eqrect(screen->r, r))
 33+		return;
 34+
 35+	ntms = *localtime(ntm);
 36+	anghr = 90-(ntms.hour*5 + ntms.min/12)*6;
 37+	angmin = 90-ntms.min*6;
 38+	tm = ntm;
 39+	r = screen->r;
 40+	c = divpt(addpt(r.min, r.max), 2);
 41+	rad = Dx(r) < Dy(r) ? Dx(r) : Dy(r);
 42+	rad /= 2;
 43+	rad -= 8;
 44+
 45+	draw(screen, screen->r, back, nil, ZP);
 46+	for(i=0; i<12; i++)
 47+		fillellipse(screen, circlept(c, rad, i*(360/12)), 2, 2, dots, ZP);
 48+
 49+	line(screen, c, circlept(c, (rad*3)/4, angmin), 0, 0, 1, minhand, ZP);
 50+	line(screen, c, circlept(c, rad/2, anghr), 0, 0, 1, hrhand, ZP);
 51+
 52+	flushimage(display, 1);
 53+}
 54+
 55+void
 56+eresized(int new)
 57+{
 58+	if(new && getwindow(display, Refnone) < 0)
 59+		fprint(2,"can't reattach to window");
 60+	redraw(screen);
 61+}
 62+
 63+void
 64+main(int, char**)
 65+{
 66+	Event e;
 67+	Mouse m;
 68+	Menu menu;
 69+	char *mstr[] = {"exit", 0};
 70+	int key, timer;
 71+	int t;
 72+
 73+	if (initdraw(0, 0, "clock") < 0)
 74+		sysfatal("initdraw failed");
 75+	back = allocimagemix(display, DPalebluegreen, DWhite);
 76+
 77+	hrhand = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DDarkblue);
 78+	minhand = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPaleblue);
 79+	dots = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DBlue);
 80+	redraw(screen);
 81+
 82+	einit(Emouse);
 83+	t = (30*1000);
 84+	timer = etimer(0, t);
 85+
 86+	menu.item = mstr;
 87+	menu.lasthit = 0;
 88+	for(;;) {
 89+		key = event(&e);
 90+		if(key == Emouse) {
 91+			m = e.mouse;
 92+			if(m.buttons & 4) {
 93+				if(emenuhit(3, &m, &menu) == 0)
 94+					exits(0);
 95+			}
 96+		} else if(key == timer) {
 97+			redraw(screen);
 98+		}
 99+	}	
100+}
+7, -0
1@@ -0,0 +1,7 @@
2+<$PLAN9/src/mkhdr
3+
4+TARG=clock
5+OFILES=clock.$O
6+
7+<$PLAN9/src/mkone
8+