Mercurial > mplayer.hg
annotate gui/ui/render.c @ 35203:95e5df93e174
Also add CONFIG_LZO define.
author | reimar |
---|---|
date | Tue, 30 Oct 2012 17:47:18 +0000 |
parents | 5a45efc630b8 |
children | 848ca0b6d5ca |
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" |
32982 | 30 #include "codec-cfg.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
31 #include "config.h" |
32963 | 32 #include "libavutil/avstring.h" |
33 #include "libmpdemux/stheader.h" | |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
34 #include "mixer.h" |
32954 | 35 #include "osdep/timer.h" |
32963 | 36 #include "stream/stream.h" |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
37 |
33269 | 38 #define DLABEL_DELAY 2500 // in milliseconds |
39 | |
32963 | 40 static char *image_buffer; |
41 static int image_width; | |
32956 | 42 |
32975
0dc9d64cd64e
Make functions static that are only used inside the file.
ib
parents:
32973
diff
changeset
|
43 static char *Translate(char *str) |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
44 { |
32963 | 45 static char trbuf[512]; |
46 char tmp[512]; | |
32972 | 47 unsigned int i, c; |
32963 | 48 int t; |
32967 | 49 mixer_t *mixer; |
32963 | 50 |
32972 | 51 *trbuf = 0; |
32963 | 52 |
32972 | 53 for (c = 0, i = 0; i < strlen(str); i++) { |
32963 | 54 if (str[i] != '$') { |
32972 | 55 if (c + 1 < sizeof(trbuf)) { |
32973 | 56 trbuf[c++] = str[i]; |
57 trbuf[c] = 0; | |
32972 | 58 } |
32963 | 59 } else { |
60 switch (str[++i]) { | |
61 case 't': | |
33555 | 62 snprintf(tmp, sizeof(tmp), "%02d", guiInfo.Track); |
32963 | 63 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
64 break; | |
65 | |
66 case 'o': | |
67 TranslateFilename(0, tmp, sizeof(tmp)); | |
68 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
69 break; | |
70 | |
71 case 'f': | |
72 TranslateFilename(1, tmp, sizeof(tmp)); | |
73 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
74 break; | |
75 | |
76 case 'F': | |
77 TranslateFilename(2, tmp, sizeof(tmp)); | |
78 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
79 break; | |
80 | |
81 case '6': | |
33897 | 82 t = guiInfo.RunningTime; |
32963 | 83 goto calclengthhhmmss; |
84 | |
85 case '1': | |
33897 | 86 t = guiInfo.ElapsedTime; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
87 calclengthhhmmss: |
32963 | 88 snprintf(tmp, sizeof(tmp), "%02d:%02d:%02d", t / 3600, t / 60 % 60, t % 60); |
89 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
90 break; | |
91 | |
92 case '7': | |
33897 | 93 t = guiInfo.RunningTime; |
32963 | 94 goto calclengthmmmmss; |
95 | |
96 case '2': | |
33897 | 97 t = guiInfo.ElapsedTime; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
98 calclengthmmmmss: |
32963 | 99 snprintf(tmp, sizeof(tmp), "%04d:%02d", t / 60, t % 60); |
100 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
101 break; | |
102 | |
103 case '3': | |
33897 | 104 snprintf(tmp, sizeof(tmp), "%02d", guiInfo.ElapsedTime / 3600); |
32963 | 105 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
106 break; | |
107 | |
108 case '4': | |
33897 | 109 snprintf(tmp, sizeof(tmp), "%02d", (guiInfo.ElapsedTime / 60) % 60); |
32963 | 110 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
111 break; | |
112 | |
113 case '5': | |
33897 | 114 snprintf(tmp, sizeof(tmp), "%02d", guiInfo.ElapsedTime % 60); |
32963 | 115 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
116 break; | |
117 | |
118 case '8': | |
33897 | 119 snprintf(tmp, sizeof(tmp), "%01d:%02d:%02d", guiInfo.ElapsedTime / 3600, (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60); |
32963 | 120 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
121 break; | |
122 | |
123 case 'v': | |
33555 | 124 snprintf(tmp, sizeof(tmp), "%3.2f%%", guiInfo.Volume); |
32963 | 125 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
126 break; | |
127 | |
128 case 'V': | |
33555 | 129 snprintf(tmp, sizeof(tmp), "%3.1f", guiInfo.Volume); |
32963 | 130 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
131 break; | |
132 | |
133 case 'b': | |
33555 | 134 snprintf(tmp, sizeof(tmp), "%3.2f%%", guiInfo.Balance); |
32963 | 135 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
136 break; | |
137 | |
138 case 'B': | |
33555 | 139 snprintf(tmp, sizeof(tmp), "%3.1f", guiInfo.Balance); |
32963 | 140 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
141 break; | |
142 | |
143 case 'x': | |
33901 | 144 snprintf(tmp, sizeof(tmp), "%d", guiInfo.VideoWidth); |
32963 | 145 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
146 break; | |
147 | |
148 case 'y': | |
33901 | 149 snprintf(tmp, sizeof(tmp), "%d", guiInfo.VideoHeight); |
32963 | 150 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
151 break; | |
152 | |
153 case 'C': | |
33774
474ffcdcc6e7
Change guiInterface_t void pointer member declarations.
ib
parents:
33773
diff
changeset
|
154 snprintf(tmp, sizeof(tmp), "%s", guiInfo.sh_video ? guiInfo.sh_video->codec->name : ""); |
32963 | 155 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
156 break; | |
157 | |
158 case 's': | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33556
diff
changeset
|
159 if (guiInfo.Playing == GUI_STOP) |
32963 | 160 av_strlcat(trbuf, "s", sizeof(trbuf)); |
161 break; | |
162 | |
33616 | 163 case 'l': // legacy |
164 case 'p': | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33556
diff
changeset
|
165 if (guiInfo.Playing == GUI_PLAY) |
32963 | 166 av_strlcat(trbuf, "p", sizeof(trbuf)); |
167 break; | |
168 | |
169 case 'e': | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33556
diff
changeset
|
170 if (guiInfo.Playing == GUI_PAUSE) |
32963 | 171 av_strlcat(trbuf, "e", sizeof(trbuf)); |
172 break; | |
173 | |
174 case 'a': | |
175 | |
33555 | 176 mixer = mpctx_get_mixer(guiInfo.mpcontext); |
32967 | 177 |
32963 | 178 if (mixer->muted) { |
179 av_strlcat(trbuf, "n", sizeof(trbuf)); | |
180 break; | |
181 } | |
182 | |
33646 | 183 switch (guiInfo.AudioChannels) { |
32963 | 184 case 0: |
185 av_strlcat(trbuf, "n", sizeof(trbuf)); | |
186 break; | |
187 | |
188 case 1: | |
189 av_strlcat(trbuf, "m", sizeof(trbuf)); | |
190 break; | |
191 | |
192 case 2: | |
193 av_strlcat(trbuf, "t", sizeof(trbuf)); | |
194 break; | |
195 } | |
196 | |
197 break; | |
198 | |
199 case 'T': | |
33555 | 200 switch (guiInfo.StreamType) { |
32963 | 201 case STREAMTYPE_FILE: |
202 av_strlcat(trbuf, "f", sizeof(trbuf)); | |
203 break; | |
204 | |
34077 | 205 case STREAMTYPE_STREAM: |
206 av_strlcat(trbuf, "u", sizeof(trbuf)); | |
207 break; | |
208 | |
34387 | 209 case STREAMTYPE_CDDA: |
210 av_strlcat(trbuf, "a", sizeof(trbuf)); | |
211 break; | |
212 | |
32963 | 213 case STREAMTYPE_VCD: |
214 av_strlcat(trbuf, "v", sizeof(trbuf)); | |
215 break; | |
216 | |
217 case STREAMTYPE_DVD: | |
218 av_strlcat(trbuf, "d", sizeof(trbuf)); | |
219 break; | |
220 | |
221 default: | |
222 av_strlcat(trbuf, " ", sizeof(trbuf)); | |
223 break; | |
224 } | |
225 break; | |
226 | |
227 case '$': | |
228 av_strlcat(trbuf, "$", sizeof(trbuf)); | |
229 break; | |
230 | |
231 default: | |
232 continue; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
233 } |
32963 | 234 |
235 c = strlen(trbuf); | |
236 } | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
237 } |
32963 | 238 |
239 return trbuf; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
240 } |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
241 |
33555 | 242 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
|
243 { |
32963 | 244 int i = 0, ix, iy; |
245 uint32_t *buf = NULL; | |
246 uint32_t *drw = NULL; | |
247 register uint32_t tmp; | |
248 | |
249 /* register uint32_t yc; */ | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
250 |
32963 | 251 if (!bf || (bf->Image == NULL)) |
252 return; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
253 |
32963 | 254 i = bf->Width * (bf->Height / max) * ofs; |
255 buf = (uint32_t *)image_buffer; | |
256 drw = (uint32_t *)bf->Image; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
257 |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
258 #if 1 |
32963 | 259 for (iy = y; iy < (int)(y + bf->Height / max); iy++) |
260 for (ix = x; ix < (int)(x + bf->Width); ix++) { | |
261 tmp = drw[i++]; | |
262 | |
33534 | 263 if (!IS_TRANSPARENT(tmp)) |
32963 | 264 buf[iy * image_width + ix] = tmp; |
265 } | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
266 #else |
32963 | 267 yc = y * image_width; |
268 | |
269 for (iy = y; iy < (int)(y + bf->Height / max); iy++) { | |
270 for (ix = x; ix < (int)(x + bf->Width); ix++) { | |
271 tmp = drw[i++]; | |
272 | |
33534 | 273 if (!IS_TRANSPARENT(tmp)) |
32963 | 274 buf[yc + ix] = tmp; |
275 } | |
276 | |
277 yc += image_width; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
278 } |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
279 #endif |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
280 } |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
281 |
33555 | 282 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
|
283 { |
32963 | 284 int i = 0, w, r, ix, iy; |
285 uint32_t *buf = NULL; | |
286 uint32_t *drw = NULL; | |
287 register uint32_t tmp; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
288 |
32963 | 289 if (!bf || (bf->Image == NULL)) |
290 return; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
291 |
32963 | 292 buf = (uint32_t *)image_buffer; |
293 drw = (uint32_t *)bf->Image; | |
294 w = bf->Width * frac; | |
295 r = bf->Width - w; | |
296 | |
297 for (iy = y; iy < (int)(y + bf->Height); iy++) { | |
298 for (ix = x; ix < (int)(x + w); ix++) { | |
299 tmp = drw[i++]; | |
300 | |
33534 | 301 if (!IS_TRANSPARENT(tmp)) |
32963 | 302 buf[iy * image_width + ix] = tmp; |
303 } | |
304 | |
305 i += r; | |
306 } | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
307 } |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
308 |
33548 | 309 void RenderAll(wsTWindow *window, wItem *Items, int nrItems, char *db) |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
310 { |
32963 | 311 wItem *item; |
33555 | 312 guiImage *image = NULL; |
32963 | 313 int i, ofs; |
314 | |
315 image_buffer = db; | |
316 image_width = window->Width; | |
317 | |
318 for (i = 0; i < nrItems + 1; i++) { | |
319 item = &Items[i]; | |
32966
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
320 |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
321 switch (item->pressed) { |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
322 case btnPressed: |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
323 ofs = 0; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
324 break; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
325 |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
326 case btnReleased: |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
327 ofs = 1; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
328 break; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
329 |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
330 default: |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
331 ofs = 2; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
332 break; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
333 } |
32963 | 334 |
335 switch (item->type) { | |
336 case itButton: | |
337 PutImage(&item->Bitmap, item->x, item->y, 3, ofs); | |
338 break; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
339 |
32963 | 340 case itPotmeter: |
341 if (item->numphases == 1) | |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
342 SimplePotmeterPutImage(&item->Bitmap, item->x, item->y, item->value / 100.0); |
32963 | 343 else |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
344 PutImage(&item->Bitmap, item->x, item->y, item->numphases, (item->numphases - 1) * (item->value / 100.0)); |
32963 | 345 break; |
346 | |
347 case itHPotmeter: | |
348 if (item->numphases == 1) | |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
349 SimplePotmeterPutImage(&item->Bitmap, item->x, item->y, item->value / 100.0); |
32963 | 350 else |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
351 PutImage(&item->Bitmap, item->x, item->y, item->numphases, (item->numphases - 1) * (item->value / 100.0)); |
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
352 PutImage(&item->Mask, item->x + (item->width - item->pwidth) * (item->value / 100.0), item->y, 3, ofs); |
32963 | 353 break; |
354 | |
355 case itVPotmeter: | |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
356 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
|
357 PutImage(&item->Mask, item->x, item->y + (item->height - item->pheight) * (1.0 - item->value / 100.0), 3, ofs); |
32963 | 358 break; |
359 | |
360 case itSLabel: | |
32969 | 361 if (item->width == -1) |
362 item->width = fntTextWidth(item->fontid, item->label); | |
33971 | 363 image = fntTextRender(item, 0, item->label); |
32963 | 364 if (image) |
365 PutImage(image, item->x, item->y, 1, 0); | |
32969 | 366 break; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
367 |
32963 | 368 case itDLabel: |
369 { | |
370 int x; | |
371 unsigned int d; | |
372 char *t = Translate(item->label); | |
373 | |
374 if (!item->text || (strcmp(item->text, t) != 0)) { | |
375 free(item->text); | |
376 item->text = strdup(t); | |
377 item->textwidth = fntTextWidth(item->fontid, t); | |
378 item->starttime = GetTimerMS(); | |
379 item->last_x = 0; | |
32761
3ceeb62a1125
Improve the readability of dynamic labels which scroll.
ib
parents:
32759
diff
changeset
|
380 } |
32963 | 381 |
382 d = GetTimerMS() - item->starttime; | |
383 | |
32964 | 384 if (d < DLABEL_DELAY) |
32963 | 385 x = item->last_x; // don't scroll yet |
386 else { | |
387 int l; | |
388 char c[2]; | |
389 | |
390 l = (item->textwidth ? item->textwidth : item->width); | |
32964 | 391 x = l - ((d - DLABEL_DELAY) / 20) % l - 1; |
32963 | 392 c[0] = *item->text; |
393 c[1] = '\0'; | |
394 | |
395 if (x < (fntTextWidth(item->fontid, c) + 1) >> 1) { | |
396 item->starttime = GetTimerMS(); // stop again | |
397 item->last_x = x; // at current x pos | |
398 } | |
32761
3ceeb62a1125
Improve the readability of dynamic labels which scroll.
ib
parents:
32759
diff
changeset
|
399 } |
32963 | 400 |
33971 | 401 image = fntTextRender(item, x, t); |
32963 | 402 } |
403 | |
404 if (image) | |
405 PutImage(image, item->x, item->y, 1, 0); | |
406 | |
407 break; | |
408 } | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
409 } |
32963 | 410 |
33548 | 411 wsConvert(window, db); |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
412 } |