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