Mercurial > mplayer.hg
annotate gui/ui/render.c @ 36914:1db578946152
Add new dynamic label variable $D.
This is the balance without decimal places (which makes more sense to me
than $B and should have been the output of $B in the first place).
author | ib |
---|---|
date | Thu, 13 Mar 2014 15:41:22 +0000 |
parents | 11932adad7a2 |
children | d41fbe8a8797 |
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 "libavutil/avstring.h" |
32954 | 30 #include "osdep/timer.h" |
32963 | 31 #include "stream/stream.h" |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
32 |
33269 | 33 #define DLABEL_DELAY 2500 // in milliseconds |
34 | |
32963 | 35 static char *image_buffer; |
36 static int image_width; | |
32956 | 37 |
32975
0dc9d64cd64e
Make functions static that are only used inside the file.
ib
parents:
32973
diff
changeset
|
38 static char *Translate(char *str) |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
39 { |
32963 | 40 static char trbuf[512]; |
41 char tmp[512]; | |
32972 | 42 unsigned int i, c; |
32963 | 43 int t; |
44 | |
32972 | 45 *trbuf = 0; |
32963 | 46 |
32972 | 47 for (c = 0, i = 0; i < strlen(str); i++) { |
32963 | 48 if (str[i] != '$') { |
32972 | 49 if (c + 1 < sizeof(trbuf)) { |
32973 | 50 trbuf[c++] = str[i]; |
51 trbuf[c] = 0; | |
32972 | 52 } |
32963 | 53 } else { |
54 switch (str[++i]) { | |
55 case 't': | |
33555 | 56 snprintf(tmp, sizeof(tmp), "%02d", guiInfo.Track); |
32963 | 57 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
58 break; | |
59 | |
60 case 'o': | |
61 TranslateFilename(0, tmp, sizeof(tmp)); | |
62 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
63 break; | |
64 | |
65 case 'f': | |
66 TranslateFilename(1, tmp, sizeof(tmp)); | |
67 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
68 break; | |
69 | |
70 case 'F': | |
71 TranslateFilename(2, tmp, sizeof(tmp)); | |
72 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
73 break; | |
74 | |
75 case '6': | |
33897 | 76 t = guiInfo.RunningTime; |
32963 | 77 goto calclengthhhmmss; |
78 | |
79 case '1': | |
33897 | 80 t = guiInfo.ElapsedTime; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
81 calclengthhhmmss: |
32963 | 82 snprintf(tmp, sizeof(tmp), "%02d:%02d:%02d", t / 3600, t / 60 % 60, t % 60); |
83 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
84 break; | |
85 | |
86 case '7': | |
33897 | 87 t = guiInfo.RunningTime; |
32963 | 88 goto calclengthmmmmss; |
89 | |
90 case '2': | |
33897 | 91 t = guiInfo.ElapsedTime; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
92 calclengthmmmmss: |
32963 | 93 snprintf(tmp, sizeof(tmp), "%04d:%02d", t / 60, t % 60); |
94 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
95 break; | |
96 | |
97 case '3': | |
33897 | 98 snprintf(tmp, sizeof(tmp), "%02d", guiInfo.ElapsedTime / 3600); |
32963 | 99 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
100 break; | |
101 | |
102 case '4': | |
33897 | 103 snprintf(tmp, sizeof(tmp), "%02d", (guiInfo.ElapsedTime / 60) % 60); |
32963 | 104 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
105 break; | |
106 | |
107 case '5': | |
33897 | 108 snprintf(tmp, sizeof(tmp), "%02d", guiInfo.ElapsedTime % 60); |
32963 | 109 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
110 break; | |
111 | |
112 case '8': | |
33897 | 113 snprintf(tmp, sizeof(tmp), "%01d:%02d:%02d", guiInfo.ElapsedTime / 3600, (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60); |
32963 | 114 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
115 break; | |
116 | |
117 case 'v': | |
33555 | 118 snprintf(tmp, sizeof(tmp), "%3.2f%%", guiInfo.Volume); |
32963 | 119 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
120 break; | |
121 | |
122 case 'V': | |
33555 | 123 snprintf(tmp, sizeof(tmp), "%3.1f", guiInfo.Volume); |
32963 | 124 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
125 break; | |
126 | |
127 case 'b': | |
33555 | 128 snprintf(tmp, sizeof(tmp), "%3.2f%%", guiInfo.Balance); |
32963 | 129 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
130 break; | |
131 | |
132 case 'B': | |
33555 | 133 snprintf(tmp, sizeof(tmp), "%3.1f", guiInfo.Balance); |
32963 | 134 av_strlcat(trbuf, tmp, sizeof(trbuf)); |
135 break; | |
136 | |
36914 | 137 case 'D': |
138 snprintf(tmp, sizeof(tmp), "%3.0f", guiInfo.Balance); | |
139 av_strlcat(trbuf, tmp, sizeof(trbuf)); | |
140 break; | |
141 | |
32963 | 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': | |
35462 | 153 snprintf(tmp, sizeof(tmp), "%s", guiInfo.CodecName ? guiInfo.CodecName : ""); |
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': | |
33646 | 174 switch (guiInfo.AudioChannels) { |
32963 | 175 case 0: |
176 av_strlcat(trbuf, "n", sizeof(trbuf)); | |
177 break; | |
178 | |
179 case 1: | |
180 av_strlcat(trbuf, "m", sizeof(trbuf)); | |
181 break; | |
182 | |
183 case 2: | |
184 av_strlcat(trbuf, "t", sizeof(trbuf)); | |
185 break; | |
36910
11932adad7a2
Add symbol character 'r' for dynamic label variable $a.
ib
parents:
36909
diff
changeset
|
186 |
11932adad7a2
Add symbol character 'r' for dynamic label variable $a.
ib
parents:
36909
diff
changeset
|
187 default: |
11932adad7a2
Add symbol character 'r' for dynamic label variable $a.
ib
parents:
36909
diff
changeset
|
188 av_strlcat(trbuf, "r", sizeof(trbuf)); |
11932adad7a2
Add symbol character 'r' for dynamic label variable $a.
ib
parents:
36909
diff
changeset
|
189 break; |
32963 | 190 } |
191 break; | |
192 | |
193 case 'T': | |
33555 | 194 switch (guiInfo.StreamType) { |
32963 | 195 case STREAMTYPE_FILE: |
196 av_strlcat(trbuf, "f", sizeof(trbuf)); | |
197 break; | |
198 | |
34077 | 199 case STREAMTYPE_STREAM: |
200 av_strlcat(trbuf, "u", sizeof(trbuf)); | |
201 break; | |
202 | |
34387 | 203 case STREAMTYPE_CDDA: |
204 av_strlcat(trbuf, "a", sizeof(trbuf)); | |
205 break; | |
206 | |
32963 | 207 case STREAMTYPE_VCD: |
208 av_strlcat(trbuf, "v", sizeof(trbuf)); | |
209 break; | |
210 | |
211 case STREAMTYPE_DVD: | |
212 av_strlcat(trbuf, "d", sizeof(trbuf)); | |
213 break; | |
214 | |
36429 | 215 case STREAMTYPE_TV: |
216 case STREAMTYPE_DVB: | |
217 av_strlcat(trbuf, "b", sizeof(trbuf)); | |
218 break; | |
219 | |
32963 | 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 |
35688 | 308 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
|
309 { |
35688 | 310 guiItem *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: | |
35541 | 336 |
32963 | 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: |
35541 | 341 |
32963 | 342 if (item->numphases == 1) |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
343 SimplePotmeterPutImage(&item->Bitmap, item->x, item->y, item->value / 100.0); |
32963 | 344 else |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
345 PutImage(&item->Bitmap, item->x, item->y, item->numphases, (item->numphases - 1) * (item->value / 100.0)); |
35541 | 346 |
32963 | 347 break; |
348 | |
349 case itHPotmeter: | |
35541 | 350 |
32963 | 351 if (item->numphases == 1) |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
352 SimplePotmeterPutImage(&item->Bitmap, item->x, item->y, item->value / 100.0); |
32963 | 353 else |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
354 PutImage(&item->Bitmap, item->x, item->y, item->numphases, (item->numphases - 1) * (item->value / 100.0)); |
35541 | 355 |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
356 PutImage(&item->Mask, item->x + (item->width - item->pwidth) * (item->value / 100.0), item->y, 3, ofs); |
32963 | 357 break; |
358 | |
359 case itVPotmeter: | |
35541 | 360 |
32970
3673c28ce811
Use double constants for higher precision calculations.
ib
parents:
32969
diff
changeset
|
361 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
|
362 PutImage(&item->Mask, item->x, item->y + (item->height - item->pheight) * (1.0 - item->value / 100.0), 3, ofs); |
32963 | 363 break; |
364 | |
365 case itSLabel: | |
35541 | 366 |
32969 | 367 if (item->width == -1) |
368 item->width = fntTextWidth(item->fontid, item->label); | |
35541 | 369 |
33971 | 370 image = fntTextRender(item, 0, item->label); |
35541 | 371 |
32963 | 372 if (image) |
373 PutImage(image, item->x, item->y, 1, 0); | |
35541 | 374 |
32969 | 375 break; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
376 |
32963 | 377 case itDLabel: |
378 { | |
379 int x; | |
380 unsigned int d; | |
381 char *t = Translate(item->label); | |
382 | |
383 if (!item->text || (strcmp(item->text, t) != 0)) { | |
384 free(item->text); | |
385 item->text = strdup(t); | |
386 item->textwidth = fntTextWidth(item->fontid, t); | |
387 item->starttime = GetTimerMS(); | |
388 item->last_x = 0; | |
32761
3ceeb62a1125
Improve the readability of dynamic labels which scroll.
ib
parents:
32759
diff
changeset
|
389 } |
32963 | 390 |
391 d = GetTimerMS() - item->starttime; | |
392 | |
32964 | 393 if (d < DLABEL_DELAY) |
32963 | 394 x = item->last_x; // don't scroll yet |
395 else { | |
396 int l; | |
397 char c[2]; | |
398 | |
399 l = (item->textwidth ? item->textwidth : item->width); | |
35362 | 400 x = (l ? l - ((d - DLABEL_DELAY) / 20) % l - 1 : 0); |
32963 | 401 c[0] = *item->text; |
402 c[1] = '\0'; | |
403 | |
404 if (x < (fntTextWidth(item->fontid, c) + 1) >> 1) { | |
405 item->starttime = GetTimerMS(); // stop again | |
406 item->last_x = x; // at current x pos | |
407 } | |
32761
3ceeb62a1125
Improve the readability of dynamic labels which scroll.
ib
parents:
32759
diff
changeset
|
408 } |
32963 | 409 |
33971 | 410 image = fntTextRender(item, x, t); |
32963 | 411 } |
412 | |
413 if (image) | |
414 PutImage(image, item->x, item->y, 1, 0); | |
415 | |
416 break; | |
417 } | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
418 } |
32963 | 419 |
35744 | 420 wsImageRender(window, db); |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
421 } |