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