comparison gui/ui/render.c @ 33556:520fb0f7544c

Rename GUI directory 'mplayer' and some files in it. The directory 'mplayer' contains the files for the user interface and has thus been renamed 'ui'. Inside this directory the following files have been renamed to better reflect their contents: mw.c -> main.c sw.c -> sub.c pb.c -> playbar.c gui_common.* -> render.* play.* -> actions.*
author ib
date Sat, 18 Jun 2011 16:03:31 +0000
parents gui/mplayer/gui_common.c@c5a19bbeac2b
children 1f9a31d4f114
comparison
equal deleted inserted replaced
33555:c5a19bbeac2b 33556:520fb0f7544c
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 */
18
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 #include "render.h"
25 #include "gui/interface.h"
26 #include "gui/skin/font.h"
27
28 #include "access_mpcontext.h"
29 #include "codec-cfg.h"
30 #include "config.h"
31 #include "help_mp.h"
32 #include "libavutil/avstring.h"
33 #include "libmpdemux/stheader.h"
34 #include "mixer.h"
35 #include "osdep/timer.h"
36 #include "stream/stream.h"
37
38 #define DLABEL_DELAY 2500 // in milliseconds
39
40 static char *image_buffer;
41 static int image_width;
42
43 static void TranslateFilename(int c, char *tmp, size_t tmplen)
44 {
45 int i;
46 char *p;
47 size_t len;
48
49 switch (guiInfo.StreamType) {
50 case STREAMTYPE_STREAM:
51 av_strlcpy(tmp, guiInfo.Filename, tmplen);
52 break;
53
54 case STREAMTYPE_FILE:
55 if (guiInfo.Filename && guiInfo.Filename[0]) {
56 p = strrchr(guiInfo.Filename, '/');
57
58 if (p)
59 av_strlcpy(tmp, p + 1, tmplen);
60 else
61 av_strlcpy(tmp, guiInfo.Filename, tmplen);
62
63 len = strlen(tmp);
64
65 if (len > 3 && tmp[len - 3] == '.')
66 tmp[len - 3] = 0;
67 else if (len > 4 && tmp[len - 4] == '.')
68 tmp[len - 4] = 0;
69 else if (len > 5 && tmp[len - 5] == '.')
70 tmp[len - 5] = 0;
71 } else
72 av_strlcpy(tmp, MSGTR_NoFileLoaded, tmplen);
73 break;
74
75 #ifdef CONFIG_DVDREAD
76 case STREAMTYPE_DVD:
77 if (guiInfo.DVD.current_chapter)
78 snprintf(tmp, tmplen, MSGTR_Chapter, guiInfo.DVD.current_chapter);
79 else
80 av_strlcat(tmp, MSGTR_NoChapter, tmplen);
81 break;
82 #endif
83
84 #ifdef CONFIG_VCD
85 case STREAMTYPE_VCD:
86 snprintf(tmp, tmplen, MSGTR_VCDTrack, guiInfo.Track);
87 break;
88 #endif
89
90 default:
91 av_strlcpy(tmp, MSGTR_NoMediaOpened, tmplen);
92 break;
93 }
94
95 if (c) {
96 for (i = 0; tmp[i]; i++) {
97 int t = 0;
98
99 if (c == 1)
100 if (tmp[i] >= 'A' && tmp[i] <= 'Z')
101 t = 32;
102
103 if (c == 2)
104 if (tmp[i] >= 'a' && tmp[i] <= 'z')
105 t = -32;
106
107 tmp[i] = (char)(tmp[i] + t);
108 }
109 }
110 }
111
112 static char *Translate(char *str)
113 {
114 static char trbuf[512];
115 char tmp[512];
116 unsigned int i, c;
117 int t;
118 mixer_t *mixer;
119
120 *trbuf = 0;
121
122 for (c = 0, i = 0; i < strlen(str); i++) {
123 if (str[i] != '$') {
124 if (c + 1 < sizeof(trbuf)) {
125 trbuf[c++] = str[i];
126 trbuf[c] = 0;
127 }
128 } else {
129 switch (str[++i]) {
130 case 't':
131 snprintf(tmp, sizeof(tmp), "%02d", guiInfo.Track);
132 av_strlcat(trbuf, tmp, sizeof(trbuf));
133 break;
134
135 case 'o':
136 TranslateFilename(0, tmp, sizeof(tmp));
137 av_strlcat(trbuf, tmp, sizeof(trbuf));
138 break;
139
140 case 'f':
141 TranslateFilename(1, tmp, sizeof(tmp));
142 av_strlcat(trbuf, tmp, sizeof(trbuf));
143 break;
144
145 case 'F':
146 TranslateFilename(2, tmp, sizeof(tmp));
147 av_strlcat(trbuf, tmp, sizeof(trbuf));
148 break;
149
150 case '6':
151 t = guiInfo.LengthInSec;
152 goto calclengthhhmmss;
153
154 case '1':
155 t = guiInfo.TimeSec;
156 calclengthhhmmss:
157 snprintf(tmp, sizeof(tmp), "%02d:%02d:%02d", t / 3600, t / 60 % 60, t % 60);
158 av_strlcat(trbuf, tmp, sizeof(trbuf));
159 break;
160
161 case '7':
162 t = guiInfo.LengthInSec;
163 goto calclengthmmmmss;
164
165 case '2':
166 t = guiInfo.TimeSec;
167 calclengthmmmmss:
168 snprintf(tmp, sizeof(tmp), "%04d:%02d", t / 60, t % 60);
169 av_strlcat(trbuf, tmp, sizeof(trbuf));
170 break;
171
172 case '3':
173 snprintf(tmp, sizeof(tmp), "%02d", guiInfo.TimeSec / 3600);
174 av_strlcat(trbuf, tmp, sizeof(trbuf));
175 break;
176
177 case '4':
178 snprintf(tmp, sizeof(tmp), "%02d", (guiInfo.TimeSec / 60) % 60);
179 av_strlcat(trbuf, tmp, sizeof(trbuf));
180 break;
181
182 case '5':
183 snprintf(tmp, sizeof(tmp), "%02d", guiInfo.TimeSec % 60);
184 av_strlcat(trbuf, tmp, sizeof(trbuf));
185 break;
186
187 case '8':
188 snprintf(tmp, sizeof(tmp), "%01d:%02d:%02d", guiInfo.TimeSec / 3600, (guiInfo.TimeSec / 60) % 60, guiInfo.TimeSec % 60);
189 av_strlcat(trbuf, tmp, sizeof(trbuf));
190 break;
191
192 case 'v':
193 snprintf(tmp, sizeof(tmp), "%3.2f%%", guiInfo.Volume);
194 av_strlcat(trbuf, tmp, sizeof(trbuf));
195 break;
196
197 case 'V':
198 snprintf(tmp, sizeof(tmp), "%3.1f", guiInfo.Volume);
199 av_strlcat(trbuf, tmp, sizeof(trbuf));
200 break;
201
202 case 'b':
203 snprintf(tmp, sizeof(tmp), "%3.2f%%", guiInfo.Balance);
204 av_strlcat(trbuf, tmp, sizeof(trbuf));
205 break;
206
207 case 'B':
208 snprintf(tmp, sizeof(tmp), "%3.1f", guiInfo.Balance);
209 av_strlcat(trbuf, tmp, sizeof(trbuf));
210 break;
211
212 case 'd':
213 snprintf(tmp, sizeof(tmp), "%d", guiInfo.FrameDrop);
214 av_strlcat(trbuf, tmp, sizeof(trbuf));
215 break;
216
217 case 'x':
218 snprintf(tmp, sizeof(tmp), "%d", guiInfo.MovieWidth);
219 av_strlcat(trbuf, tmp, sizeof(trbuf));
220 break;
221
222 case 'y':
223 snprintf(tmp, sizeof(tmp), "%d", guiInfo.MovieHeight);
224 av_strlcat(trbuf, tmp, sizeof(trbuf));
225 break;
226
227 case 'C':
228 snprintf(tmp, sizeof(tmp), "%s", guiInfo.sh_video ? ((sh_video_t *)guiInfo.sh_video)->codec->name : "");
229 av_strlcat(trbuf, tmp, sizeof(trbuf));
230 break;
231
232 case 's':
233 if (guiInfo.Playing == 0)
234 av_strlcat(trbuf, "s", sizeof(trbuf));
235 break;
236
237 case 'l':
238 if (guiInfo.Playing == 1)
239 av_strlcat(trbuf, "p", sizeof(trbuf));
240 break;
241
242 case 'e':
243 if (guiInfo.Playing == 2)
244 av_strlcat(trbuf, "e", sizeof(trbuf));
245 break;
246
247 case 'a':
248
249 mixer = mpctx_get_mixer(guiInfo.mpcontext);
250
251 if (mixer->muted) {
252 av_strlcat(trbuf, "n", sizeof(trbuf));
253 break;
254 }
255
256 switch (guiInfo.AudioType) {
257 case 0:
258 av_strlcat(trbuf, "n", sizeof(trbuf));
259 break;
260
261 case 1:
262 av_strlcat(trbuf, "m", sizeof(trbuf));
263 break;
264
265 case 2:
266 av_strlcat(trbuf, "t", sizeof(trbuf));
267 break;
268 }
269
270 break;
271
272 case 'T':
273 switch (guiInfo.StreamType) {
274 case STREAMTYPE_FILE:
275 av_strlcat(trbuf, "f", sizeof(trbuf));
276 break;
277
278 #ifdef CONFIG_VCD
279 case STREAMTYPE_VCD:
280 av_strlcat(trbuf, "v", sizeof(trbuf));
281 break;
282 #endif
283
284 case STREAMTYPE_STREAM:
285 av_strlcat(trbuf, "u", sizeof(trbuf));
286 break;
287
288 #ifdef CONFIG_DVDREAD
289 case STREAMTYPE_DVD:
290 av_strlcat(trbuf, "d", sizeof(trbuf));
291 break;
292 #endif
293
294 default:
295 av_strlcat(trbuf, " ", sizeof(trbuf));
296 break;
297 }
298 break;
299
300 case '$':
301 av_strlcat(trbuf, "$", sizeof(trbuf));
302 break;
303
304 default:
305 continue;
306 }
307
308 c = strlen(trbuf);
309 }
310 }
311
312 return trbuf;
313 }
314
315 static void PutImage(guiImage *bf, int x, int y, int max, int ofs)
316 {
317 int i = 0, ix, iy;
318 uint32_t *buf = NULL;
319 uint32_t *drw = NULL;
320 register uint32_t tmp;
321
322 /* register uint32_t yc; */
323
324 if (!bf || (bf->Image == NULL))
325 return;
326
327 i = bf->Width * (bf->Height / max) * ofs;
328 buf = (uint32_t *)image_buffer;
329 drw = (uint32_t *)bf->Image;
330
331 #if 1
332 for (iy = y; iy < (int)(y + bf->Height / max); iy++)
333 for (ix = x; ix < (int)(x + bf->Width); ix++) {
334 tmp = drw[i++];
335
336 if (!IS_TRANSPARENT(tmp))
337 buf[iy * image_width + ix] = tmp;
338 }
339 #else
340 yc = y * image_width;
341
342 for (iy = y; iy < (int)(y + bf->Height / max); iy++) {
343 for (ix = x; ix < (int)(x + bf->Width); ix++) {
344 tmp = drw[i++];
345
346 if (!IS_TRANSPARENT(tmp))
347 buf[yc + ix] = tmp;
348 }
349
350 yc += image_width;
351 }
352 #endif
353 }
354
355 static void SimplePotmeterPutImage(guiImage *bf, int x, int y, float frac)
356 {
357 int i = 0, w, r, ix, iy;
358 uint32_t *buf = NULL;
359 uint32_t *drw = NULL;
360 register uint32_t tmp;
361
362 if (!bf || (bf->Image == NULL))
363 return;
364
365 buf = (uint32_t *)image_buffer;
366 drw = (uint32_t *)bf->Image;
367 w = bf->Width * frac;
368 r = bf->Width - w;
369
370 for (iy = y; iy < (int)(y + bf->Height); iy++) {
371 for (ix = x; ix < (int)(x + w); ix++) {
372 tmp = drw[i++];
373
374 if (!IS_TRANSPARENT(tmp))
375 buf[iy * image_width + ix] = tmp;
376 }
377
378 i += r;
379 }
380 }
381
382 void RenderAll(wsTWindow *window, wItem *Items, int nrItems, char *db)
383 {
384 wItem *item;
385 guiImage *image = NULL;
386 int i, ofs;
387
388 image_buffer = db;
389 image_width = window->Width;
390
391 for (i = 0; i < nrItems + 1; i++) {
392 item = &Items[i];
393
394 switch (item->pressed) {
395 case btnPressed:
396 ofs = 0;
397 break;
398
399 case btnReleased:
400 ofs = 1;
401 break;
402
403 default:
404 ofs = 2;
405 break;
406 }
407
408 switch (item->type) {
409 case itButton:
410 PutImage(&item->Bitmap, item->x, item->y, 3, ofs);
411 break;
412
413 case itPotmeter:
414 if (item->numphases == 1)
415 SimplePotmeterPutImage(&item->Bitmap, item->x, item->y, item->value / 100.0);
416 else
417 PutImage(&item->Bitmap, item->x, item->y, item->numphases, (item->numphases - 1) * (item->value / 100.0));
418 break;
419
420 case itHPotmeter:
421 if (item->numphases == 1)
422 SimplePotmeterPutImage(&item->Bitmap, item->x, item->y, item->value / 100.0);
423 else
424 PutImage(&item->Bitmap, item->x, item->y, item->numphases, (item->numphases - 1) * (item->value / 100.0));
425 PutImage(&item->Mask, item->x + (item->width - item->pwidth) * (item->value / 100.0), item->y, 3, ofs);
426 break;
427
428 case itVPotmeter:
429 PutImage(&item->Bitmap, item->x, item->y, item->numphases, item->numphases * (1.0 - item->value / 100.0));
430 PutImage(&item->Mask, item->x, item->y + (item->height - item->pheight) * (1.0 - item->value / 100.0), 3, ofs);
431 break;
432
433 case itSLabel:
434 if (item->width == -1)
435 item->width = fntTextWidth(item->fontid, item->label);
436 image = fntRender(item, 0, item->label);
437 if (image)
438 PutImage(image, item->x, item->y, 1, 0);
439 break;
440
441 case itDLabel:
442 {
443 int x;
444 unsigned int d;
445 char *t = Translate(item->label);
446
447 if (!item->text || (strcmp(item->text, t) != 0)) {
448 free(item->text);
449 item->text = strdup(t);
450 item->textwidth = fntTextWidth(item->fontid, t);
451 item->starttime = GetTimerMS();
452 item->last_x = 0;
453 }
454
455 d = GetTimerMS() - item->starttime;
456
457 if (d < DLABEL_DELAY)
458 x = item->last_x; // don't scroll yet
459 else {
460 int l;
461 char c[2];
462
463 l = (item->textwidth ? item->textwidth : item->width);
464 x = l - ((d - DLABEL_DELAY) / 20) % l - 1;
465 c[0] = *item->text;
466 c[1] = '\0';
467
468 if (x < (fntTextWidth(item->fontid, c) + 1) >> 1) {
469 item->starttime = GetTimerMS(); // stop again
470 item->last_x = x; // at current x pos
471 }
472 }
473
474 image = fntRender(item, x, t);
475 }
476
477 if (image)
478 PutImage(image, item->x, item->y, 1, 0);
479
480 break;
481 }
482 }
483
484 wsConvert(window, db);
485 }