annotate gui/win32/skinload.c @ 31771:75398f13e9f6

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