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