Mercurial > mplayer.hg
comparison Gui/win32/widgetrender.c @ 18914:d450ec82ae57
Initial win32 gui release.
author | vayne |
---|---|
date | Thu, 06 Jul 2006 02:07:03 +0000 |
parents | |
children | e701a6eed5cb |
comparison
equal
deleted
inserted
replaced
18913:2dc84d07332c | 18914:d450ec82ae57 |
---|---|
1 /* | |
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 program is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation; either version 2 of the License, or | |
10 (at your option) any later version. | |
11 | |
12 This program is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with this program; if not, write to the Free Software | |
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA | |
20 */ | |
21 | |
22 #include <stdio.h> | |
23 #include <ctype.h> | |
24 #include <windows.h> | |
25 #include <interface.h> | |
26 #include "gui.h" | |
27 | |
28 extern char *codecname; | |
29 #define MAX_LABELSIZE 250 | |
30 | |
31 static void render(int bitsperpixel, image *dst, image *src, int x, int y, int sx, int sy, int sw, int sh, int transparent) | |
32 { | |
33 int i; | |
34 int bpp = bitsperpixel / 8; | |
35 int offset = (dst->width * bpp * y) + (x * bpp); | |
36 int soffset = (src->width * bpp * sy) + (sx * bpp); | |
37 | |
38 for(i=0; i<sh; i++) | |
39 { | |
40 int c; | |
41 for(c=0; c < (sw * bpp); c += bpp) | |
42 { | |
43 if(bpp == 2) | |
44 { | |
45 if(!transparent || (((src->data + soffset + (i * src->width * bpp) + c)[0] != 0x1f) | |
46 && ((src->data + soffset + (i * src->width * bpp) + c)[1] != 0x7c))) | |
47 memcpy(dst->data + offset + c, src->data + soffset + (i * src->width * bpp) + c, bpp); | |
48 } | |
49 else if(bpp > 2) | |
50 { | |
51 if(!transparent || *((unsigned int *) (src->data + soffset + (i * src->width * bpp) + c)) != 0x00ff00ff) | |
52 memcpy(dst->data + offset + c, src->data + soffset + (i * src->width * bpp) + c, bpp); | |
53 } | |
54 } | |
55 offset += (dst->width * bpp); | |
56 } | |
57 } | |
58 | |
59 static image *find_background(skin_t *skin, widget *item) | |
60 { | |
61 unsigned int i; | |
62 for (i=0; i < skin->windowcount; i++) | |
63 if(skin->windows[i]->type == item->window) | |
64 return skin->windows[i]->base->bitmap[0]; | |
65 return NULL; | |
66 } | |
67 | |
68 /******************************************************************/ | |
69 /* FONT related functions */ | |
70 /******************************************************************/ | |
71 | |
72 /* returns the pos of s2 inside s1 or -1 if s1 doesn't contain s2 */ | |
73 static int strpos(char *s1, const char* s2) | |
74 { | |
75 unsigned int i, x; | |
76 for (i=0; i < strlen(s1); i++) | |
77 { | |
78 if(s1[i] == s2[0]) | |
79 { | |
80 if(strlen(s1 + i) >= strlen(s2)) | |
81 { | |
82 for (x=0; x <strlen(s2); x++) | |
83 if(s1[i + x] != s2[x]) break; | |
84 if(x == strlen(s2)) return i; | |
85 } | |
86 } | |
87 } | |
88 return -1; | |
89 } | |
90 | |
91 /* replaces all occurences of what in dest with format */ | |
92 static void stringreplace(char *dest, const char *what, const char *format, ... ) | |
93 { | |
94 char tmp[MAX_LABELSIZE]; | |
95 int offset=0; | |
96 va_list va; | |
97 va_start(va, format); | |
98 vsnprintf(tmp, MAX_LABELSIZE, format, va); | |
99 va_end(va); | |
100 /* no search string == replace the entire string */ | |
101 if(!what) | |
102 { | |
103 memcpy(dest, tmp, strlen(tmp)); | |
104 dest[strlen(tmp)] = 0; | |
105 return; | |
106 } | |
107 while((offset = strpos(dest, what)) != -1) | |
108 { | |
109 memmove(dest + offset + strlen(tmp), dest + offset + strlen(what), strlen(dest + offset + strlen(what)) + 1); | |
110 memcpy(dest + offset, tmp, strlen(tmp)); | |
111 } | |
112 } | |
113 | |
114 /* replaces the chars with special meaning with the associated data from the player info struct */ | |
115 static char *generatetextfromlabel(widget *item) | |
116 { | |
117 char *text = malloc(MAX_LABELSIZE); | |
118 char tmp[MAX_LABELSIZE]; | |
119 unsigned int i; | |
120 if(!item) | |
121 { | |
122 free(text); | |
123 return NULL; | |
124 } | |
125 strcpy(text, item->label); | |
126 if(item->type == tySlabel) return text; | |
127 stringreplace(text, "$1", "%.2i:%.2i:%.2i", guiIntfStruct.TimeSec / 3600, | |
128 (guiIntfStruct.TimeSec / 60) % 60, guiIntfStruct.TimeSec % 60); | |
129 stringreplace(text, "$2", "%.4i:%.2i", guiIntfStruct.TimeSec / 60, guiIntfStruct.TimeSec % 60); | |
130 stringreplace(text, "$3", "%.2i", guiIntfStruct.TimeSec / 3600); | |
131 stringreplace(text, "$4", "%.2i", (guiIntfStruct.TimeSec / 60) % 60); | |
132 stringreplace(text, "$5", "%.2i", guiIntfStruct.TimeSec % 60); | |
133 stringreplace(text, "$6", "%.2i:%.2i:%.2i", guiIntfStruct.LengthInSec / 3600, | |
134 (guiIntfStruct.LengthInSec / 60) % 60, guiIntfStruct.LengthInSec % 60); | |
135 stringreplace(text, "$7", "%.4i:%.2i", guiIntfStruct.LengthInSec / 60, guiIntfStruct.LengthInSec % 60); | |
136 stringreplace(text, "$8", "%i:%.2i:%.2i", guiIntfStruct.TimeSec / 3600, | |
137 (guiIntfStruct.TimeSec / 60) % 60, guiIntfStruct.TimeSec % 60); | |
138 stringreplace(text, "$v", "%3.2f", guiIntfStruct.Volume); | |
139 stringreplace(text, "$V", "%3.1f", guiIntfStruct.Volume); | |
140 stringreplace(text, "$b", "%3.2f", guiIntfStruct.Balance); | |
141 stringreplace(text, "$B", "%3.1f", guiIntfStruct.Balance); | |
142 stringreplace(text, "$t", "%.2i", guiIntfStruct.Track); | |
143 stringreplace(text, "$o", "%s", guiIntfStruct.Filename); | |
144 stringreplace(text, "$x", "%i", guiIntfStruct.MovieWidth); | |
145 stringreplace(text, "$y", "%i", guiIntfStruct.MovieHeight); | |
146 stringreplace(text, "$C", "%s", guiIntfStruct.sh_video ? codecname : ""); | |
147 stringreplace(text, "$$", "$"); | |
148 | |
149 if(!strcmp(text, "$p") || !strcmp(text, "$s") || !strcmp(text, "$e")) | |
150 { | |
151 if(guiIntfStruct.Playing == 0) stringreplace(text, NULL, "s"); | |
152 else if(guiIntfStruct.Playing == 1) stringreplace(text, NULL, "p"); | |
153 else if(guiIntfStruct.Playing == 2) stringreplace(text, NULL, "e"); | |
154 } | |
155 | |
156 if(guiIntfStruct.AudioType == 0) stringreplace(text, "$a", "n"); | |
157 else if(guiIntfStruct.AudioType == 1) stringreplace(text, "$a", "m"); | |
158 else stringreplace(text, "$a", "t"); | |
159 | |
160 if(guiIntfStruct.StreamType == 0) | |
161 stringreplace(text, "$T", "f"); | |
162 #ifdef USE_DVDREAD | |
163 else if(guiIntfStruct.StreamType == STREAMTYPE_DVD || guiIntfStruct.StreamType == STREAMTYPE_DVDNAV) | |
164 stringreplace(text, "$T", "d"); | |
165 #endif | |
166 else stringreplace(text, "$T", "u"); | |
167 | |
168 if(guiIntfStruct.Filename) | |
169 { | |
170 for (i=0; i<strlen(guiIntfStruct.Filename); i++) | |
171 tmp[i] = tolower(guiIntfStruct.Filename[i]); | |
172 stringreplace(text, "$f", tmp); | |
173 | |
174 for (i=0; i<strlen(guiIntfStruct.Filename); i++) | |
175 tmp[i] = toupper(guiIntfStruct.Filename[i]); | |
176 stringreplace(text, "$F", tmp); | |
177 } | |
178 | |
179 return text; | |
180 } | |
181 | |
182 /* cuts text to buflen scrolling from right to left */ | |
183 static void scrolltext(char *text, unsigned int buflen, float *value) | |
184 { | |
185 char *buffer = (char *) malloc(buflen + 1); | |
186 unsigned int x,i; | |
187 if(*value < buflen) x = 0; | |
188 else x = *value - buflen; | |
189 memset(buffer, ' ', buflen); | |
190 for (i = (*value>=buflen) ? 0 : buflen - *value; i<buflen; i++) | |
191 { | |
192 if(x < strlen(text)) | |
193 buffer[i] = text[x]; | |
194 x++; | |
195 } | |
196 buffer[buflen] = 0; | |
197 *value += 1.0f; | |
198 if(*value >= strlen(text) + buflen) *value = 0.0f; | |
199 strcpy(text, buffer); | |
200 free(buffer); | |
201 } | |
202 | |
203 /* updates all dlabels and slabels */ | |
204 void renderinfobox(skin_t *skin, window_priv_t *priv) | |
205 { | |
206 unsigned int i; | |
207 if (!priv) return; | |
208 | |
209 /* repaint the area behind the text*/ | |
210 /* we have to do this for all labels here, because they may overlap in buggy skins ;( */ | |
211 | |
212 for (i=0; i<skin->widgetcount; i++) | |
213 if((skin->widgets[i]->type == tyDlabel) || (skin->widgets[i]->type == tySlabel)) | |
214 { | |
215 if(skin->widgets[i]->window == priv->type) | |
216 render(skin->desktopbpp, | |
217 &priv->img, | |
218 find_background(skin, skin->widgets[i]), | |
219 skin->widgets[i]->x, | |
220 skin->widgets[i]->y, | |
221 skin->widgets[i]->x, | |
222 skin->widgets[i]->y, | |
223 skin->widgets[i]->length, | |
224 skin->widgets[i]->font->chars[0]->height, | |
225 1); | |
226 } | |
227 | |
228 /* load all slabels and dlabels */ | |
229 for (i=0; i<skin->widgetcount; i++) | |
230 { | |
231 widget *item = skin->widgets[i]; | |
232 if(item->window != priv->type) continue; | |
233 if((i == skin->widgetcount) || (item->type == tyDlabel) || (item->type == tySlabel)) | |
234 { | |
235 char *text = generatetextfromlabel(item); | |
236 unsigned int current, c; | |
237 int offset = 0; | |
238 unsigned int textlen; | |
239 if(!text) continue; | |
240 textlen = strlen(text); | |
241 | |
242 /* render(win, win->background, gui->skin->widgets[i]->x, gui->skin->widgets[i]->y, | |
243 gui->skin->widgets[i]->x, gui->skin->widgets[i]->y, | |
244 gui->skin->widgets[i]->length, gui->skin->widgets[i]->font->chars[0]->height,1); */ | |
245 | |
246 /* calculate text size */ | |
247 for (current=0; current<textlen; current++) | |
248 { | |
249 for (c=0; c<item->font->charcount; c++) | |
250 if(item->font->chars[c]->c == text[current]) | |
251 { | |
252 offset += item->font->chars[c]->width; | |
253 break; | |
254 } | |
255 } | |
256 | |
257 /* labels can be scrolled if they are to big */ | |
258 if((item->type == tyDlabel) && (item->length < offset)) | |
259 { | |
260 int tomuch = (offset - item->length) / (offset /textlen); | |
261 scrolltext(text, textlen - tomuch - 1, &skin->widgets[i]->value); | |
262 textlen = strlen(text); | |
263 } | |
264 | |
265 /* align the text */ | |
266 if(item->align == 1) | |
267 offset = (item->length-offset) / 2; | |
268 else if(item->align == 2) | |
269 offset = item->length-offset; | |
270 else | |
271 offset = 0; | |
272 | |
273 if(offset < 0) offset = 0; | |
274 | |
275 /* render the text */ | |
276 for (current=0; current<textlen; current++) | |
277 { | |
278 for (c=0; c<item->font->charcount; c++) | |
279 { | |
280 char_t *cchar = item->font->chars[c]; | |
281 if(cchar->c == *(text + current)) | |
282 { | |
283 render(skin->desktopbpp, | |
284 &priv->img, | |
285 item->font->image, | |
286 item->x + offset, | |
287 item->y, | |
288 cchar->x, | |
289 cchar->y, | |
290 (cchar->width + offset > item->length) ? item->length - offset : cchar->width, | |
291 cchar->height, | |
292 1); | |
293 offset += cchar->width; | |
294 break; | |
295 } | |
296 } | |
297 } | |
298 free(text); | |
299 } | |
300 } | |
301 } | |
302 | |
303 /******************************************************************/ | |
304 /* WIDGET related functions */ | |
305 /******************************************************************/ | |
306 | |
307 void renderwidget(skin_t *skin, image *dest, widget *item, int state) | |
308 { | |
309 if(!dest) return; | |
310 image *img = NULL; | |
311 int height; | |
312 int y; | |
313 if((item->type == tyButton) || (item->type == tyHpotmeter) || (item->type == tyPotmeter)) | |
314 img = item->bitmap[0]; | |
315 | |
316 if(!img) return; | |
317 | |
318 y = item->y; | |
319 if(item->type == tyPotmeter) | |
320 { | |
321 height = img->height / item->phases; | |
322 y = height * (int)(item->value * item->phases / 100); | |
323 if(y > img->height-height) | |
324 y = img->height - height; | |
325 } | |
326 else | |
327 { | |
328 height = img->height / 3; | |
329 y = state * height; | |
330 } | |
331 | |
332 /* redraw background */ | |
333 if(item->type == tyButton) | |
334 render(skin->desktopbpp, dest, find_background(skin,item), item->x, item->y, item->x, item->y, img->width, height, 1); | |
335 | |
336 if((item->type == tyHpotmeter) || (item->type == tyPotmeter)) | |
337 { | |
338 /* repaint the area behind the slider */ | |
339 render(skin->desktopbpp, dest, find_background(skin, item), item->wx, item->wy, item->wx, item->wy, item->wwidth, item->height, 1); | |
340 item->x = item->value * (item->wwidth-item->width) / 100 + item->wx; | |
341 if((item->x + item->width) > (item->wx + item->wwidth)) | |
342 item->x = item->wx + item->wwidth - item->width; | |
343 if(item->x < item->wx) | |
344 item->x = item->wx; | |
345 /* workaround for blue */ | |
346 if(item->type == tyHpotmeter) | |
347 height = (item->height < img->height / 3) ? item->height : img->height / 3; | |
348 } | |
349 render(skin->desktopbpp, dest, img, item->x, item->y, 0, y, img->width, height, 1); | |
350 } |