-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigital-clock.c
106 lines (84 loc) · 3.6 KB
/
digital-clock.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdio.h>
#include <time.h>
#include "sal.h"
#include "config.h"
#include "image.h"
#include "window.h"
#include "aquarium.h"
static Imlib_Image figures, colon;
static int dc_x, dc_y;
void digital_clock_update(struct aquarium *aquarium)
{
time_t now;
struct tm *mt;
int x = dc_x;
int t[3];
int l, i;
if(aquarium->digital_clock == AL_NO)
return;
now = time(NULL);
mt = localtime(&now);
t[0] = mt->tm_hour;
t[1] = mt->tm_min;
t[2] = mt->tm_sec;
l = 2 + aquarium->digital_clock_seconds;
for (i = 0; i < l; i++) {
imlib_context_set_image(figures);
window_draw((unsigned char *)imlib_image_get_data_for_reading_only(),
0, (t[i] / 10) * imlib_image_get_height() / 10,
imlib_image_get_width(),
imlib_image_get_height() / 10,
x, dc_y,
true);
x += imlib_image_get_width();
window_draw((unsigned char *)imlib_image_get_data_for_reading_only(),
0, (t[i] % 10) * imlib_image_get_height() / 10,
imlib_image_get_width(),
imlib_image_get_height() / 10,
x, dc_y,
true);
x += imlib_image_get_width();
if (i + 1 != l) {
imlib_context_set_image(colon);
window_draw((unsigned char *)imlib_image_get_data_for_reading_only(),
0, 0,
imlib_image_get_width(),
imlib_image_get_height(),
x, dc_y,
true);
x += imlib_image_get_width();
}
}
}
void digital_clock_init(struct aquarium *aquarium)
{
int total_width;
if(aquarium->digital_clock != AL_NO && aquarium->digital_clock_small != AL_NO) {
printf("Error: You can't have both a small and a large digital clock at the same time.\n");
return;
}
if(aquarium->digital_clock != AL_NO) {
figures = image_load("digital-clock/bigfigures.png");
colon = image_load("digital-clock/bigcolon.png");
} else if(aquarium->digital_clock_small != AL_NO) {
figures = image_load("digital-clock/smallfigures.png");
colon = image_load("digital-clock/smallcolon.png");
aquarium->digital_clock = aquarium->digital_clock_small;
} else
return;
image_change_color(figures,
RED(aquarium->digital_clock_color),
GREEN(aquarium->digital_clock_color),
BLUE(aquarium->digital_clock_color));
image_change_color(colon,
RED(aquarium->digital_clock_color),
GREEN(aquarium->digital_clock_color),
BLUE(aquarium->digital_clock_color));
imlib_context_set_image(figures);
total_width = (4 + 2 * aquarium->digital_clock_seconds) * imlib_image_get_width();
imlib_context_set_image(colon);
total_width += (1 + aquarium->digital_clock_seconds) * imlib_image_get_width();
aquarium_transform(aquarium->digital_clock,
total_width, imlib_image_get_height(),
&dc_x, &dc_y);
}