-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate.c
More file actions
79 lines (64 loc) · 2.41 KB
/
Copy pathdate.c
File metadata and controls
79 lines (64 loc) · 2.41 KB
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
#include <time.h>
#include <stdio.h>
#include "sal.h"
#include "config.h"
#include "image.h"
#include "window.h"
#include "aquarium.h"
static Imlib_Image figures, months;
void date_update(struct aquarium *aquarium)
{
time_t now;
struct tm *mt;
int tw;
int x, y;
if (aquarium->date == AL_NO)
return;
now = time(NULL);
mt = localtime(&now);
imlib_context_set_image(months);
tw = imlib_image_get_width();
imlib_context_set_image(figures);
tw += (1 + (mt->tm_mday > 9)) * imlib_image_get_width();
aquarium_transform(aquarium->date,
tw, imlib_image_get_height(),
&x, &y);
if (mt->tm_mday > 9) {
window_draw((unsigned char *)imlib_image_get_data_for_reading_only(),
0, (mt->tm_mday / 10) * (imlib_image_get_height() / 10),
imlib_image_get_width(),
imlib_image_get_height() / 10,
x, y,
true);
x += imlib_image_get_width();
}
window_draw((unsigned char *)imlib_image_get_data_for_reading_only(),
0, (mt->tm_mday % 10) * (imlib_image_get_height() / 10),
imlib_image_get_width(),
imlib_image_get_height() / 10,
x, y,
true);
x += imlib_image_get_width() + 3;
imlib_context_set_image(months);
window_draw((unsigned char *)imlib_image_get_data_for_reading_only(),
0, mt->tm_mon * imlib_image_get_height() / 12,
imlib_image_get_width(),
imlib_image_get_height() / 12,
x, y,
true);
}
void date_init(struct aquarium *aquarium)
{
if (aquarium->date == AL_NO)
return;
figures = image_load("date/figures.png");
months = image_load("date/months.png");
image_change_color(figures,
RED(aquarium->date_color),
GREEN(aquarium->date_color),
BLUE(aquarium->date_color));
image_change_color(months,
RED(aquarium->date_color),
GREEN(aquarium->date_color),
BLUE(aquarium->date_color));
}