-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathicon.c
164 lines (154 loc) · 3.84 KB
/
icon.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Twin - A Tiny Window System
* Copyright (c) 2004 Keith Packard <[email protected]>
* All rights reserved.
*/
#include "twin_private.h"
#define G(d) ((signed char) ((d) * 64))
#define ICON_THIN (1.0 / 20.0)
#define L(v) G(v + ICON_THIN / 2)
#define T(v) G(v + ICON_THIN / 2)
#define R(v) G(v - ICON_THIN / 2)
#define B(v) G(v - ICON_THIN / 2)
/* clang-format off */
static const signed char _twin_itable[] = {
/* Menu */
#define TWIN_MENU_POS 0
'm', L(0), T(0),
'd', R(1), T(0),
'd', R(1), B(1),
'd', L(0), B(1),
'x',
's',
'm', G(0.2), G(0.2),
'd', G(0.8), G(0.2),
's',
'm', G(0.2), G(0.4),
'd', G(0.8), G(0.4),
's',
'm', G(0.2), G(0.6),
'd', G(0.8), G(0.6),
's',
'm', G(0.2), G(0.8),
'd', G(0.8), G(0.8),
's',
'e',
#define TWIN_MENU_LEN 43
/* Minimize */
#define TWIN_MINIMIZE_POS TWIN_MENU_POS + TWIN_MENU_LEN
'm', L(0), G(0.8),
'd', L(0), B(1),
'd', R(1), B(1),
'd', R(1), G(0.8),
'x',
'w', G(0.05),
'p',
'e',
#define TWIN_MINIMIZE_LEN 17
/* Maximize */
#define TWIN_MAXIMIZE_POS TWIN_MINIMIZE_POS + TWIN_MINIMIZE_LEN
'm', L(0), T(0),
'd', L(0), G(0.2),
'd', R(1), G(0.2),
'd', R(1), T(0),
'f',
'm', L(0), T(0),
'd', L(0), B(1),
'd', R(1), B(1),
'd', R(1), T(0),
'x',
's',
'e',
#define TWIN_MAXIMIZE_LEN 28
/* Close */
#define TWIN_CLOSE_POS TWIN_MAXIMIZE_POS + TWIN_MAXIMIZE_LEN
'm', L(0), T(0),
'd', L(0), T(0.1),
'd', G(0.4), G(0.5),
'd', L(0), B(0.9),
'd', L(0), B(1),
'd', L(0.1), B(1),
'd', G(0.5), G(0.6),
'd', R(0.9), B(1),
'd', R(1), B(1),
'd', R(1), B(0.9),
'd', G(0.6), G(0.5),
'd', R(1), T(0.1),
'd', R(1), T(0),
'd', R(0.9), T(0),
'd', G(0.5), G(0.4),
'd', L(0.1), T(0),
'x',
'p',
'e',
#define TWIN_CLOSE_LEN 51
/* Resize */
#define TWIN_RESIZE_POS TWIN_CLOSE_POS + TWIN_CLOSE_LEN
'm', L(0), G(-0.8),
'd', L(0), T(0),
'd', G(-0.8), T(0),
'd', G(-0.8), G(0.2),
'd', G(0.2), G(0.2),
'd', G(0.2), G(-0.8),
'x',
'p',
'e',
#define TWIN_RESIZE_LEN 21
};
/* clang-format on */
const uint16_t _twin_icons[] = {
TWIN_MENU_POS, TWIN_MINIMIZE_POS, TWIN_MAXIMIZE_POS,
TWIN_CLOSE_POS, TWIN_RESIZE_POS,
};
#define V(i) (g[i] << 10)
#define TWIN_ICON_FILL 0xff808080
#define TWIN_ICON_STROKE 0xff202020
void twin_icon_draw(twin_pixmap_t *pixmap,
twin_icon_t icon,
twin_matrix_t matrix)
{
twin_path_t *path = twin_path_create();
const signed char *g = _twin_itable + _twin_icons[icon];
twin_fixed_t stroke_width = twin_double_to_fixed(ICON_THIN);
twin_path_set_matrix(path, matrix);
for (;;) {
switch (*g++) {
case 'm':
twin_path_move(path, V(0), V(1));
g += 2;
continue;
case 'd':
twin_path_draw(path, V(0), V(1));
g += 2;
continue;
case 'c':
twin_path_curve(path, V(0), V(1), V(2), V(3), V(4), V(5));
g += 6;
continue;
case 'x':
twin_path_close(path);
continue;
case 'w':
stroke_width = V(0);
g += 1;
continue;
case 'f':
twin_paint_path(pixmap, TWIN_ICON_FILL, path);
twin_path_empty(path);
continue;
case 's':
twin_paint_stroke(pixmap, TWIN_ICON_STROKE, path, stroke_width);
twin_path_empty(path);
continue;
case 'p':
twin_paint_path(pixmap, TWIN_ICON_FILL, path);
twin_paint_stroke(pixmap, TWIN_ICON_STROKE, path, stroke_width);
twin_path_empty(path);
continue;
case 'e':
break;
}
break;
}
twin_path_destroy(path);
}