Mercurial > mplayer.hg
annotate gui/win32/skinload.c @ 26720:d68c3cd43cd4
Change subtitle selection order by giving "indirect" ways of specifying the
desired subtitle track the least priority.
Selection of displayed subtitles by language (-slang) and default track
attribute is only performed if all other ways have failed. They are not
directly controllable by the user (especially default tracks), therefore they
should not override -sub, -vobsub and even auto-subs.
Based on a patch by Sergey Malkovsky (mplayer.win32_gmail_com).
author | eugeni |
---|---|
date | Mon, 12 May 2008 20:40:39 +0000 |
parents | 9ba6d4487292 |
children | 9e6fdede8ece |
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 <stdlib.h> | |
23796 | 25 #include <stdio.h> |
23077 | 26 #include <inttypes.h> |
27 #include <windows.h> | |
28 | |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
29 #include "mp_msg.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
30 #include "cpudetect.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
31 #include "libswscale/rgb2rgb.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
32 #include "libswscale/swscale.h" |
23077 | 33 #include "gui.h" |
26372
76413880bfad
Update include paths to account for build system changes.
diego
parents:
23796
diff
changeset
|
34 #include "gui/bitmap.h" |
23077 | 35 |
36 #define MAX_LINESIZE 256 | |
37 | |
38 typedef struct | |
39 { | |
40 int msg; | |
41 char *name; | |
42 } evName; | |
43 | |
44 static const evName evNames[] = | |
45 { | |
46 { evNone, "evNone" }, | |
47 { evPlay, "evPlay" }, | |
48 { evDropFile, "evDropFile" }, | |
49 { evStop, "evStop" }, | |
50 { evPause, "evPause" }, | |
51 { evPrev, "evPrev" }, | |
52 { evNext, "evNext" }, | |
53 { evLoad, "evLoad" }, | |
54 { evEqualizer, "evEqualizer" }, | |
55 { evEqualizer, "evEqualeaser" }, | |
56 { evPlayList, "evPlaylist" }, | |
57 { evExit, "evExit" }, | |
58 { evIconify, "evIconify" }, | |
59 { evIncBalance, "evIncBalance" }, | |
60 { evDecBalance, "evDecBalance" }, | |
61 { evFullScreen, "evFullScreen" }, | |
62 { evFName, "evFName" }, | |
63 { evMovieTime, "evMovieTime" }, | |
64 { evAbout, "evAbout" }, | |
65 { evLoadPlay, "evLoadPlay" }, | |
66 { evPreferences, "evPreferences" }, | |
67 { evSkinBrowser, "evSkinBrowser" }, | |
68 { evBackward10sec, "evBackward10sec" }, | |
69 { evForward10sec, "evForward10sec" }, | |
70 { evBackward1min, "evBackward1min" }, | |
71 { evForward1min, "evForward1min" }, | |
72 { evBackward10min, "evBackward10min" }, | |
73 { evForward10min, "evForward10min" }, | |
74 { evIncVolume, "evIncVolume" }, | |
75 { evDecVolume, "evDecVolume" }, | |
76 { evMute, "evMute" }, | |
77 { evIncAudioBufDelay, "evIncAudioBufDelay" }, | |
78 { evDecAudioBufDelay, "evDecAudioBufDelay" }, | |
79 { evPlaySwitchToPause, "evPlaySwitchToPause" }, | |
80 { evPauseSwitchToPlay, "evPauseSwitchToPlay" }, | |
81 { evNormalSize, "evNormalSize" }, | |
82 { evDoubleSize, "evDoubleSize" }, | |
83 { evSetMoviePosition, "evSetMoviePosition" }, | |
84 { evSetVolume, "evSetVolume" }, | |
85 { evSetBalance, "evSetBalance" }, | |
86 { evHelp, "evHelp" }, | |
87 { evLoadSubtitle, "evLoadSubtitle" }, | |
88 { evPlayDVD, "evPlayDVD" }, | |
89 { evPlayVCD, "evPlayVCD" }, | |
90 { evSetURL, "evSetURL" }, | |
91 { evLoadAudioFile, "evLoadAudioFile" }, | |
92 { evDropSubtitle, "evDropSubtitle" }, | |
93 { evSetAspect, "evSetAspect" } | |
94 }; | |
95 | |
96 static const int evBoxs = sizeof(evNames) / sizeof(evName); | |
97 | |
98 static char *geteventname(int event) | |
99 { | |
100 int i; | |
101 for(i=0; i<evBoxs; i++) | |
102 if(evNames[i].msg == event) | |
103 return evNames[i].name; | |
104 return NULL; | |
105 } | |
106 | |
107 static inline int get_sws_cpuflags(void) | |
108 { | |
109 return (gCpuCaps.hasMMX ? SWS_CPU_CAPS_MMX : 0) | | |
110 (gCpuCaps.hasMMX2 ? SWS_CPU_CAPS_MMX2 : 0) | | |
111 (gCpuCaps.has3DNow ? SWS_CPU_CAPS_3DNOW : 0); | |
112 } | |
113 | |
114 /* reads a complete image as is into image buffer */ | |
115 static image *pngRead(skin_t *skin, unsigned char *fname) | |
116 { | |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
117 int i; |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
118 txSample bmp; |
23077 | 119 image *bf; |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
120 char *filename = NULL; |
23077 | 121 FILE *fp; |
122 | |
123 if(!stricmp(fname, "NULL")) return 0; | |
124 | |
125 /* find filename in order file file.png */ | |
126 if(!(fp = fopen(fname, "rb"))) | |
127 { | |
128 filename = calloc(1, strlen(skin->skindir) + strlen(fname) + 6); | |
129 sprintf(filename, "%s\\%s.png", skin->skindir, fname); | |
130 if(!(fp = fopen(filename, "rb"))) | |
131 { | |
132 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[png] cannot find image %s\n", filename); | |
133 free(filename); | |
134 return 0; | |
135 } | |
136 } | |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
137 fclose(fp); |
23077 | 138 |
139 for (i=0; i < skin->imagecount; i++) | |
140 if(!strcmp(fname, skin->images[i]->name)) | |
141 { | |
142 #ifdef DEBUG | |
143 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[png] skinfile %s already exists\n", fname); | |
144 #endif | |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
145 free(filename); |
23077 | 146 return skin->images[i]; |
147 } | |
148 (skin->imagecount)++; | |
149 skin->images = realloc(skin->images, sizeof(image *) * skin->imagecount); | |
150 bf = skin->images[(skin->imagecount) - 1] = calloc(1, sizeof(image)); | |
151 bf->name = strdup(fname); | |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
152 bpRead(filename ? filename : fname, &bmp); |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
153 free(filename); |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
154 bf->width = bmp.Width; bf->height = bmp.Height; |
23077 | 155 |
156 #ifdef DEBUG | |
157 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[png] loaded image %s\n", fname); | |
158 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[png] size: %dx%d bits: %d\n", bf->width, bf->height, BPP); | |
159 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[png] imagesize: %u\n", imgsize); | |
160 #endif | |
161 | |
162 bf->size = bf->width * bf->height * skin->desktopbpp / 8; | |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
163 if (skin->desktopbpp == 32) |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
164 bf->data = bmp.Image; |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
165 else { |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
166 bf->data = malloc(bf->size); |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
167 rgb32tobgr32(bmp.Image, bmp.Image, bmp.ImageSize); |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
168 if(skin->desktopbpp == 16) rgb32tobgr15(bmp.Image, bf->data, bmp.ImageSize); |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
169 else if(skin->desktopbpp == 24) rgb32tobgr24(bmp.Image, bf->data, bmp.ImageSize); |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
170 free(bmp.Image); |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
171 } |
23077 | 172 return bf; |
173 } | |
174 | |
175 /* frees all skin images */ | |
176 static void freeimages(skin_t *skin) | |
177 { | |
178 unsigned int i; | |
179 for (i=0; i<skin->imagecount; i++) | |
180 { | |
181 if(skin->images && skin->images[i]) | |
182 { | |
183 if(skin->images[i]->data) free(skin->images[i]->data); | |
184 if(skin->images[i]->name) free(skin->images[i]->name); | |
185 free(skin->images[i]); | |
186 } | |
187 } | |
188 free(skin->images); | |
189 } | |
190 | |
191 #ifdef DEBUG | |
192 void dumpwidgets(skin_t *skin) | |
193 { | |
194 unsigned int i; | |
195 for (i=0; i<skin->widgetcount; i++) | |
196 mp_msg(MSGT_GPLAYER, MSGL_V, "widget %p id %i\n", skin->widgets[i], skin->widgets[i]->id); | |
197 } | |
198 #endif | |
199 | |
200 static int counttonextchar(const char *s1, char c) | |
201 { | |
202 unsigned int i; | |
203 for (i=0; i<strlen(s1); i++) | |
204 if(s1[i] == c) return i; | |
205 return 0; | |
206 } | |
207 | |
208 static char *findnextstring(char *temp, const char *desc, int *base) | |
209 { | |
210 int len = counttonextchar(*base + desc, ','); | |
211 memset(temp, 0, strlen(desc) + 1); | |
212 if(!len) len = strlen(desc); | |
213 memcpy(temp, *base + desc, len); | |
214 *base += (len+1); | |
215 return temp; | |
216 } | |
217 | |
218 static void freeskin(skin_t *skin) | |
219 { | |
220 unsigned int i; | |
221 if(skin->skindir) | |
222 { | |
223 free(skin->skindir); | |
224 skin->skindir = NULL; | |
225 } | |
226 | |
227 for (i=1; i<=skin->lastusedid; i++) | |
228 skin->removewidget(skin, i); | |
229 | |
230 if(skin->widgets) | |
231 { | |
232 free(skin->widgets); | |
233 skin->widgets = NULL; | |
234 } | |
235 | |
236 freeimages(skin); | |
237 for(i=0; i<skin->windowcount; i++) | |
238 { | |
239 if(skin->windows[i]->name) | |
240 { | |
241 free(skin->windows[i]->name); | |
242 skin->windows[i]->name = NULL; | |
243 } | |
244 free(skin->windows[i]); | |
245 } | |
246 | |
247 free(skin->windows); | |
248 skin->windows = NULL; | |
249 | |
250 for (i=0; i<skin->fontcount; i++) | |
251 { | |
252 unsigned int x; | |
253 if(skin->fonts[i]->name) | |
254 { | |
255 free(skin->fonts[i]->name); | |
256 skin->fonts[i]->name = NULL; | |
257 } | |
258 | |
259 if(skin->fonts[i]->id) | |
260 { | |
261 free(skin->fonts[i]->id); | |
262 skin->fonts[i]->id = NULL; | |
263 } | |
264 | |
265 for (x=0; x<skin->fonts[i]->charcount; x++) | |
266 { | |
267 free(skin->fonts[i]->chars[x]); | |
268 skin->fonts[i]->chars[x] = NULL; | |
269 } | |
270 | |
271 if(skin->fonts[i]->chars) | |
272 { | |
273 free(skin->fonts[i]->chars); | |
274 skin->fonts[i]->chars = NULL; | |
275 } | |
276 | |
277 free(skin->fonts[i]); | |
278 skin->fonts[i] = NULL; | |
279 } | |
280 free(skin->fonts); | |
281 skin->fonts = NULL; | |
282 #ifdef DEBUG | |
283 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN FREE] skin freed\n"); | |
284 #endif | |
285 free(skin); | |
286 skin = NULL; | |
287 } | |
288 | |
289 static void removewidget(skin_t *skin, int id) | |
290 { | |
291 unsigned int i; | |
292 unsigned int pos=0; | |
293 widget **temp = calloc(skin->widgetcount - 1, sizeof(widget *)); | |
294 | |
295 for (i=0; i<skin->widgetcount; i++) | |
296 { | |
297 if(skin->widgets[i]->id == id) | |
298 { | |
299 if(skin->widgets[i]->label) | |
300 free(skin->widgets[i]->label); | |
301 free(skin->widgets[i]); | |
302 skin->widgets[i] = NULL; | |
303 } | |
304 else | |
305 { | |
306 temp[pos] = skin->widgets[i]; | |
307 pos++; | |
308 } | |
309 } | |
310 if (pos != i) | |
311 { | |
312 (skin->widgetcount)--; | |
313 free(skin->widgets); | |
314 skin->widgets = temp; | |
315 #ifdef DEBUG | |
316 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "removed widget %i\n", id); | |
317 #endif | |
318 return; | |
319 } | |
320 free(temp); | |
321 mp_msg(MSGT_GPLAYER, MSGL_ERR, "widget %i not found\n", id); | |
322 } | |
323 | |
324 static void addwidget(skin_t *skin, window *win, const char *desc) | |
325 { | |
326 widget *mywidget; | |
327 char *temp = calloc(1, strlen(desc) + 1); | |
328 (skin->widgetcount)++; | |
329 (skin->lastusedid)++; | |
330 skin->widgets = realloc(skin->widgets, sizeof(widget *) * skin->widgetcount); | |
331 mywidget = skin->widgets[(skin->widgetcount) - 1] = calloc(1, sizeof(widget)); | |
332 mywidget->id = skin->lastusedid; | |
333 mywidget->window = win->type; | |
334 /* parse and fill widget specific info */ | |
335 if(!strncmp(desc, "base", 4)) | |
336 { | |
337 int base = counttonextchar(desc, '=') + 1; | |
338 mywidget->type = tyBase; | |
339 mywidget->bitmap[0] = pngRead(skin, findnextstring(temp, desc, &base)); | |
340 mywidget->wx = mywidget->x = atoi(findnextstring(temp, desc, &base)); | |
341 mywidget->wy = mywidget->y = atoi(findnextstring(temp, desc, &base)); | |
342 mywidget->wwidth = mywidget->width = atoi(findnextstring(temp, desc, &base)); | |
343 mywidget->wheight = mywidget->height = atoi(findnextstring(temp, desc, &base)); | |
344 win->base = mywidget; | |
345 #ifdef DEBUG | |
346 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [BASE] %s %i %i %i %i\n", | |
347 (mywidget->bitmap[0]) ? mywidget->bitmap[0]->name : NULL, | |
348 mywidget->x, mywidget->y, mywidget->width, mywidget->height); | |
349 #endif | |
350 } | |
351 else if(!strncmp(desc, "button", 6)) | |
352 { | |
353 int base = counttonextchar(desc, '=') + 1; | |
354 int i; | |
355 mywidget->type = tyButton; | |
356 mywidget->bitmap[0] = pngRead(skin, findnextstring(temp, desc, &base)); | |
357 mywidget->wx = mywidget->x = atoi(findnextstring(temp, desc, &base)); | |
358 mywidget->wy = mywidget->y = atoi(findnextstring(temp, desc, &base)); | |
359 mywidget->wwidth = mywidget->width = atoi(findnextstring(temp, desc, &base)); | |
360 mywidget->wheight = mywidget->height = atoi(findnextstring(temp, desc, &base)); | |
361 findnextstring(temp, desc, &base); | |
362 | |
363 /* Assign corresponding event to the widget */ | |
364 mywidget->msg = evNone; | |
365 for (i=0; i<evBoxs; i++) | |
366 { | |
367 if(!strcmp(temp, evNames[i].name)) | |
368 { | |
369 mywidget->msg = evNames[i].msg; | |
370 break; | |
371 } | |
372 } | |
373 | |
374 #ifdef DEBUG | |
375 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [BUTTON] %s %i %i %i %i msg %i\n", | |
376 (mywidget->bitmap[0]) ? mywidget->bitmap[0]->name : NULL, | |
377 mywidget->x, mywidget->y, mywidget->width, mywidget->height, mywidget->msg); | |
378 #endif | |
379 } | |
380 else if(!strncmp(desc, "hpotmeter", 9) || !strncmp(desc, "vpotmeter", 9)) | |
381 { | |
382 int base = counttonextchar(desc, '=') + 1; | |
383 int i; | |
384 /* hpotmeter = button, bwidth, bheight, phases, numphases, default, X, Y, width, height, message */ | |
385 if(!strncmp(desc, "hpotmeter", 9)) mywidget->type = tyHpotmeter; | |
386 else mywidget->type = tyVpotmeter; | |
387 mywidget->bitmap[0] = pngRead(skin, findnextstring(temp, desc, &base)); | |
388 mywidget->width = atoi(findnextstring(temp, desc, &base)); | |
389 mywidget->height = atoi(findnextstring(temp, desc, &base)); | |
390 mywidget->bitmap[1] = pngRead(skin, findnextstring(temp, desc, &base)); | |
391 mywidget->phases = atoi(findnextstring(temp, desc, &base)); | |
392 mywidget->value = atof(findnextstring(temp, desc, &base)); | |
393 mywidget->x = mywidget->wx = atoi(findnextstring(temp, desc, &base)); | |
394 mywidget->y = mywidget->wy = atoi(findnextstring(temp, desc, &base)); | |
395 mywidget->wwidth = atoi(findnextstring(temp, desc, &base)); | |
396 mywidget->wheight = atoi(findnextstring(temp, desc, &base)); | |
397 findnextstring(temp, desc, &base); | |
398 mywidget->msg = evNone; | |
399 for (i=0; i<evBoxs; i++) | |
400 { | |
401 if(!strcmp(temp, evNames[i].name)) | |
402 { | |
403 mywidget->msg = evNames[i].msg; | |
404 break; | |
405 } | |
406 } | |
407 #ifdef DEBUG | |
408 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] %s %s %i %i %s %i %f %i %i %i %i msg %i\n", | |
409 (mywidget->type == tyHpotmeter) ? "[HPOTMETER]" : "[VPOTMETER]", | |
410 (mywidget->bitmap[0]) ? mywidget->bitmap[0]->name : NULL, | |
411 mywidget->width, mywidget->height, | |
412 (mywidget->bitmap[1]) ? mywidget->bitmap[1]->name : NULL, | |
413 mywidget->phases, mywidget->value, | |
414 mywidget->wx, mywidget->wy, mywidget->wwidth, mywidget->wwidth, | |
415 mywidget->msg); | |
416 #endif | |
417 } | |
418 else if(!strncmp(desc, "potmeter", 8)) | |
419 { | |
420 int base = counttonextchar(desc, '=') + 1; | |
421 int i; | |
422 /* potmeter = phases, numphases, default, X, Y, width, height, message */ | |
423 mywidget->type = tyPotmeter; | |
424 mywidget->bitmap[0] = pngRead(skin, findnextstring(temp, desc, &base)); | |
425 mywidget->phases = atoi(findnextstring(temp, desc, &base)); | |
426 mywidget->value = atof(findnextstring(temp, desc, &base)); | |
427 mywidget->wx = mywidget->x = atoi(findnextstring(temp, desc, &base)); | |
428 mywidget->wy = mywidget->y = atoi(findnextstring(temp, desc, &base)); | |
429 mywidget->wwidth = mywidget->width = atoi(findnextstring(temp, desc, &base)); | |
430 mywidget->wheight = mywidget->height = atoi(findnextstring(temp, desc, &base)); | |
431 findnextstring(temp, desc, &base); | |
432 mywidget->msg = evNone; | |
433 for (i=0; i<evBoxs; i++) | |
434 { | |
435 if(!strcmp(temp, evNames[i].name)) | |
436 { | |
437 mywidget->msg=evNames[i].msg; | |
438 break; | |
439 } | |
440 } | |
441 #ifdef DEBUG | |
442 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [POTMETER] %s %i %i %i %f %i %i msg %i\n", | |
443 (mywidget->bitmap[0]) ? mywidget->bitmap[0]->name : NULL, | |
444 mywidget->width, mywidget->height, | |
445 mywidget->phases, mywidget->value, | |
446 mywidget->x, mywidget->y, | |
447 mywidget->msg); | |
448 #endif | |
449 } | |
450 else if(!strncmp(desc, "menu", 4)) | |
451 { | |
452 int base = counttonextchar(desc, '=') + 1; | |
453 int i; | |
454 mywidget->type = tyMenu; | |
455 mywidget->wx=atoi(findnextstring(temp, desc, &base)); | |
456 mywidget->x=0; | |
457 mywidget->wy=mywidget->y=atoi(findnextstring(temp, desc, &base)); | |
458 mywidget->wwidth=mywidget->width=atoi(findnextstring(temp, desc, &base)); | |
459 mywidget->wheight=mywidget->height=atoi(findnextstring(temp, desc, &base)); | |
460 findnextstring(temp, desc, &base); | |
461 mywidget->msg = evNone; | |
462 for (i=0; i<evBoxs; i++) | |
463 { | |
464 if(!strcmp(temp, evNames[i].name)) | |
465 { | |
466 mywidget->msg = evNames[i].msg; | |
467 break; | |
468 } | |
469 } | |
470 #ifdef DEBUG | |
471 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [MENU] %i %i %i %i msg %i\n", | |
472 mywidget->x, mywidget->y, mywidget->width, mywidget->height, mywidget->msg); | |
473 #endif | |
474 } | |
475 else if(!strncmp(desc, "selected", 8)) | |
476 { | |
477 win->base->bitmap[1] = pngRead(skin, (char *) desc + 9); | |
478 #ifdef DEBUG | |
479 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [BASE] added image %s\n", win->base->bitmap[1]->name); | |
480 #endif | |
481 } | |
482 else if(!strncmp(desc, "slabel",6)) | |
483 { | |
484 int base = counttonextchar(desc, '=') + 1; | |
485 unsigned int i; | |
486 mywidget->type = tySlabel; | |
487 mywidget->wx = mywidget->x = atoi(findnextstring(temp, desc, &base)); | |
488 mywidget->wy = mywidget->y = atoi(findnextstring(temp, desc, &base)); | |
489 findnextstring(temp, desc, &base); | |
490 mywidget->font = NULL; | |
491 for (i=0; i<skin->fontcount; i++) | |
492 { | |
493 if(!strcmp(temp, skin->fonts[i]->name)) | |
494 { | |
495 mywidget->font = skin->fonts[i]; | |
496 break; | |
497 } | |
498 } | |
499 mywidget->label = strdup(findnextstring(temp, desc, &base)); | |
500 #ifdef DEBUG | |
501 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [SLABEL] %i %i %s %s\n", | |
502 mywidget->x, mywidget->y, mywidget->font->name, mywidget->label); | |
503 #endif | |
504 } | |
505 else if(!strncmp(desc, "dlabel", 6)) | |
506 { | |
507 int base = counttonextchar(desc, '=') + 1; | |
508 unsigned int i; | |
509 mywidget->type = tyDlabel; | |
510 mywidget->wx = mywidget->x = atoi(findnextstring(temp, desc, &base)); | |
511 mywidget->wy = mywidget->y = atoi(findnextstring(temp, desc, &base)); | |
512 mywidget->length = atoi(findnextstring(temp, desc, &base)); | |
513 mywidget->align = atoi(findnextstring(temp, desc, &base)); | |
514 findnextstring(temp, desc, &base); | |
515 mywidget->font = NULL; | |
516 for (i=0; i<skin->fontcount; i++) | |
517 { | |
518 if(!strcmp(temp, skin->fonts[i]->name)) | |
519 { | |
520 mywidget->font=skin->fonts[i]; | |
521 break; | |
522 } | |
523 } | |
524 mywidget->label=strdup(findnextstring(temp, desc, &base)); | |
525 #ifdef DEBUG | |
526 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [DLABEL] %i %i %i %i %s \"%s\"\n", | |
527 mywidget->x, mywidget->y, mywidget->length, mywidget->align, mywidget->font->name, mywidget->label); | |
528 #endif | |
529 } | |
530 free(temp); | |
531 } | |
532 | |
533 static void loadfonts(skin_t* skin) | |
534 { | |
535 unsigned int x; | |
536 for (x=0; x<skin->fontcount; x++) | |
537 { | |
538 FILE *fp; | |
539 int linenumber=0; | |
540 char *filename; | |
541 char *tmp = calloc(1, MAX_LINESIZE); | |
542 char *desc = calloc(1, MAX_LINESIZE); | |
543 filename = calloc(1, strlen(skin->skindir) + strlen(skin->fonts[x]->name) + 6); | |
544 sprintf(filename, "%s\\%s.fnt", skin->skindir, skin->fonts[x]->name); | |
545 if(!(fp = fopen(filename,"rb"))) | |
546 { | |
547 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[FONT LOAD] Font not found \"%s\"\n", skin->fonts[x]->name); | |
548 return; | |
549 } | |
550 while(!feof(fp)) | |
551 { | |
552 int pos = 0; | |
553 unsigned int i; | |
554 fgets(tmp, MAX_LINESIZE, fp); | |
555 linenumber++; | |
556 memset(desc, 0, MAX_LINESIZE); | |
557 for (i=0; i<strlen(tmp); i++) | |
558 { | |
559 /* remove spaces and linebreaks */ | |
560 if((tmp[i] == ' ') || (tmp[i] == '\n') || (tmp[i] == '\r')) continue; | |
561 /* remove comments */ | |
562 if((tmp[i] == ';') && ((i < 1) || (tmp[i-1] != '\"'))) | |
563 { | |
564 #ifdef DEBUG | |
565 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[FONT LOAD] Comment: %s", tmp + i + 1); | |
566 #endif | |
567 break; | |
568 } | |
569 desc[pos] = tmp[i]; | |
570 pos++; | |
571 } | |
572 if(!strlen(desc)) continue; | |
573 /* now we have "readable" output -> parse it */ | |
574 if(!strncmp(desc, "image", 5)) | |
575 { | |
576 skin->fonts[x]->image = pngRead(skin, desc + 6); | |
577 #ifdef DEBUG | |
578 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[FONT] [IMAGE] \"%s\"\n", desc + 6); | |
579 #endif | |
580 } | |
581 else | |
582 { | |
583 int base = 4; | |
584 if(*desc != '"') break; | |
585 if(*(desc + 1) == 0) break; | |
586 (skin->fonts[x]->charcount)++; | |
587 skin->fonts[x]->chars = realloc(skin->fonts[x]->chars, sizeof(char_t *) *skin->fonts[x]->charcount); | |
588 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]=calloc(1, sizeof(char_t)); | |
589 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->c = ((*(desc + 1) == '"') && (*(desc + 2) != '"')) ? ' ': *(desc + 1); | |
590 if((*(desc + 1) == '"') && (*(desc + 2) != '"')) base = 3; | |
591 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->x = atoi(findnextstring(tmp, desc, &base)); | |
592 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->y = atoi(findnextstring(tmp, desc, &base)); | |
593 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->width = atoi(findnextstring(tmp, desc, &base)); | |
594 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->height = atoi(findnextstring(tmp, desc, &base)); | |
595 #ifdef DEBUG | |
596 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[FONT] [CHAR] %c %i %i %i %i\n", | |
597 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->c, | |
598 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->x, | |
599 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->y, | |
600 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->width, | |
601 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->height); | |
602 #endif | |
603 } | |
604 } | |
605 free(desc); | |
606 free(filename); | |
607 free(tmp); | |
608 fclose(fp); | |
609 } | |
610 } | |
611 | |
612 skin_t* loadskin(char* skindir, int desktopbpp) | |
613 { | |
614 FILE *fp; | |
615 int reachedendofwindow = 0; | |
616 int linenumber = 0; | |
617 skin_t *skin = calloc(1, sizeof(skin_t)); | |
618 char *filename; | |
619 char *tmp = calloc(1, MAX_LINESIZE); | |
620 char *desc = calloc(1, MAX_LINESIZE); | |
621 window* mywindow = NULL; | |
622 | |
623 /* init swscaler */ | |
624 sws_rgb2rgb_init(get_sws_cpuflags()); | |
625 /* setup funcs */ | |
626 skin->freeskin = freeskin; | |
627 skin->pngRead = pngRead; | |
628 skin->addwidget = addwidget; | |
629 skin->removewidget = removewidget; | |
630 skin->geteventname = geteventname; | |
631 skin->desktopbpp = desktopbpp; | |
632 skin->skindir = strdup(skindir); | |
633 | |
634 filename = calloc(1, strlen(skin->skindir) + strlen("skin") + 2); | |
635 sprintf(filename, "%s\\skin", skin->skindir); | |
636 if(!(fp = fopen(filename, "rb"))) | |
637 { | |
638 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[SKIN LOAD] Skin \"%s\" not found\n", skindir); | |
639 skin->freeskin(skin); | |
640 return NULL; | |
641 } | |
642 | |
643 while(!feof(fp)) | |
644 { | |
645 int pos = 0; | |
646 unsigned int i; | |
647 int insidequote = 0; | |
648 fgets(tmp, MAX_LINESIZE, fp); | |
649 linenumber++; | |
650 memset(desc, 0, MAX_LINESIZE); | |
651 for (i=0; i<strlen(tmp); i++) | |
652 { | |
653 if((tmp[i] == '"') && !insidequote) { insidequote=1; continue; } | |
654 else if((tmp[i] == '"') && insidequote) { insidequote=0 ; continue; } | |
655 /* remove spaces and linebreaks */ | |
656 if((!insidequote && (tmp[i] == ' ')) || (tmp[i] == '\n') || (tmp[i] == '\r')) continue; | |
657 /* remove comments */ | |
658 else if(tmp[i] == ';') | |
659 { | |
660 #ifdef DEBUG | |
661 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN LOAD] Comment: %s", tmp + i + 1); | |
662 #endif | |
663 break; | |
664 } | |
665 desc[pos] = tmp[i]; | |
666 pos++; | |
667 } | |
668 | |
669 if(!strlen(desc)) continue; | |
670 /* now we have "readable" output -> parse it */ | |
671 /* parse window specific info */ | |
672 if(!strncmp(desc, "section", 7)) | |
673 { | |
674 #ifdef DEBUG | |
675 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [SECTION] \"%s\"\n", desc + 8); | |
676 #endif | |
677 } | |
678 else if(!strncmp(desc, "window", 6)) | |
679 { | |
680 #ifdef DEBUG | |
681 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [WINDOW] \"%s\"\n", desc + 7); | |
682 #endif | |
683 reachedendofwindow = 0; | |
684 (skin->windowcount)++; | |
685 skin->windows = realloc(skin->windows, sizeof(window *) * skin->windowcount); | |
686 mywindow = skin->windows[(skin->windowcount) - 1] = calloc(1, sizeof(window)); | |
687 mywindow->name = strdup(desc + 7); | |
688 if(!strncmp(desc + 7, "main", 4)) mywindow->type = wiMain; | |
689 else if(!strncmp(desc+7, "sub", 3)) | |
690 { | |
691 mywindow->type = wiSub; | |
692 mywindow->decoration = 1; | |
693 } | |
694 else if(!strncmp(desc + 7, "menu", 4)) mywindow->type = wiMenu; | |
695 else if(!strncmp(desc + 7, "playbar", 7)) mywindow->type = wiPlaybar; | |
696 else mp_msg(MSGT_GPLAYER, MSGL_V, "[SKIN] warning found unknown windowtype"); | |
697 } | |
698 else if(!strncmp(desc, "decoration", 10) && !strncmp(desc + 11, "enable", 6)) | |
699 { | |
700 mywindow->decoration = 1; | |
701 #ifdef DEBUG | |
702 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [DECORATION] enabled decoration for window \"%s\"\n", mywindow->name); | |
703 #endif | |
704 } | |
705 else if(!strncmp(desc, "background", 10)) | |
706 { | |
707 int base = counttonextchar(desc, '=') + 1; | |
708 char temp[MAX_LINESIZE]; | |
709 mywindow->backgroundcolor[0] = atoi(findnextstring(temp, desc, &base)); | |
710 mywindow->backgroundcolor[1] = atoi(findnextstring(temp, desc, &base)); | |
711 mywindow->backgroundcolor[2] = atoi(findnextstring(temp, desc, &base)); | |
712 #ifdef DEBUG | |
713 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [BACKGROUND] window \"%s\" has backgroundcolor (%i,%i,%i)\n", mywindow->name, | |
714 mywindow->backgroundcolor[0], | |
715 mywindow->backgroundcolor[1], | |
716 mywindow->backgroundcolor[2]); | |
717 #endif | |
718 } | |
719 else if(!strncmp(desc, "end", 3)) | |
720 { | |
721 if(reachedendofwindow) | |
722 { | |
723 #ifdef DEBUG | |
724 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [END] of section\n"); | |
725 #endif | |
726 } | |
727 else | |
728 { | |
729 reachedendofwindow = 1; | |
730 #ifdef DEBUG | |
731 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [END] of window \"%s\"\n", mywindow->name); | |
732 #endif | |
733 } | |
734 } | |
735 else if(!strncmp(desc, "font", 4)) | |
736 { | |
737 unsigned int i; | |
738 int id = 0; | |
739 char temp[MAX_LINESIZE]; | |
740 int base = counttonextchar(desc, '=')+1; | |
741 findnextstring(temp, desc, &base); | |
742 findnextstring(temp, desc, &base); | |
743 for (i=0; i<skin->fontcount; i++) | |
744 if(!strcmp(skin->fonts[i]->id, temp)) | |
745 { | |
746 id = i; | |
747 break; | |
748 } | |
749 if(!id) | |
750 { | |
751 int base = counttonextchar(desc, '=') + 1; | |
752 findnextstring(temp, desc, &base); | |
753 id = skin->fontcount; | |
754 (skin->fontcount)++; | |
755 skin->fonts = realloc(skin->fonts, sizeof(font_t *) * skin->fontcount); | |
756 skin->fonts[id]=calloc(1, sizeof(font_t)); | |
757 skin->fonts[id]->name = strdup(temp); | |
758 skin->fonts[id]->id = strdup(findnextstring(temp, desc, &base)); | |
759 } | |
760 #ifdef DEBUG | |
761 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [FONT] id \"%s\" name \"%s\"\n", skin->fonts[id]->name, skin->fonts[id]->id); | |
762 #endif | |
763 } | |
764 else | |
765 skin->addwidget(skin, mywindow, desc); | |
766 } | |
767 | |
768 free(desc); | |
769 free(filename); | |
770 free(tmp); | |
771 fclose(fp); | |
772 loadfonts(skin); | |
773 mp_msg(MSGT_GPLAYER, MSGL_V, "[SKIN LOAD] loaded skin \"%s\"\n", skin->skindir); | |
774 /* dumpwidgets(skin); */ | |
775 return skin; | |
776 } |