-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblock_watch_face.c
111 lines (94 loc) · 2.97 KB
/
block_watch_face.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
107
108
109
110
111
#include "block_watch_face.h"
#include "watch_face_internal.h"
#define DIGITS_COUNT 10
typedef struct {
RectangleType rect[2];
} ShapeType;
#define FILL_RECT(RECT, X, Y, W, H) \
{ \
RECT.topLeft.x = X; \
RECT.topLeft.y = Y; \
RECT.extent.x = W; \
RECT.extent.y = H; \
}
/**
* @brief Initialize digit shapes.
* @return Pointer to array of the digit shapes on success, NULL otherwise.
*/
static void* init_watch_face(WatchFaceType* watchFace) {
ShapeType* shapes;
shapes = MemPtrNew(sizeof(ShapeType) * DIGITS_COUNT);
if (shapes == NULL) {
return NULL;
}
FILL_RECT(shapes[0].rect[0], 1, 1, 2, 3)
FILL_RECT(shapes[0].rect[1], 1, 1, 2, 3)
FILL_RECT(shapes[1].rect[0], 0, 0, 3, 5)
FILL_RECT(shapes[1].rect[1], 0, 0, 3, 5)
FILL_RECT(shapes[2].rect[0], 0, 1, 3, 1)
FILL_RECT(shapes[2].rect[1], 2, 3, 3, 1)
FILL_RECT(shapes[3].rect[0], 0, 1, 3, 1)
FILL_RECT(shapes[3].rect[1], 0, 3, 3, 1)
FILL_RECT(shapes[4].rect[0], 1, 0, 2, 2)
FILL_RECT(shapes[4].rect[1], 0, 3, 3, 2)
FILL_RECT(shapes[5].rect[0], 2, 1, 3, 1)
FILL_RECT(shapes[5].rect[1], 0, 3, 3, 1)
FILL_RECT(shapes[6].rect[0], 2, 1, 3, 1)
FILL_RECT(shapes[6].rect[1], 2, 3, 2, 1)
FILL_RECT(shapes[7].rect[0], 0, 1, 3, 4)
FILL_RECT(shapes[7].rect[1], 0, 1, 3, 4)
FILL_RECT(shapes[8].rect[0], 1, 1, 2, 1)
FILL_RECT(shapes[8].rect[1], 1, 3, 2, 1)
FILL_RECT(shapes[9].rect[0], 1, 1, 2, 1)
FILL_RECT(shapes[9].rect[1], 0, 3, 3, 1)
return shapes;
}
static void draw_shape(ShapeType* shape, UInt16 scale, UInt16 x, UInt16 y) {
RectangleType buf;
int i = 0;
for (; i < 2; ++i) {
MemMove(&buf, &(shape->rect[i]), sizeof(RectangleType));
buf.topLeft.x *= scale;
buf.topLeft.y *= scale;
buf.topLeft.x += x;
buf.topLeft.y += y;
buf.extent.x *= scale;
buf.extent.y *= scale;
WinDrawRectangle(&buf, 0);
}
}
static Err init(void** internal) {
if ((*internal = init_watch_face(NULL)) == NULL) {
return memErrorClass;
}
return errNone;
}
static void draw_time(void* internal, DateTimeType* dt) {
UInt8 hi_hour, lo_hour, hi_minute, lo_minute;
ShapeType* shapes = (ShapeType*) internal;
hi_hour = dt->hour / 10;
lo_hour = dt->hour % 10;
hi_minute = dt->minute / 10;
lo_minute = dt->minute % 10;
WinEraseWindow();
draw_shape(&(shapes[hi_hour]), 16, 0, 0);
draw_shape(&(shapes[lo_hour]), 16, 80, 0);
draw_shape(&(shapes[hi_minute]), 16, 0, 80);
draw_shape(&(shapes[lo_minute]), 16, 80, 80);
}
static UInt32 get_data_size() {
return sizeof(ShapeType) * DIGITS_COUNT;
}
static void block_watchface_free(void* internal) {
MemPtrFree(internal);
}
WatchFaceType* createBlockWatchFace() {
WatchFaceType* result = MemPtrNew(sizeof (WatchFaceType));
result->prefix = 'BLOC';
result->internal = NULL;
result->GetDataSize = get_data_size;
result->DrawTime = draw_time;
result->InitWatchFace = init;
result->Free = block_watchface_free;
return result;
}