Mercurial > mplayer.hg
annotate gui/ui/render.c @ 36789:82a86ba65249
configure (cosmetic): Adjust indent and add blank lines.
author | ib |
---|---|
date | Wed, 19 Feb 2014 15:30:22 +0000 |
parents | 28ea255e40ce |
children | 1548470f45f8 |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
18 |
33123
9566100d88a1
Replace inttypes.h by stdint.h and remove inttypes.h where unneeded.
ib
parents:
32982
diff
changeset
|
19 #include <stdint.h> |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
20 #include <stdio.h> |
32963 | 21 #include <stdlib.h> |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
22 #include <string.h> |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
23 |
33556 | 24 #include "render.h" |
32952 | 25 #include "gui/interface.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
25603
diff
changeset
|
26 #include "gui/skin/font.h" |
34175 | 27 #include "gui/util/string.h" |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
28 |
32963 | 29 #include "access_mpcontext.h" |
36032 | 30 #include "mixer.h" |
32963 | 31 #include "libavutil/avstring.h" |
32954 | 32 #include "osdep/timer.h" |
32963 | 33 #include "stream/stream.h" |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
34 |
33269 | 35 #define DLABEL_DELAY 2500 // in milliseconds |
36 | |
32963 | 37 static char *image_buffer; |
38 static int image_width; | |
32956 | 39 |
32975
0dc9d64cd64e
Make functions static that are only used inside the file.
ib
parents:
32973
diff
changeset
|
40 static char *Translate(char *str) |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
41 { |
32963 | 42 static char trbuf[512]; |
43 char tmp[512]; | |
32972 | 44 unsigned int i, c; |
32963 | 45 int t; |
35536 | 46 mixer_t *mixer = NULL; |
32963 | 47 |
32972 | 48 *trbuf = 0; |
32963 | 49 |
32972 | 50 for (c = 0, i = 0; i < strlen(str); i++) { |
32963 | 51 if (str[i] != '$') { |
32972 | 52 if (c + 1 < sizeof(trbuf)) { |
32973 | 53 trbuf[c++] = str[i]; |
54 trbuf[c] = 0; | |
32972 | 55 } |
32963 | 56 } else { |
57 switch (str[++i]) { | |
58 case 't': | |
33555 | 59 snprintf(tmp, sizeof(tmp), "%02d", guiInfo.Track); |
32963 | 60 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
61 break; | |
62 | |
63 case 'o': | |
64 TranslateFilename(0, tmp, sizeof(tmp)); | |
65 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
66 break; | |
67 | |
68 case 'f': | |
69 TranslateFilename(1, tmp, sizeof(tmp)); | |
70 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
71 break; | |
72 | |
73 case 'F': | |
74 TranslateFilename(2, tmp, sizeof(tmp)); | |
75 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
76 break; | |
77 | |
78 case '6': | |
33897 | 79 t = guiInfo.RunningTime; |
32963 | 80 goto calclengthhhmmss; |
81 | |
82 case '1': | |
33897 | 83 t = guiInfo.ElapsedTime; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
84 calclengthhhmmss: |
32963 | 85 snprintf(tmp, sizeof(tmp), "%02d:%02d:%02d", t / 3600, t / 60 % 60, t % 60); |
86 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
87 break; | |
88 | |
89 case '7': | |
33897 | 90 t = guiInfo.RunningTime; |
32963 | 91 goto calclengthmmmmss; |
92 | |
93 case '2': | |
33897 | 94 t = guiInfo.ElapsedTime; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
95 calclengthmmmmss: |
32963 | 96 snprintf(tmp, sizeof(tmp), "%04d:%02d", t / 60, t % 60); |
97 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
98 break; | |
99 | |
100 case '3': | |
33897 | 101 snprintf(tmp, sizeof(tmp), "%02d", guiInfo.ElapsedTime / 3600); |
32963 | 102 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
103 break; | |
104 | |
105 case '4': | |
33897 | 106 snprintf(tmp, sizeof(tmp), "%02d", (guiInfo.ElapsedTime / 60) % 60); |
32963 | 107 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
108 break; | |
109 | |
110 case '5': | |
33897 | 111 snprintf(tmp, sizeof(tmp), "%02d", guiInfo.ElapsedTime % 60); |
32963 | 112 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
113 break; | |
114 | |
115 case '8': | |
33897 | 116 snprintf(tmp, sizeof(tmp), "%01d:%02d:%02d", guiInfo.ElapsedTime / 3600, (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60); |
32963 | 117 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
118 break; | |
119 | |
120 case 'v': | |
33555 | 121 snprintf(tmp, sizeof(tmp), "%3.2f%%", guiInfo.Volume); |
32963 | 122 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
123 break; | |
124 | |
125 case 'V': | |
33555 | 126 snprintf(tmp, sizeof(tmp), "%3.1f", guiInfo.Volume); |
32963 | 127 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
128 break; | |
129 | |
130 case 'b': | |
33555 | 131 snprintf(tmp, sizeof(tmp), "%3.2f%%", guiInfo.Balance); |
32963 | 132 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
133 break; | |
134 | |
135 case 'B': | |
33555 | 136 snprintf(tmp, sizeof(tmp), "%3.1f", guiInfo.Balance); |
32963 | 137 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
138 break; | |
139 | |
140 case 'x': | |
33901 | 141 snprintf(tmp, sizeof(tmp), "%d", guiInfo.VideoWidth); |
32963 | 142 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
143 break; | |
144 | |
145 case 'y': | |
33901 | 146 snprintf(tmp, sizeof(tmp), "%d", guiInfo.VideoHeight); |
32963 | 147 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
148 break; | |
149 | |
150 case 'C': | |
35462 | 151 snprintf(tmp, sizeof(tmp), "%s", guiInfo.CodecName ? guiInfo.CodecName : ""); |
32963 | 152 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
153 break; | |
154 | |
155 case 's': | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33556
diff
changeset
|
156 if (guiInfo.Playing == GUI_STOP) |
32963 | 157 av_strlcat(trbuf, "s", sizeof(trbuf)); |
158 break; | |
159 | |
33616 | 160 case 'l': // legacy |
161 case 'p': | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33556
diff
changeset
|
162 if (guiInfo.Playing == GUI_PLAY) |
32963 | 163 av_strlcat(trbuf, "p", sizeof(trbuf)); |
164 break; | |
165 | |
166 case 'e': | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33556
diff
changeset
|
167 if (guiInfo.Playing == GUI_PAUSE) |
32963 | 168 av_strlcat(trbuf, "e", sizeof(trbuf)); |
169 break; | |
170 | |
171 case 'a': | |
172 | |
35536 | 173 if (guiInfo.mpcontext) |
35538 | 174 mixer = mpctx_get_mixer(guiInfo.mpcontext); |
32967 | 175 |
35536 | 176 if (mixer && mixer->muted) { |
32963 | 177 av_strlcat(trbuf, "n", sizeof(trbuf)); |
178 break; | |
179 } | |
180 | |
33646 | 181 switch (guiInfo.AudioChannels) { |
32963 | 182 case 0: |
183 av_strlcat(trbuf, "n", sizeof(trbuf)); | |
184 break; | |
185 | |
186 case 1: | |
187 av_strlcat(trbuf, "m", sizeof(trbuf)); | |
188 break; | |
189 | |
190 case 2: | |
191 av_strlcat(trbuf, "t", sizeof(trbuf)); | |
192 break; | |
193 } | |
194 | |
195 break; | |
196 | |
197 case 'T': | |
33555 | 198 switch (guiInfo.StreamType) { |
32963 | 199 case STREAMTYPE_FILE: |
200 av_strlcat(trbuf, "f", sizeof(trbuf)); | |
201 break; | |
202 | |
34077 | 203 case STREAMTYPE_STREAM: |
204 av_strlcat(trbuf, "u", sizeof(trbuf)); | |
205 break; | |
206 | |
34387 | 207 case STREAMTYPE_CDDA: |
208 av_strlcat(trbuf, "a", sizeof(trbuf)); | |
209 break; | |
210 | |
32963 | 211 case STREAMTYPE_VCD: |
212 av_strlcat(trbuf, "v", sizeof(trbuf)); | |
213 break; | |
214 | |
215 case STREAMTYPE_DVD: | |
216 av_strlcat(trbuf, "d", sizeof(trbuf)); | |
217 break; | |
218 | |
36429 | 219 case STREAMTYPE_TV: |
220 case STREAMTYPE_DVB: | |
221 av_strlcat(trbuf, "b", sizeof(trbuf)); | |
222 break; | |
223 | |
32963 | 224 default: |
225 av_strlcat(trbuf, " ", sizeof(trbuf)); | |
226 break; | |
227 } | |
228 break; | |
229 | |
230 case '$': | |
231 av_strlcat(trbuf, "$", sizeof(trbuf)); | |
232 break; | |
233 | |
234 default: | |
235 continue; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
236 } |
32963 | 237 |
238 c = strlen(trbuf); | |
239 } | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
240 } |
32963 | 241 |
242 return trbuf; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
243 } |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
244 |
33555 | 245 static void PutImage(guiImage *bf, int x, int y, int max, int ofs) |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
246 { |
32963 | 247 int i = 0, ix, iy; |
248 uint32_t *buf = NULL; | |
249 uint32_t *drw = NULL; | |
250 register uint32_t tmp; | |
251 | |
252 /* register uint32_t yc; */ | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
253 |
32963 | 254 if (!bf || (bf->Image == NULL)) |
255 return; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
256 |
32963 | 257 i = bf->Width * (bf->Height / max) * ofs; |
258 buf = (uint32_t *)image_buffer; | |
259 drw = (uint32_t *)bf->Image; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
260 |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
261 #if 1 |
32963 | 262 for (iy = y; iy < (int)(y + bf->Height / max); iy++) |
263 for (ix = x; ix < (int)(x + bf->Width); ix++) { | |
264 tmp = drw[i++]; | |
265 | |
33534 | 266 if (!IS_TRANSPARENT(tmp)) |
32963 | 267 buf[iy * image_width + ix] = tmp; |
268 } | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
269 #else |
32963 | 270 yc = y * image_width; |
271 | |
272 for (iy = y; iy < (int)(y + bf->Height / max); iy++) { | |
273 for (ix = x; ix < (int)(x + bf->Width); ix++) { | |
274 tmp = drw[i++]; | |
275 | |
33534 | 276 if (!IS_TRANSPARENT(tmp)) |
32963 | 277 buf[yc + ix] = tmp; |
278 } | |
279 | |
280 yc += image_width; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
281 } |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
282 #endif |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
283 } |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
284 |
33555 | 285 static void SimplePotmeterPutImage(guiImage *bf, int x, int y, float frac) |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
286 { |
32963 | 287 int i = 0, w, r, ix, iy; |
288 uint32_t *buf = NULL; | |
289 uint32_t *drw = NULL; | |
290 register uint32_t tmp; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
291 |
32963 | 292 if (!bf || (bf->Image == NULL)) |
293 return; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
294 |
32963 | 295 buf = (uint32_t *)image_buffer; |
296 drw = (uint32_t *)bf->Image; | |
297 w = bf->Width * frac; | |
298 r = bf->Width - w; | |
299 | |
300 for (iy = y; iy < (int)(y + bf->Height); iy++) { | |
301 for (ix = x; ix < (int)(x + w); ix++) { | |
302 tmp = drw[i++]; | |
303 | |
33534 | 304 if (!IS_TRANSPARENT(tmp)) |
32963 | 305 buf[iy * image_width + ix] = tmp; |
306 } | |
307 | |
308 i += r; | |
309 } | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
310 } |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
311 |
35688 | 312 void RenderAll(wsWindow *window, guiItem *Items, int nrItems, char *db) |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
313 { |
35688 | 314 guiItem *item; |
33555 | 315 guiImage *image = NULL; |
32963 | 316 int i, ofs; |
317 | |
318 image_buffer = db; | |
319 image_width = window->Width; | |
320 | |
321 for (i = 0; i < nrItems + 1; i++) { | |
322 item = &Items[i]; | |
32966
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
323 |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
324 switch (item->pressed) { |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
325 case btnPressed: |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
326 ofs = 0; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
327 break; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
328 |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
329 case btnReleased: |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
330 ofs = 1; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
331 break; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
332 |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
333 default: |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
334 ofs = 2; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
335 break; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
336 } |
32963 | 337 |
338 switch (item->type) { | |
339 case itButton: | |
35541 | 340 |
32963 | 341 PutImage(&item->Bitmap, item->x, item->y, 3, ofs); |
342 break; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
343 |
32963 | 344 case itPotmeter: |
35541 | 345 |
32963 | 346 if (item->numphases == 1) |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
347 SimplePotmeterPutImage(&item->Bitmap, item->x, item->y, item->value / 100.0); |
32963 | 348 else |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
349 PutImage(&item->Bitmap, item->x, item->y, item->numphases, (item->numphases - 1) * (item->value / 100.0)); |
35541 | 350 |
32963 | 351 break; |
352 | |
353 case itHPotmeter: | |
35541 | 354 |
32963 | 355 if (item->numphases == 1) |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
356 SimplePotmeterPutImage(&item->Bitmap, item->x, item->y, item->value / 100.0); |
32963 | 357 else |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
358 PutImage(&item->Bitmap, item->x, item->y, item->numphases, (item->numphases - 1) * (item->value / 100.0)); |
35541 | 359 |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
360 PutImage(&item->Mask, item->x + (item->width - item->pwidth) * (item->value / 100.0), item->y, 3, ofs); |
32963 | 361 break; |
362 | |
363 case itVPotmeter: | |
35541 | 364 |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
365 PutImage(&item->Bitmap, item->x, item->y, item->numphases, item->numphases * (1.0 - item->value / 100.0)); |
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
366 PutImage(&item->Mask, item->x, item->y + (item->height - item->pheight) * (1.0 - item->value / 100.0), 3, ofs); |
32963 | 367 break; |
368 | |
369 case itSLabel: | |
35541 | 370 |
32969 | 371 if (item->width == -1) |
372 item->width = fntTextWidth(item->fontid, item->label); | |
35541 | 373 |
33971 | 374 image = fntTextRender(item, 0, item->label); |
35541 | 375 |
32963 | 376 if (image) |
377 PutImage(image, item->x, item->y, 1, 0); | |
35541 | 378 |
32969 | 379 break; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
380 |
32963 | 381 case itDLabel: |
382 { | |
383 int x; | |
384 unsigned int d; | |
385 char *t = Translate(item->label); | |
386 | |
387 if (!item->text || (strcmp(item->text, t) != 0)) { | |
388 free(item->text); | |
389 item->text = strdup(t); | |
390 item->textwidth = fntTextWidth(item->fontid, t); | |
391 item->starttime = GetTimerMS(); | |
392 item->last_x = 0; | |
32761
3ceeb62a1125
Improve the readability of dynamic labels which scroll.
ib
parents:
32759
diff
changeset
|
393 } |
32963 | 394 |
395 d = GetTimerMS() - item->starttime; | |
396 | |
32964 | 397 if (d < DLABEL_DELAY) |
32963 | 398 x = item->last_x; // don't scroll yet |
399 else { | |
400 int l; | |
401 char c[2]; | |
402 | |
403 l = (item->textwidth ? item->textwidth : item->width); | |
35362 | 404 x = (l ? l - ((d - DLABEL_DELAY) / 20) % l - 1 : 0); |
32963 | 405 c[0] = *item->text; |
406 c[1] = '\0'; | |
407 | |
408 if (x < (fntTextWidth(item->fontid, c) + 1) >> 1) { | |
409 item->starttime = GetTimerMS(); // stop again | |
410 item->last_x = x; // at current x pos | |
411 } | |
32761
3ceeb62a1125
Improve the readability of dynamic labels which scroll.
ib
parents:
32759
diff
changeset
|
412 } |
32963 | 413 |
33971 | 414 image = fntTextRender(item, x, t); |
32963 | 415 } |
416 | |
417 if (image) | |
418 PutImage(image, item->x, item->y, 1, 0); | |
419 | |
420 break; | |
421 } | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
422 } |
32963 | 423 |
35744 | 424 wsImageRender(window, db); |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
425 } |