Mercurial > mplayer.hg
annotate gui/win32/skinload.c @ 33043:04203ae3000c
Always use get_format, reduces usage of CODEC_CAP_HWACCEL* conditions.
author | reimar |
---|---|
date | Sun, 27 Mar 2011 14:02:32 +0000 |
parents | c4891d10ddbb |
children | 9684ad0e1291 |
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/swscale.h" |
32833
c4891d10ddbb
Adjust #include paths after the merge of libavcore into libavutil in FFmpeg.
diego
parents:
32537
diff
changeset
|
32 #include "libavutil/imgutils.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 /* reads a complete image as is into image buffer */ | |
108 static image *pngRead(skin_t *skin, unsigned char *fname) | |
109 { | |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
110 int i; |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
111 txSample bmp; |
23077 | 112 image *bf; |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
113 char *filename = NULL; |
23077 | 114 FILE *fp; |
115 | |
116 if(!stricmp(fname, "NULL")) return 0; | |
117 | |
118 /* find filename in order file file.png */ | |
119 if(!(fp = fopen(fname, "rb"))) | |
120 { | |
121 filename = calloc(1, strlen(skin->skindir) + strlen(fname) + 6); | |
122 sprintf(filename, "%s\\%s.png", skin->skindir, fname); | |
123 if(!(fp = fopen(filename, "rb"))) | |
124 { | |
125 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[png] cannot find image %s\n", filename); | |
126 free(filename); | |
127 return 0; | |
128 } | |
129 } | |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
130 fclose(fp); |
23077 | 131 |
132 for (i=0; i < skin->imagecount; i++) | |
133 if(!strcmp(fname, skin->images[i]->name)) | |
134 { | |
135 #ifdef DEBUG | |
136 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[png] skinfile %s already exists\n", fname); | |
137 #endif | |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
138 free(filename); |
23077 | 139 return skin->images[i]; |
140 } | |
141 (skin->imagecount)++; | |
142 skin->images = realloc(skin->images, sizeof(image *) * skin->imagecount); | |
143 bf = skin->images[(skin->imagecount) - 1] = calloc(1, sizeof(image)); | |
144 bf->name = strdup(fname); | |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
145 bpRead(filename ? filename : fname, &bmp); |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
146 free(filename); |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
147 bf->width = bmp.Width; bf->height = bmp.Height; |
23077 | 148 |
149 #ifdef DEBUG | |
150 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[png] loaded image %s\n", fname); | |
151 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[png] size: %dx%d bits: %d\n", bf->width, bf->height, BPP); | |
152 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[png] imagesize: %u\n", imgsize); | |
153 #endif | |
154 | |
155 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
|
156 if (skin->desktopbpp == 32) |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
157 bf->data = bmp.Image; |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
158 else { |
32028
9e6fdede8ece
gui: remove direct usage of rgb2rgb interface, use swscale instead
ramiro
parents:
26457
diff
changeset
|
159 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
|
160 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
|
161 uint8_t *dst[4] = { NULL, NULL, NULL, NULL }; |
9e6fdede8ece
gui: remove direct usage of rgb2rgb interface, use swscale instead
ramiro
parents:
26457
diff
changeset
|
162 int dst_stride[4]; |
9e6fdede8ece
gui: remove direct usage of rgb2rgb interface, use swscale instead
ramiro
parents:
26457
diff
changeset
|
163 enum PixelFormat out_pix_fmt; |
9e6fdede8ece
gui: remove direct usage of rgb2rgb interface, use swscale instead
ramiro
parents:
26457
diff
changeset
|
164 struct SwsContext *sws; |
9e6fdede8ece
gui: remove direct usage of rgb2rgb interface, use swscale instead
ramiro
parents:
26457
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 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
|
169 bmp.Width, bmp.Height, out_pix_fmt, |
9e6fdede8ece
gui: remove direct usage of rgb2rgb interface, use swscale instead
ramiro
parents:
26457
diff
changeset
|
170 SWS_POINT, NULL, NULL, NULL); |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
171 bf->data = malloc(bf->size); |
32028
9e6fdede8ece
gui: remove direct usage of rgb2rgb interface, use swscale instead
ramiro
parents:
26457
diff
changeset
|
172 dst[0] = bf->data; |
9e6fdede8ece
gui: remove direct usage of rgb2rgb interface, use swscale instead
ramiro
parents:
26457
diff
changeset
|
173 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
|
174 sws_freeContext(sws); |
23266
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
175 free(bmp.Image); |
6cd7f1c23d90
Reuse linux code for reading png images for windows Gui,
reimar
parents:
23091
diff
changeset
|
176 } |
23077 | 177 return bf; |
178 } | |
179 | |
180 /* frees all skin images */ | |
181 static void freeimages(skin_t *skin) | |
182 { | |
183 unsigned int i; | |
184 for (i=0; i<skin->imagecount; i++) | |
185 { | |
186 if(skin->images && skin->images[i]) | |
187 { | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
188 free(skin->images[i]->data); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
189 free(skin->images[i]->name); |
23077 | 190 free(skin->images[i]); |
191 } | |
192 } | |
193 free(skin->images); | |
194 } | |
195 | |
196 #ifdef DEBUG | |
197 void dumpwidgets(skin_t *skin) | |
198 { | |
199 unsigned int i; | |
200 for (i=0; i<skin->widgetcount; i++) | |
201 mp_msg(MSGT_GPLAYER, MSGL_V, "widget %p id %i\n", skin->widgets[i], skin->widgets[i]->id); | |
202 } | |
203 #endif | |
204 | |
205 static int counttonextchar(const char *s1, char c) | |
206 { | |
207 unsigned int i; | |
208 for (i=0; i<strlen(s1); i++) | |
209 if(s1[i] == c) return i; | |
210 return 0; | |
211 } | |
212 | |
213 static char *findnextstring(char *temp, const char *desc, int *base) | |
214 { | |
215 int len = counttonextchar(*base + desc, ','); | |
216 memset(temp, 0, strlen(desc) + 1); | |
217 if(!len) len = strlen(desc); | |
218 memcpy(temp, *base + desc, len); | |
219 *base += (len+1); | |
220 return temp; | |
221 } | |
222 | |
223 static void freeskin(skin_t *skin) | |
224 { | |
225 unsigned int i; | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
226 |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
227 free(skin->skindir); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
228 skin->skindir = NULL; |
23077 | 229 |
230 for (i=1; i<=skin->lastusedid; i++) | |
231 skin->removewidget(skin, i); | |
232 | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
233 free(skin->widgets); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
234 skin->widgets = NULL; |
23077 | 235 |
236 freeimages(skin); | |
237 for(i=0; i<skin->windowcount; i++) | |
238 { | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
239 free(skin->windows[i]->name); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
240 skin->windows[i]->name = NULL; |
23077 | 241 free(skin->windows[i]); |
242 } | |
243 | |
244 free(skin->windows); | |
245 skin->windows = NULL; | |
246 | |
247 for (i=0; i<skin->fontcount; i++) | |
248 { | |
249 unsigned int x; | |
250 | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
251 free(skin->fonts[i]->name); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
252 skin->fonts[i]->name = NULL; |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
253 |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
254 free(skin->fonts[i]->id); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
255 skin->fonts[i]->id = NULL; |
23077 | 256 |
257 for (x=0; x<skin->fonts[i]->charcount; x++) | |
258 { | |
259 free(skin->fonts[i]->chars[x]); | |
260 skin->fonts[i]->chars[x] = NULL; | |
261 } | |
262 | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
263 free(skin->fonts[i]->chars); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
264 skin->fonts[i]->chars = NULL; |
23077 | 265 |
266 free(skin->fonts[i]); | |
267 skin->fonts[i] = NULL; | |
268 } | |
269 free(skin->fonts); | |
270 skin->fonts = NULL; | |
271 #ifdef DEBUG | |
272 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN FREE] skin freed\n"); | |
273 #endif | |
274 free(skin); | |
275 skin = NULL; | |
276 } | |
277 | |
278 static void removewidget(skin_t *skin, int id) | |
279 { | |
280 unsigned int i; | |
281 unsigned int pos=0; | |
282 widget **temp = calloc(skin->widgetcount - 1, sizeof(widget *)); | |
283 | |
284 for (i=0; i<skin->widgetcount; i++) | |
285 { | |
286 if(skin->widgets[i]->id == id) | |
287 { | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32028
diff
changeset
|
288 free(skin->widgets[i]->label); |
23077 | 289 free(skin->widgets[i]); |
290 skin->widgets[i] = NULL; | |
291 } | |
292 else | |
293 { | |
294 temp[pos] = skin->widgets[i]; | |
295 pos++; | |
296 } | |
297 } | |
298 if (pos != i) | |
299 { | |
300 (skin->widgetcount)--; | |
301 free(skin->widgets); | |
302 skin->widgets = temp; | |
303 #ifdef DEBUG | |
304 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "removed widget %i\n", id); | |
305 #endif | |
306 return; | |
307 } | |
308 free(temp); | |
309 mp_msg(MSGT_GPLAYER, MSGL_ERR, "widget %i not found\n", id); | |
310 } | |
311 | |
312 static void addwidget(skin_t *skin, window *win, const char *desc) | |
313 { | |
314 widget *mywidget; | |
315 char *temp = calloc(1, strlen(desc) + 1); | |
316 (skin->widgetcount)++; | |
317 (skin->lastusedid)++; | |
318 skin->widgets = realloc(skin->widgets, sizeof(widget *) * skin->widgetcount); | |
319 mywidget = skin->widgets[(skin->widgetcount) - 1] = calloc(1, sizeof(widget)); | |
320 mywidget->id = skin->lastusedid; | |
321 mywidget->window = win->type; | |
322 /* parse and fill widget specific info */ | |
323 if(!strncmp(desc, "base", 4)) | |
324 { | |
325 int base = counttonextchar(desc, '=') + 1; | |
326 mywidget->type = tyBase; | |
327 mywidget->bitmap[0] = pngRead(skin, findnextstring(temp, desc, &base)); | |
328 mywidget->wx = mywidget->x = atoi(findnextstring(temp, desc, &base)); | |
329 mywidget->wy = mywidget->y = atoi(findnextstring(temp, desc, &base)); | |
330 mywidget->wwidth = mywidget->width = atoi(findnextstring(temp, desc, &base)); | |
331 mywidget->wheight = mywidget->height = atoi(findnextstring(temp, desc, &base)); | |
332 win->base = mywidget; | |
333 #ifdef DEBUG | |
334 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [BASE] %s %i %i %i %i\n", | |
335 (mywidget->bitmap[0]) ? mywidget->bitmap[0]->name : NULL, | |
336 mywidget->x, mywidget->y, mywidget->width, mywidget->height); | |
337 #endif | |
338 } | |
339 else if(!strncmp(desc, "button", 6)) | |
340 { | |
341 int base = counttonextchar(desc, '=') + 1; | |
342 int i; | |
343 mywidget->type = tyButton; | |
344 mywidget->bitmap[0] = pngRead(skin, findnextstring(temp, desc, &base)); | |
345 mywidget->wx = mywidget->x = atoi(findnextstring(temp, desc, &base)); | |
346 mywidget->wy = mywidget->y = atoi(findnextstring(temp, desc, &base)); | |
347 mywidget->wwidth = mywidget->width = atoi(findnextstring(temp, desc, &base)); | |
348 mywidget->wheight = mywidget->height = atoi(findnextstring(temp, desc, &base)); | |
349 findnextstring(temp, desc, &base); | |
350 | |
351 /* Assign corresponding event to the widget */ | |
352 mywidget->msg = evNone; | |
353 for (i=0; i<evBoxs; i++) | |
354 { | |
355 if(!strcmp(temp, evNames[i].name)) | |
356 { | |
357 mywidget->msg = evNames[i].msg; | |
358 break; | |
359 } | |
360 } | |
361 | |
362 #ifdef DEBUG | |
363 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [BUTTON] %s %i %i %i %i msg %i\n", | |
364 (mywidget->bitmap[0]) ? mywidget->bitmap[0]->name : NULL, | |
365 mywidget->x, mywidget->y, mywidget->width, mywidget->height, mywidget->msg); | |
366 #endif | |
367 } | |
368 else if(!strncmp(desc, "hpotmeter", 9) || !strncmp(desc, "vpotmeter", 9)) | |
369 { | |
370 int base = counttonextchar(desc, '=') + 1; | |
371 int i; | |
372 /* hpotmeter = button, bwidth, bheight, phases, numphases, default, X, Y, width, height, message */ | |
373 if(!strncmp(desc, "hpotmeter", 9)) mywidget->type = tyHpotmeter; | |
374 else mywidget->type = tyVpotmeter; | |
375 mywidget->bitmap[0] = pngRead(skin, findnextstring(temp, desc, &base)); | |
376 mywidget->width = atoi(findnextstring(temp, desc, &base)); | |
377 mywidget->height = atoi(findnextstring(temp, desc, &base)); | |
378 mywidget->bitmap[1] = pngRead(skin, findnextstring(temp, desc, &base)); | |
379 mywidget->phases = atoi(findnextstring(temp, desc, &base)); | |
380 mywidget->value = atof(findnextstring(temp, desc, &base)); | |
381 mywidget->x = mywidget->wx = atoi(findnextstring(temp, desc, &base)); | |
382 mywidget->y = mywidget->wy = atoi(findnextstring(temp, desc, &base)); | |
383 mywidget->wwidth = atoi(findnextstring(temp, desc, &base)); | |
384 mywidget->wheight = atoi(findnextstring(temp, desc, &base)); | |
385 findnextstring(temp, desc, &base); | |
386 mywidget->msg = evNone; | |
387 for (i=0; i<evBoxs; i++) | |
388 { | |
389 if(!strcmp(temp, evNames[i].name)) | |
390 { | |
391 mywidget->msg = evNames[i].msg; | |
392 break; | |
393 } | |
394 } | |
395 #ifdef DEBUG | |
396 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] %s %s %i %i %s %i %f %i %i %i %i msg %i\n", | |
397 (mywidget->type == tyHpotmeter) ? "[HPOTMETER]" : "[VPOTMETER]", | |
398 (mywidget->bitmap[0]) ? mywidget->bitmap[0]->name : NULL, | |
399 mywidget->width, mywidget->height, | |
400 (mywidget->bitmap[1]) ? mywidget->bitmap[1]->name : NULL, | |
401 mywidget->phases, mywidget->value, | |
402 mywidget->wx, mywidget->wy, mywidget->wwidth, mywidget->wwidth, | |
403 mywidget->msg); | |
404 #endif | |
405 } | |
406 else if(!strncmp(desc, "potmeter", 8)) | |
407 { | |
408 int base = counttonextchar(desc, '=') + 1; | |
409 int i; | |
410 /* potmeter = phases, numphases, default, X, Y, width, height, message */ | |
411 mywidget->type = tyPotmeter; | |
412 mywidget->bitmap[0] = pngRead(skin, findnextstring(temp, desc, &base)); | |
413 mywidget->phases = atoi(findnextstring(temp, desc, &base)); | |
414 mywidget->value = atof(findnextstring(temp, desc, &base)); | |
415 mywidget->wx = mywidget->x = atoi(findnextstring(temp, desc, &base)); | |
416 mywidget->wy = mywidget->y = atoi(findnextstring(temp, desc, &base)); | |
417 mywidget->wwidth = mywidget->width = atoi(findnextstring(temp, desc, &base)); | |
418 mywidget->wheight = mywidget->height = atoi(findnextstring(temp, desc, &base)); | |
419 findnextstring(temp, desc, &base); | |
420 mywidget->msg = evNone; | |
421 for (i=0; i<evBoxs; i++) | |
422 { | |
423 if(!strcmp(temp, evNames[i].name)) | |
424 { | |
425 mywidget->msg=evNames[i].msg; | |
426 break; | |
427 } | |
428 } | |
429 #ifdef DEBUG | |
430 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [POTMETER] %s %i %i %i %f %i %i msg %i\n", | |
431 (mywidget->bitmap[0]) ? mywidget->bitmap[0]->name : NULL, | |
432 mywidget->width, mywidget->height, | |
433 mywidget->phases, mywidget->value, | |
434 mywidget->x, mywidget->y, | |
435 mywidget->msg); | |
436 #endif | |
437 } | |
438 else if(!strncmp(desc, "menu", 4)) | |
439 { | |
440 int base = counttonextchar(desc, '=') + 1; | |
441 int i; | |
442 mywidget->type = tyMenu; | |
443 mywidget->wx=atoi(findnextstring(temp, desc, &base)); | |
444 mywidget->x=0; | |
445 mywidget->wy=mywidget->y=atoi(findnextstring(temp, desc, &base)); | |
446 mywidget->wwidth=mywidget->width=atoi(findnextstring(temp, desc, &base)); | |
447 mywidget->wheight=mywidget->height=atoi(findnextstring(temp, desc, &base)); | |
448 findnextstring(temp, desc, &base); | |
449 mywidget->msg = evNone; | |
450 for (i=0; i<evBoxs; i++) | |
451 { | |
452 if(!strcmp(temp, evNames[i].name)) | |
453 { | |
454 mywidget->msg = evNames[i].msg; | |
455 break; | |
456 } | |
457 } | |
458 #ifdef DEBUG | |
459 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [MENU] %i %i %i %i msg %i\n", | |
460 mywidget->x, mywidget->y, mywidget->width, mywidget->height, mywidget->msg); | |
461 #endif | |
462 } | |
463 else if(!strncmp(desc, "selected", 8)) | |
464 { | |
465 win->base->bitmap[1] = pngRead(skin, (char *) desc + 9); | |
466 #ifdef DEBUG | |
467 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [BASE] added image %s\n", win->base->bitmap[1]->name); | |
468 #endif | |
469 } | |
470 else if(!strncmp(desc, "slabel",6)) | |
471 { | |
472 int base = counttonextchar(desc, '=') + 1; | |
473 unsigned int i; | |
474 mywidget->type = tySlabel; | |
475 mywidget->wx = mywidget->x = atoi(findnextstring(temp, desc, &base)); | |
476 mywidget->wy = mywidget->y = atoi(findnextstring(temp, desc, &base)); | |
477 findnextstring(temp, desc, &base); | |
478 mywidget->font = NULL; | |
479 for (i=0; i<skin->fontcount; i++) | |
480 { | |
481 if(!strcmp(temp, skin->fonts[i]->name)) | |
482 { | |
483 mywidget->font = skin->fonts[i]; | |
484 break; | |
485 } | |
486 } | |
487 mywidget->label = strdup(findnextstring(temp, desc, &base)); | |
488 #ifdef DEBUG | |
489 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [SLABEL] %i %i %s %s\n", | |
490 mywidget->x, mywidget->y, mywidget->font->name, mywidget->label); | |
491 #endif | |
492 } | |
493 else if(!strncmp(desc, "dlabel", 6)) | |
494 { | |
495 int base = counttonextchar(desc, '=') + 1; | |
496 unsigned int i; | |
497 mywidget->type = tyDlabel; | |
498 mywidget->wx = mywidget->x = atoi(findnextstring(temp, desc, &base)); | |
499 mywidget->wy = mywidget->y = atoi(findnextstring(temp, desc, &base)); | |
500 mywidget->length = atoi(findnextstring(temp, desc, &base)); | |
501 mywidget->align = atoi(findnextstring(temp, desc, &base)); | |
502 findnextstring(temp, desc, &base); | |
503 mywidget->font = NULL; | |
504 for (i=0; i<skin->fontcount; i++) | |
505 { | |
506 if(!strcmp(temp, skin->fonts[i]->name)) | |
507 { | |
508 mywidget->font=skin->fonts[i]; | |
509 break; | |
510 } | |
511 } | |
512 mywidget->label=strdup(findnextstring(temp, desc, &base)); | |
513 #ifdef DEBUG | |
514 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [ITEM] [DLABEL] %i %i %i %i %s \"%s\"\n", | |
515 mywidget->x, mywidget->y, mywidget->length, mywidget->align, mywidget->font->name, mywidget->label); | |
516 #endif | |
517 } | |
518 free(temp); | |
519 } | |
520 | |
521 static void loadfonts(skin_t* skin) | |
522 { | |
523 unsigned int x; | |
524 for (x=0; x<skin->fontcount; x++) | |
525 { | |
526 FILE *fp; | |
527 int linenumber=0; | |
528 char *filename; | |
529 char *tmp = calloc(1, MAX_LINESIZE); | |
530 char *desc = calloc(1, MAX_LINESIZE); | |
531 filename = calloc(1, strlen(skin->skindir) + strlen(skin->fonts[x]->name) + 6); | |
532 sprintf(filename, "%s\\%s.fnt", skin->skindir, skin->fonts[x]->name); | |
533 if(!(fp = fopen(filename,"rb"))) | |
534 { | |
535 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[FONT LOAD] Font not found \"%s\"\n", skin->fonts[x]->name); | |
536 return; | |
537 } | |
538 while(!feof(fp)) | |
539 { | |
540 int pos = 0; | |
541 unsigned int i; | |
542 fgets(tmp, MAX_LINESIZE, fp); | |
543 linenumber++; | |
544 memset(desc, 0, MAX_LINESIZE); | |
545 for (i=0; i<strlen(tmp); i++) | |
546 { | |
547 /* remove spaces and linebreaks */ | |
548 if((tmp[i] == ' ') || (tmp[i] == '\n') || (tmp[i] == '\r')) continue; | |
549 /* remove comments */ | |
550 if((tmp[i] == ';') && ((i < 1) || (tmp[i-1] != '\"'))) | |
551 { | |
552 #ifdef DEBUG | |
553 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[FONT LOAD] Comment: %s", tmp + i + 1); | |
554 #endif | |
555 break; | |
556 } | |
557 desc[pos] = tmp[i]; | |
558 pos++; | |
559 } | |
560 if(!strlen(desc)) continue; | |
561 /* now we have "readable" output -> parse it */ | |
562 if(!strncmp(desc, "image", 5)) | |
563 { | |
564 skin->fonts[x]->image = pngRead(skin, desc + 6); | |
565 #ifdef DEBUG | |
566 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[FONT] [IMAGE] \"%s\"\n", desc + 6); | |
567 #endif | |
568 } | |
569 else | |
570 { | |
571 int base = 4; | |
572 if(*desc != '"') break; | |
573 if(*(desc + 1) == 0) break; | |
574 (skin->fonts[x]->charcount)++; | |
575 skin->fonts[x]->chars = realloc(skin->fonts[x]->chars, sizeof(char_t *) *skin->fonts[x]->charcount); | |
576 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]=calloc(1, sizeof(char_t)); | |
577 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->c = ((*(desc + 1) == '"') && (*(desc + 2) != '"')) ? ' ': *(desc + 1); | |
578 if((*(desc + 1) == '"') && (*(desc + 2) != '"')) base = 3; | |
579 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->x = atoi(findnextstring(tmp, desc, &base)); | |
580 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->y = atoi(findnextstring(tmp, desc, &base)); | |
581 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->width = atoi(findnextstring(tmp, desc, &base)); | |
582 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->height = atoi(findnextstring(tmp, desc, &base)); | |
583 #ifdef DEBUG | |
584 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[FONT] [CHAR] %c %i %i %i %i\n", | |
585 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->c, | |
586 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->x, | |
587 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->y, | |
588 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->width, | |
589 skin->fonts[x]->chars[skin->fonts[x]->charcount - 1]->height); | |
590 #endif | |
591 } | |
592 } | |
593 free(desc); | |
594 free(filename); | |
595 free(tmp); | |
596 fclose(fp); | |
597 } | |
598 } | |
599 | |
600 skin_t* loadskin(char* skindir, int desktopbpp) | |
601 { | |
602 FILE *fp; | |
603 int reachedendofwindow = 0; | |
604 int linenumber = 0; | |
605 skin_t *skin = calloc(1, sizeof(skin_t)); | |
606 char *filename; | |
607 char *tmp = calloc(1, MAX_LINESIZE); | |
608 char *desc = calloc(1, MAX_LINESIZE); | |
609 window* mywindow = NULL; | |
610 | |
611 /* setup funcs */ | |
612 skin->freeskin = freeskin; | |
613 skin->pngRead = pngRead; | |
614 skin->addwidget = addwidget; | |
615 skin->removewidget = removewidget; | |
616 skin->geteventname = geteventname; | |
617 skin->desktopbpp = desktopbpp; | |
618 skin->skindir = strdup(skindir); | |
619 | |
620 filename = calloc(1, strlen(skin->skindir) + strlen("skin") + 2); | |
621 sprintf(filename, "%s\\skin", skin->skindir); | |
622 if(!(fp = fopen(filename, "rb"))) | |
623 { | |
624 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[SKIN LOAD] Skin \"%s\" not found\n", skindir); | |
625 skin->freeskin(skin); | |
626 return NULL; | |
627 } | |
628 | |
629 while(!feof(fp)) | |
630 { | |
631 int pos = 0; | |
632 unsigned int i; | |
633 int insidequote = 0; | |
634 fgets(tmp, MAX_LINESIZE, fp); | |
635 linenumber++; | |
636 memset(desc, 0, MAX_LINESIZE); | |
637 for (i=0; i<strlen(tmp); i++) | |
638 { | |
639 if((tmp[i] == '"') && !insidequote) { insidequote=1; continue; } | |
640 else if((tmp[i] == '"') && insidequote) { insidequote=0 ; continue; } | |
641 /* remove spaces and linebreaks */ | |
642 if((!insidequote && (tmp[i] == ' ')) || (tmp[i] == '\n') || (tmp[i] == '\r')) continue; | |
643 /* remove comments */ | |
644 else if(tmp[i] == ';') | |
645 { | |
646 #ifdef DEBUG | |
647 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN LOAD] Comment: %s", tmp + i + 1); | |
648 #endif | |
649 break; | |
650 } | |
651 desc[pos] = tmp[i]; | |
652 pos++; | |
653 } | |
654 | |
655 if(!strlen(desc)) continue; | |
656 /* now we have "readable" output -> parse it */ | |
657 /* parse window specific info */ | |
658 if(!strncmp(desc, "section", 7)) | |
659 { | |
660 #ifdef DEBUG | |
661 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [SECTION] \"%s\"\n", desc + 8); | |
662 #endif | |
663 } | |
664 else if(!strncmp(desc, "window", 6)) | |
665 { | |
666 #ifdef DEBUG | |
667 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [WINDOW] \"%s\"\n", desc + 7); | |
668 #endif | |
669 reachedendofwindow = 0; | |
670 (skin->windowcount)++; | |
671 skin->windows = realloc(skin->windows, sizeof(window *) * skin->windowcount); | |
672 mywindow = skin->windows[(skin->windowcount) - 1] = calloc(1, sizeof(window)); | |
673 mywindow->name = strdup(desc + 7); | |
674 if(!strncmp(desc + 7, "main", 4)) mywindow->type = wiMain; | |
675 else if(!strncmp(desc+7, "sub", 3)) | |
676 { | |
677 mywindow->type = wiSub; | |
678 mywindow->decoration = 1; | |
679 } | |
680 else if(!strncmp(desc + 7, "menu", 4)) mywindow->type = wiMenu; | |
681 else if(!strncmp(desc + 7, "playbar", 7)) mywindow->type = wiPlaybar; | |
682 else mp_msg(MSGT_GPLAYER, MSGL_V, "[SKIN] warning found unknown windowtype"); | |
683 } | |
684 else if(!strncmp(desc, "decoration", 10) && !strncmp(desc + 11, "enable", 6)) | |
685 { | |
686 mywindow->decoration = 1; | |
687 #ifdef DEBUG | |
688 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [DECORATION] enabled decoration for window \"%s\"\n", mywindow->name); | |
689 #endif | |
690 } | |
691 else if(!strncmp(desc, "background", 10)) | |
692 { | |
693 int base = counttonextchar(desc, '=') + 1; | |
694 char temp[MAX_LINESIZE]; | |
695 mywindow->backgroundcolor[0] = atoi(findnextstring(temp, desc, &base)); | |
696 mywindow->backgroundcolor[1] = atoi(findnextstring(temp, desc, &base)); | |
697 mywindow->backgroundcolor[2] = atoi(findnextstring(temp, desc, &base)); | |
698 #ifdef DEBUG | |
699 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [BACKGROUND] window \"%s\" has backgroundcolor (%i,%i,%i)\n", mywindow->name, | |
700 mywindow->backgroundcolor[0], | |
701 mywindow->backgroundcolor[1], | |
702 mywindow->backgroundcolor[2]); | |
703 #endif | |
704 } | |
705 else if(!strncmp(desc, "end", 3)) | |
706 { | |
707 if(reachedendofwindow) | |
708 { | |
709 #ifdef DEBUG | |
710 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [END] of section\n"); | |
711 #endif | |
712 } | |
713 else | |
714 { | |
715 reachedendofwindow = 1; | |
716 #ifdef DEBUG | |
717 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [END] of window \"%s\"\n", mywindow->name); | |
718 #endif | |
719 } | |
720 } | |
721 else if(!strncmp(desc, "font", 4)) | |
722 { | |
723 unsigned int i; | |
724 int id = 0; | |
725 char temp[MAX_LINESIZE]; | |
726 int base = counttonextchar(desc, '=')+1; | |
727 findnextstring(temp, desc, &base); | |
728 findnextstring(temp, desc, &base); | |
729 for (i=0; i<skin->fontcount; i++) | |
730 if(!strcmp(skin->fonts[i]->id, temp)) | |
731 { | |
732 id = i; | |
733 break; | |
734 } | |
735 if(!id) | |
736 { | |
737 int base = counttonextchar(desc, '=') + 1; | |
738 findnextstring(temp, desc, &base); | |
739 id = skin->fontcount; | |
740 (skin->fontcount)++; | |
741 skin->fonts = realloc(skin->fonts, sizeof(font_t *) * skin->fontcount); | |
742 skin->fonts[id]=calloc(1, sizeof(font_t)); | |
743 skin->fonts[id]->name = strdup(temp); | |
744 skin->fonts[id]->id = strdup(findnextstring(temp, desc, &base)); | |
745 } | |
746 #ifdef DEBUG | |
747 mp_msg(MSGT_GPLAYER, MSGL_DBG4, "[SKIN] [FONT] id \"%s\" name \"%s\"\n", skin->fonts[id]->name, skin->fonts[id]->id); | |
748 #endif | |
749 } | |
750 else | |
751 skin->addwidget(skin, mywindow, desc); | |
752 } | |
753 | |
754 free(desc); | |
755 free(filename); | |
756 free(tmp); | |
757 fclose(fp); | |
758 loadfonts(skin); | |
759 mp_msg(MSGT_GPLAYER, MSGL_V, "[SKIN LOAD] loaded skin \"%s\"\n", skin->skindir); | |
760 /* dumpwidgets(skin); */ | |
761 return skin; | |
762 } |