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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
/*
** bar.c for in /home/gayot_o/prog/lib/sdl-digit
**
** Made by olivier gayot
** Login <gayot_o@epitech.net>
**
** Started on Mon Apr 23 08:05:18 2012 olivier gayot
** Last update Mon Apr 23 08:05:18 2012 olivier gayot
*/
#include "sdl_digit.h"
void draw_horizontal_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
for (int j = 0; j < size / 5; ++j) {
int decal = ABS((size / 5) / 2 - j);
SDL_Rect begin = get_rect(rect->x + decal, rect->y + j, 0,0);
SDL_Rect end = get_rect(rect->x + size - decal, rect->y + j, 0,0);
draw_line(surf, begin, end, color);
}
}
void draw_semi_horizontal_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
for (int j = 0; j < size / 5; ++j) {
int decal = ABS((size / 5) / 2 - j);
SDL_Rect begin = get_rect(rect->x + decal, rect->y + j, 0,0);
SDL_Rect end = get_rect(rect->x + size / 2 - decal, rect->y + j, 0,0);
draw_line(surf, begin, end, color);
}
}
void draw_vertical_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
int l = size / 5;
for (int i = 0; i < l; ++i) {
int decal = ABS(l / 2 - i);
SDL_Rect begin = get_rect(rect->x + i, rect->y + decal, 0, 0);
SDL_Rect end = get_rect(rect->x + i, rect->y + size - decal, 0, 0);
draw_line(surf, begin, end, color);
}
}
void draw_semi_vertical_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
int l = size / 5;
for (int i = 0; i < l; ++i) {
int decal = ABS(l / 2 - i);
SDL_Rect begin = get_rect(rect->x + i, rect->y + decal, 0, 0);
SDL_Rect end = get_rect(rect->x + i, rect->y + size / 2 - decal, 0, 0);
draw_line(surf, begin, end, color);
}
}
void draw_diag_left_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
float l = ((float)size / 5.f);
int b = l / 2;
int h = size - 2 * b;
int a = (int)(l / (sqrtf(2.f)));
SDL_Rect begin;
SDL_Rect end;
for (int y = 0; y < h; ++y) {
begin.x = 0;
begin.y = rect->y + y;
end.x = a + y;
end.y = rect->y + y;
if (y > a)
begin.x += y - a;
if (y >= h - a)
end.x -= y - (h - a);
begin.x += rect->x;
end.x += rect->x;
draw_line(surf, begin, end, color);
}
}
void draw_diag_right_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
float l = ((float)size / 5.f);
int b = l / 2;
int h = size - 2 * b;
int a = (int)(l / (sqrtf(2.f)));
SDL_Rect begin;
SDL_Rect end;
for (int y = 0; y < h; ++y) {
begin.x = 0;
begin.y = rect->y + y;
end.x = a + y;
end.y = rect->y + y;
if (y > a)
begin.x += y - a;
if (y >= h - a)
end.x -= y - (h - a);
begin.x = h - begin.x;
end.x = h - end.x;
begin.x += rect->x;
end.x += rect->x;
draw_line(surf, begin, end, color);
}
}
void draw_backslash_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
float l = ((float)size / 5.f);
int b = l / 2;
int h = size - 2 * b;
int a = (int)(l / (sqrtf(2.f)));
SDL_Rect begin;
SDL_Rect end;
for (int y = 0; y < h; ++y) {
begin.y = rect->y + y;
end.y = rect->y + y;
begin.x = 0;
end.x = a + y / 2;
if (y > a)
begin.x += (y / 2) - a / 2;
if (y >= h - a)
end.x -= (y - (h - a)) / 2;
begin.x += rect->x;
end.x += rect->x;
draw_line(surf, begin, end, color);
}
}
void draw_slash_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
float l = ((float)size / 5.f);
int b = l / 2;
int h = size - 2 * b;
int a = (int)(l / (sqrtf(2.f)));
SDL_Rect begin;
SDL_Rect end;
for (int y = 0; y < h; ++y) {
begin.y = rect->y + y;
end.y = rect->y + y;
begin.x = 0;
end.x = a + y / 2;
if (y > a)
begin.x += (y / 2) - a / 2;
if (y >= h - a)
end.x -= (y - (h - a)) / 2;
begin.x = h / 2 - begin.x;
begin.x += rect->x;
end.x = h / 2 - end.x;
end.x += rect->x;
draw_line(surf, begin, end, color);
}
}
/* id is :
* 0
* 1 2
* 3
* 4 5
* 6
*/
void draw_bar_id(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color, int id) {
SDL_Rect *rect_;
switch (id) {
case 0:
rect_ = new_rect(rect->x + (size / 5) / 2, rect->y, 0, 0);
draw_horizontal_bar(surf, rect_, size, color);
break;
case 1:
rect_ = new_rect(rect->x, rect->y + (size / 5) / 2, 0, 0);
draw_vertical_bar(surf, rect_, size, color);
break;
case 2:
rect_ = new_rect(rect->x + size, rect->y + (size / 5) / 2, 0, 0);
draw_vertical_bar(surf, rect_, size, color);
break;
case 3:
rect_ = new_rect(rect->x + (size / 5) / 2, rect->y + size, 0, 0);
draw_horizontal_bar(surf, rect_, size, color);
break;
case 4:
rect_ = new_rect(rect->x, rect->y + size + (size / 5) / 2, 0, 0);
draw_vertical_bar(surf, rect_, size, color);
break;
case 5:
rect_ = new_rect(rect->x + size, rect->y + size + (size / 5) / 2, 0, 0);
draw_vertical_bar(surf, rect_, size, color);
break;
case 6:
rect_ = new_rect(rect->x + (size / 5) / 2, rect->y + size * 2, 0, 0);
draw_horizontal_bar(surf, rect_, size, color);
break;
case 7:
rect_ = new_rect(rect->x + (size / 5), rect->y + (size / 5), 0, 0);
draw_diag_right_bar(surf, rect_, size, color);
break;
case 8:
rect_ = new_rect(rect->x + (size / 5) + size, rect->y + (size / 5), 0, 0);
draw_diag_left_bar(surf, rect_, size, color);
break;
case 9:
rect_ = new_rect(rect->x + (size / 5), rect->y + (size / 5) + size, 0, 0);
draw_diag_right_bar(surf, rect_, size, color);
break;
case 10:
rect_ = new_rect(rect->x + (size / 5), rect->y + (size / 5) + size, 0, 0);
draw_diag_left_bar(surf, rect_, size, color);
break;
case 11:
rect_ = new_rect(rect->x + (size / 2), rect->y + (size / 5) / 2, 0, 0);
draw_vertical_bar(surf, rect_, size, color);
break;
case 12:
rect_ = new_rect(rect->x + (size / 2), rect->y + (size / 5) / 2 + size, 0, 0);
draw_vertical_bar(surf, rect_, size, color);
break;
case 13:
rect_ = new_rect(rect->x + (size / 5) / 2, rect->y + size, 0, 0);
draw_semi_horizontal_bar(surf, rect_, size, color);
break;
case 14:
rect_ = new_rect(rect->x + (size / 5) / 2 + size / 2, rect->y + size, 0, 0);
draw_semi_horizontal_bar(surf, rect_, size, color);
break;
case 15:
rect_ = new_rect(rect->x + (size / 5), rect->y + (size / 5), 0, 0);
draw_backslash_bar(surf, rect_, size, color);
break;
case 16:
rect_ = new_rect(rect->x + (size / 5) + size / 2, rect->y + (size / 5), 0, 0);
draw_slash_bar(surf, rect_, size, color);
break;
case 17:
rect_ = new_rect(rect->x + (size / 5), rect->y + (size / 5) + size, 0, 0);
draw_slash_bar(surf, rect_, size, color);
break;
case 18:
rect_ = new_rect(rect->x + (size / 5) + size / 2, rect->y + (size / 5) + size, 0, 0);
draw_backslash_bar(surf, rect_, size, color);
break;
case 19:
rect_ = new_rect(rect->x + (size / 5), rect->y + (size / 5) + size, 0, 0);
draw_backslash_bar(surf, rect_, size, color);
break;
case 20:
rect_ = new_rect(rect->x + (size / 5) + size / 2, rect->y + (size / 5) + size, 0, 0);
draw_slash_bar(surf, rect_, size, color);
break;
default:
return;
break;
}
free(rect_);
}
|