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