Mercurial > mplayer.hg
annotate gui/win32/widgetrender.c @ 36917:0dfa0ecb10f4
Fix bug with dynamic label variables $p, $s and $e in Win32 GUI.
There is no reason to assume that there is nothing but the variable
in the label text. These variables must (like all the other ones)
be handled as a part of the label text.
author | ib |
---|---|
date | Thu, 13 Mar 2014 16:22:27 +0000 |
parents | d41fbe8a8797 |
children | e0a0b0846c4e |
rev | line source |
---|---|
23077 | 1 /* |
23079 | 2 * MPlayer GUI for Win32 |
3 * Copyright (C) 2003 Sascha Sommer <saschasommer@freenet.de> | |
4 * Copyright (C) 2006 Erik Augustson <erik_27can@yahoo.com> | |
5 * Copyright (C) 2006 Gianluigi Tiesi <sherpya@netfarm.it> | |
6 * | |
7 * This file is part of MPlayer. | |
8 * | |
9 * MPlayer is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * MPlayer is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
26457 | 19 * You should have received a copy of the GNU General Public License along |
20 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
23079 | 22 */ |
23077 | 23 |
24 #include <stdio.h> | |
25 #include <ctype.h> | |
26 #include <windows.h> | |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
27 |
33564 | 28 #include "gui/util/bitmap.h" |
34175 | 29 #include "gui/util/string.h" |
26372
76413880bfad
Update include paths to account for build system changes.
diego
parents:
23091
diff
changeset
|
30 #include "gui/interface.h" |
23077 | 31 #include "gui.h" |
32 | |
33 #define MAX_LABELSIZE 250 | |
34 | |
35 static void render(int bitsperpixel, image *dst, image *src, int x, int y, int sx, int sy, int sw, int sh, int transparent) | |
36 { | |
37 int i; | |
38 int bpp = bitsperpixel / 8; | |
39 int offset = (dst->width * bpp * y) + (x * bpp); | |
40 int soffset = (src->width * bpp * sy) + (sx * bpp); | |
41 | |
42 for(i=0; i<sh; i++) | |
43 { | |
44 int c; | |
45 for(c=0; c < (sw * bpp); c += bpp) | |
46 { | |
47 if(bpp == 2) | |
48 { | |
49 if(!transparent || (((src->data + soffset + (i * src->width * bpp) + c)[0] != 0x1f) | |
50 && ((src->data + soffset + (i * src->width * bpp) + c)[1] != 0x7c))) | |
51 memcpy(dst->data + offset + c, src->data + soffset + (i * src->width * bpp) + c, bpp); | |
52 } | |
53 else if(bpp > 2) | |
54 { | |
33534 | 55 if(!transparent || !IS_TRANSPARENT(*((unsigned int *) (src->data + soffset + (i * src->width * bpp) + c)))) |
23077 | 56 memcpy(dst->data + offset + c, src->data + soffset + (i * src->width * bpp) + c, bpp); |
57 } | |
58 } | |
59 offset += (dst->width * bpp); | |
60 } | |
61 } | |
62 | |
63 static image *find_background(skin_t *skin, widget *item) | |
64 { | |
65 unsigned int i; | |
66 for (i=0; i < skin->windowcount; i++) | |
67 if(skin->windows[i]->type == item->window) | |
68 return skin->windows[i]->base->bitmap[0]; | |
69 return NULL; | |
70 } | |
71 | |
72 /******************************************************************/ | |
73 /* FONT related functions */ | |
74 /******************************************************************/ | |
75 | |
76 /* returns the pos of s2 inside s1 or -1 if s1 doesn't contain s2 */ | |
77 static int strpos(char *s1, const char* s2) | |
78 { | |
79 unsigned int i, x; | |
80 for (i=0; i < strlen(s1); i++) | |
81 { | |
82 if(s1[i] == s2[0]) | |
83 { | |
84 if(strlen(s1 + i) >= strlen(s2)) | |
85 { | |
86 for (x=0; x <strlen(s2); x++) | |
87 if(s1[i + x] != s2[x]) break; | |
88 if(x == strlen(s2)) return i; | |
89 } | |
90 } | |
91 } | |
92 return -1; | |
93 } | |
94 | |
95 /* replaces all occurences of what in dest with format */ | |
96 static void stringreplace(char *dest, const char *what, const char *format, ... ) | |
97 { | |
98 char tmp[MAX_LABELSIZE]; | |
99 int offset=0; | |
100 va_list va; | |
101 va_start(va, format); | |
102 vsnprintf(tmp, MAX_LABELSIZE, format, va); | |
103 va_end(va); | |
104 /* no search string == replace the entire string */ | |
105 if(!what) | |
106 { | |
107 memcpy(dest, tmp, strlen(tmp)); | |
108 dest[strlen(tmp)] = 0; | |
109 return; | |
110 } | |
111 while((offset = strpos(dest, what)) != -1) | |
112 { | |
113 memmove(dest + offset + strlen(tmp), dest + offset + strlen(what), strlen(dest + offset + strlen(what)) + 1); | |
114 memcpy(dest + offset, tmp, strlen(tmp)); | |
115 } | |
116 } | |
117 | |
118 /* replaces the chars with special meaning with the associated data from the player info struct */ | |
119 static char *generatetextfromlabel(widget *item) | |
120 { | |
121 char *text = malloc(MAX_LABELSIZE); | |
122 char tmp[MAX_LABELSIZE]; | |
123 if(!item) | |
124 { | |
125 free(text); | |
126 return NULL; | |
127 } | |
128 strcpy(text, item->label); | |
129 if(item->type == tySlabel) return text; | |
33897 | 130 stringreplace(text, "$1", "%.2i:%.2i:%.2i", guiInfo.ElapsedTime / 3600, |
131 (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60); | |
132 stringreplace(text, "$2", "%.4i:%.2i", guiInfo.ElapsedTime / 60, guiInfo.ElapsedTime % 60); | |
133 stringreplace(text, "$3", "%.2i", guiInfo.ElapsedTime / 3600); | |
134 stringreplace(text, "$4", "%.2i", (guiInfo.ElapsedTime / 60) % 60); | |
135 stringreplace(text, "$5", "%.2i", guiInfo.ElapsedTime % 60); | |
136 stringreplace(text, "$6", "%.2i:%.2i:%.2i", guiInfo.RunningTime / 3600, | |
137 (guiInfo.RunningTime / 60) % 60, guiInfo.RunningTime % 60); | |
138 stringreplace(text, "$7", "%.4i:%.2i", guiInfo.RunningTime / 60, guiInfo.RunningTime % 60); | |
139 stringreplace(text, "$8", "%i:%.2i:%.2i", guiInfo.ElapsedTime / 3600, | |
140 (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60); | |
36904
7c5b6a58fac6
Fix dynamic label variables $v and $b in the Win32 GUI.
ib
parents:
36899
diff
changeset
|
141 stringreplace(text, "$v", "%3.2f%%", guiInfo.Volume); |
33555 | 142 stringreplace(text, "$V", "%3.1f", guiInfo.Volume); |
36916 | 143 stringreplace(text, "$U", "%3.0f", guiInfo.Volume); |
36904
7c5b6a58fac6
Fix dynamic label variables $v and $b in the Win32 GUI.
ib
parents:
36899
diff
changeset
|
144 stringreplace(text, "$b", "%3.2f%%", guiInfo.Balance); |
33555 | 145 stringreplace(text, "$B", "%3.1f", guiInfo.Balance); |
36914 | 146 stringreplace(text, "$D", "%3.0f", guiInfo.Balance); |
33555 | 147 stringreplace(text, "$t", "%.2i", guiInfo.Track); |
34163 | 148 stringreplace(text, "$o", "%s", acp(TranslateFilename(0, tmp, sizeof(tmp)))); |
33901 | 149 stringreplace(text, "$x", "%i", guiInfo.VideoWidth); |
150 stringreplace(text, "$y", "%i", guiInfo.VideoHeight); | |
33555 | 151 stringreplace(text, "$C", "%s", guiInfo.sh_video ? codecname : ""); |
23077 | 152 stringreplace(text, "$$", "$"); |
153 | |
36917
0dfa0ecb10f4
Fix bug with dynamic label variables $p, $s and $e in Win32 GUI.
ib
parents:
36916
diff
changeset
|
154 if(guiInfo.Playing == GUI_STOP) stringreplace(text, "$s", "s"); |
0dfa0ecb10f4
Fix bug with dynamic label variables $p, $s and $e in Win32 GUI.
ib
parents:
36916
diff
changeset
|
155 else if(guiInfo.Playing == GUI_PLAY) stringreplace(text, "$p", "p"); |
0dfa0ecb10f4
Fix bug with dynamic label variables $p, $s and $e in Win32 GUI.
ib
parents:
36916
diff
changeset
|
156 else if(guiInfo.Playing == GUI_PAUSE) stringreplace(text, "$e", "e"); |
23077 | 157 |
33646 | 158 if(guiInfo.AudioChannels == 0) stringreplace(text, "$a", "n"); |
159 else if(guiInfo.AudioChannels == 1) stringreplace(text, "$a", "m"); | |
36910
11932adad7a2
Add symbol character 'r' for dynamic label variable $a.
ib
parents:
36904
diff
changeset
|
160 else if(guiInfo.AudioChannels == 2) stringreplace(text, "$a", "t"); |
11932adad7a2
Add symbol character 'r' for dynamic label variable $a.
ib
parents:
36904
diff
changeset
|
161 else stringreplace(text, "$a", "r"); |
23077 | 162 |
36912
c20f0c6d19f1
Fix symbol character for dynamic label variable $T in Win32 GUI.
ib
parents:
36910
diff
changeset
|
163 if(guiInfo.StreamType == STREAMTYPE_FILE) |
23077 | 164 stringreplace(text, "$T", "f"); |
33555 | 165 else if(guiInfo.StreamType == STREAMTYPE_DVD || guiInfo.StreamType == STREAMTYPE_DVDNAV) |
23077 | 166 stringreplace(text, "$T", "d"); |
36912
c20f0c6d19f1
Fix symbol character for dynamic label variable $T in Win32 GUI.
ib
parents:
36910
diff
changeset
|
167 else if(guiInfo.StreamType == STREAMTYPE_STREAM) |
c20f0c6d19f1
Fix symbol character for dynamic label variable $T in Win32 GUI.
ib
parents:
36910
diff
changeset
|
168 stringreplace(text, "$T", "u"); |
c20f0c6d19f1
Fix symbol character for dynamic label variable $T in Win32 GUI.
ib
parents:
36910
diff
changeset
|
169 else stringreplace(text, "$T", " "); |
23077 | 170 |
34163 | 171 stringreplace(text, "$f", acp(TranslateFilename(1, tmp, sizeof(tmp)))); |
172 stringreplace(text, "$F", acp(TranslateFilename(2, tmp, sizeof(tmp)))); | |
23077 | 173 |
174 return text; | |
175 } | |
176 | |
177 /* cuts text to buflen scrolling from right to left */ | |
178 static void scrolltext(char *text, unsigned int buflen, float *value) | |
179 { | |
30702 | 180 char *buffer = malloc(buflen + 1); |
23077 | 181 unsigned int x,i; |
182 if(*value < buflen) x = 0; | |
183 else x = *value - buflen; | |
184 memset(buffer, ' ', buflen); | |
185 for (i = (*value>=buflen) ? 0 : buflen - *value; i<buflen; i++) | |
186 { | |
187 if(x < strlen(text)) | |
188 buffer[i] = text[x]; | |
189 x++; | |
190 } | |
191 buffer[buflen] = 0; | |
192 *value += 1.0f; | |
193 if(*value >= strlen(text) + buflen) *value = 0.0f; | |
194 strcpy(text, buffer); | |
195 free(buffer); | |
196 } | |
197 | |
198 /* updates all dlabels and slabels */ | |
199 void renderinfobox(skin_t *skin, window_priv_t *priv) | |
200 { | |
201 unsigned int i; | |
202 if (!priv) return; | |
203 | |
204 /* repaint the area behind the text*/ | |
205 /* we have to do this for all labels here, because they may overlap in buggy skins ;( */ | |
206 | |
207 for (i=0; i<skin->widgetcount; i++) | |
208 if((skin->widgets[i]->type == tyDlabel) || (skin->widgets[i]->type == tySlabel)) | |
209 { | |
210 if(skin->widgets[i]->window == priv->type) | |
211 render(skin->desktopbpp, | |
212 &priv->img, | |
213 find_background(skin, skin->widgets[i]), | |
214 skin->widgets[i]->x, | |
215 skin->widgets[i]->y, | |
216 skin->widgets[i]->x, | |
217 skin->widgets[i]->y, | |
218 skin->widgets[i]->length, | |
219 skin->widgets[i]->font->chars[0]->height, | |
220 1); | |
221 } | |
222 | |
223 /* load all slabels and dlabels */ | |
224 for (i=0; i<skin->widgetcount; i++) | |
225 { | |
226 widget *item = skin->widgets[i]; | |
227 if(item->window != priv->type) continue; | |
228 if((i == skin->widgetcount) || (item->type == tyDlabel) || (item->type == tySlabel)) | |
229 { | |
230 char *text = generatetextfromlabel(item); | |
231 unsigned int current, c; | |
232 int offset = 0; | |
233 unsigned int textlen; | |
234 if(!text) continue; | |
235 textlen = strlen(text); | |
236 | |
237 /* render(win, win->background, gui->skin->widgets[i]->x, gui->skin->widgets[i]->y, | |
238 gui->skin->widgets[i]->x, gui->skin->widgets[i]->y, | |
239 gui->skin->widgets[i]->length, gui->skin->widgets[i]->font->chars[0]->height,1); */ | |
240 | |
241 /* calculate text size */ | |
242 for (current=0; current<textlen; current++) | |
243 { | |
244 for (c=0; c<item->font->charcount; c++) | |
245 if(item->font->chars[c]->c == text[current]) | |
246 { | |
247 offset += item->font->chars[c]->width; | |
248 break; | |
249 } | |
250 } | |
251 | |
252 /* labels can be scrolled if they are to big */ | |
253 if((item->type == tyDlabel) && (item->length < offset)) | |
254 { | |
255 int tomuch = (offset - item->length) / (offset /textlen); | |
256 scrolltext(text, textlen - tomuch - 1, &skin->widgets[i]->value); | |
257 textlen = strlen(text); | |
258 } | |
259 | |
260 /* align the text */ | |
261 if(item->align == 1) | |
262 offset = (item->length-offset) / 2; | |
263 else if(item->align == 2) | |
264 offset = item->length-offset; | |
265 else | |
266 offset = 0; | |
267 | |
268 if(offset < 0) offset = 0; | |
269 | |
270 /* render the text */ | |
271 for (current=0; current<textlen; current++) | |
272 { | |
273 for (c=0; c<item->font->charcount; c++) | |
274 { | |
275 char_t *cchar = item->font->chars[c]; | |
276 if(cchar->c == *(text + current)) | |
277 { | |
278 render(skin->desktopbpp, | |
279 &priv->img, | |
280 item->font->image, | |
281 item->x + offset, | |
282 item->y, | |
283 cchar->x, | |
284 cchar->y, | |
285 (cchar->width + offset > item->length) ? item->length - offset : cchar->width, | |
286 cchar->height, | |
287 1); | |
288 offset += cchar->width; | |
289 break; | |
290 } | |
291 } | |
292 } | |
293 free(text); | |
294 } | |
295 } | |
296 } | |
297 | |
298 /******************************************************************/ | |
299 /* WIDGET related functions */ | |
300 /******************************************************************/ | |
301 | |
302 void renderwidget(skin_t *skin, image *dest, widget *item, int state) | |
303 { | |
304 image *img = NULL; | |
305 int height; | |
306 int y; | |
307 | |
308 if(!dest) return; | |
36898 | 309 if((item->type == tyButton) || (item->type == tyHpotmeter) || (item->type == tyVpotmeter) || (item->type == tyPotmeter)) |
23077 | 310 img = item->bitmap[0]; |
311 | |
312 if(!img) return; | |
313 | |
314 y = item->y; | |
36892 | 315 if(/* item->type == tyPotmeter */ /* legacy (potmeter) */ item->type == tyHpotmeter && item->width == item->wwidth) |
23077 | 316 { |
317 height = img->height / item->phases; | |
318 y = height * (int)(item->value * item->phases / 100); | |
319 if(y > img->height-height) | |
320 y = img->height - height; | |
321 } | |
322 else | |
323 { | |
324 height = img->height / 3; | |
325 y = state * height; | |
326 } | |
327 | |
328 /* redraw background */ | |
329 if(item->type == tyButton) | |
330 render(skin->desktopbpp, dest, find_background(skin,item), item->x, item->y, item->x, item->y, img->width, height, 1); | |
331 | |
36898 | 332 if((item->type == tyHpotmeter) || (item->type == tyVpotmeter) || (item->type == tyPotmeter)) |
23077 | 333 { |
36898 | 334 if(item->type == tyVpotmeter) |
335 { | |
336 /* repaint the area behind the slider */ | |
337 render(skin->desktopbpp, dest, find_background(skin, item), item->wx, item->wy, item->wx, item->wy, item->width, item->wheight, 1); | |
338 item->y = (100 - item->value) * (item->wheight-item->height) / 100 + item->wy; | |
339 if((item->y + item->height) > (item->wy + item->wheight)) | |
340 item->y = item->wy + item->wheight - item->height; | |
341 if(item->y < item->wy) | |
342 item->y = item->wy; | |
343 } | |
344 else | |
345 { | |
36899 | 346 /* repaint the area behind the slider */ |
347 render(skin->desktopbpp, dest, find_background(skin, item), item->wx, item->wy, item->wx, item->wy, item->wwidth, item->height, 1); | |
348 item->x = item->value * (item->wwidth-item->width) / 100 + item->wx; | |
349 if((item->x + item->width) > (item->wx + item->wwidth)) | |
350 item->x = item->wx + item->wwidth - item->width; | |
351 if(item->x < item->wx) | |
352 item->x = item->wx; | |
36898 | 353 } |
23077 | 354 } |
355 render(skin->desktopbpp, dest, img, item->x, item->y, 0, y, img->width, height, 1); | |
356 } |