4 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
26 const char clock_table
[14][5][5] = {
27 { { 1,1,1,1,1 }, /* 0 */
32 { { 0,0,0,0,1 }, /* 1 */
37 { { 1,1,1,1,1 }, /* 2 */
42 { { 1,1,1,1,1 }, /* 3 */
47 { { 1,0,0,0,1 }, /* 4 */
52 { { 1,1,1,1,1 }, /* 5 */
57 { { 1,1,1,1,1 }, /* 6 */
62 { { 1,1,1,1,1 }, /* 7 */
67 { { 1,1,1,1,1 }, /* 8 */
72 { { 1,1,1,1,1 }, /* 9 */
77 { { 0,0,0,0,0 }, /* : */
82 { { 1,1,1,1,1 }, /* A */
87 { { 1,1,1,1,1 }, /* P */
92 { { 1,0,0,0,1 }, /* M */
100 clock_draw(struct screen_write_ctx
*ctx
, int colour
, int style
)
102 struct screen
*s
= ctx
->s
;
107 u_int i
, j
, x
, y
, idx
;
112 strftime(tim
, sizeof tim
, "%l:%M ", localtime(&t
));
113 if (tm
->tm_hour
>= 12)
114 strlcat(tim
, "PM", sizeof tim
);
116 strlcat(tim
, "AM", sizeof tim
);
118 strftime(tim
, sizeof tim
, "%H:%M", tm
);
121 screen_write_clearscreen(ctx
);
123 if (screen_size_x(s
) < 6 * strlen(tim
) || screen_size_y(s
) < 6) {
124 if (screen_size_x(s
) >= strlen(tim
) && screen_size_y(s
) != 0) {
125 x
= (screen_size_x(s
) / 2) - (strlen(tim
) / 2);
126 y
= screen_size_y(s
) / 2;
127 screen_write_cursormove(ctx
, x
, y
);
129 memcpy(&gc
, &grid_default_cell
, sizeof gc
);
130 colour_set_fg(&gc
, colour
);
131 screen_write_puts(ctx
, &gc
, "%s", tim
);
136 x
= (screen_size_x(s
) / 2) - 3 * strlen(tim
);
137 y
= (screen_size_y(s
) / 2) - 3;
139 memcpy(&gc
, &grid_default_cell
, sizeof gc
);
140 colour_set_bg(&gc
, colour
);
141 for (ptr
= tim
; *ptr
!= '\0'; ptr
++) {
142 if (*ptr
>= '0' && *ptr
<= '9')
144 else if (*ptr
== ':')
146 else if (*ptr
== 'A')
148 else if (*ptr
== 'P')
150 else if (*ptr
== 'M')
157 for (j
= 0; j
< 5; j
++) {
158 for (i
= 0; i
< 5; i
++) {
159 screen_write_cursormove(ctx
, x
+ i
, y
+ j
);
160 if (clock_table
[idx
][j
][i
])
161 screen_write_putc(ctx
, &gc
, ' ');