1 /* Author: Rob DeHart IRC Asaph */
2 /* Home: http://rob.cqtopia.com/plan9/bclock.c */
11 Image
*bground
, *gray
;
13 void draw_block(int x
, int y
, int on
)
16 Rectangle rect
, bounds
;
19 boxX
= (rect
.max
.x
- rect
.min
.x
- MARGIN
* 7) / 6;
20 boxY
= (rect
.max
.y
- rect
.min
.y
- MARGIN
* 5) / 4;
21 bounds
= Rect(MARGIN
+ rect
.min
.x
+ x
* (boxX
+ MARGIN
),
22 MARGIN
+ rect
.min
.y
+ y
* (boxY
+ MARGIN
),
23 MARGIN
+ rect
.min
.x
+ x
* (boxX
+ MARGIN
) + boxX
,
24 MARGIN
+ rect
.min
.y
+ y
* (boxY
+ MARGIN
) + boxY
);
26 color
= display
->black
;
29 draw(screen
, bounds
, color
, nil
, rect
.min
);
32 void light_cols(int num
, int grp
)
37 for (i
= 3; i
>= 0; --i
)
39 if ((grp
== 0 && i
<= 1) || (grp
!= 0 && i
<= 2))
40 draw_block(grp
* 2, 3 - i
, tens
>> i
& 1);
41 draw_block(grp
* 2 + 1, 3 - i
, ones
>> i
& 1);
55 if(ntm
== tm
&& eqrect(screen
->r
, r
))
58 ntms
= *localtime(ntm
);
63 draw(screen
, screen
->r
, bground
, nil
, ZP
);
64 light_cols(ntms
.hour
, 0);
65 light_cols(ntms
.min
, 1);
66 light_cols(ntms
.sec
, 2);
68 flushimage(display
, 1);
74 if(new && getwindow(display
, Refnone
) < 0)
75 fprint(2,"can't reattach to window");
83 fprint(2, "usage: bclock [-W winsize]\n");
89 main(int argc
, char *argv
[])
94 char *mstr
[] = {"exit", 0};
100 winsize
= EARGF(usage());
107 initdraw(0,0,"bclock");
108 bground
= allocimagemix(display
, DPalebluegreen
, DWhite
);
109 gray
= allocimage(display
, Rect(0, 0, 1, 1), RGB24
, 1, 0xDDDDDDFF);
114 timer
= etimer(0, 1000);
123 if(emenuhit(3, &m
, &menu
) == 0)
126 } else if(key
== timer
) {