Mercurial > mplayer.hg
annotate gui/skin/skin.c @ 33053:f64d41dac10b
Cosmetic: Separate return statement with newline.
author | ib |
---|---|
date | Tue, 29 Mar 2011 08:53:07 +0000 |
parents | 956c67bb5198 |
children | ed66afc0b06c |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
23077 | 18 |
19 #include <stdio.h> | |
20 #include <string.h> | |
21 | |
32873 | 22 #include "skin.h" |
23077 | 23 #include "font.h" |
32893 | 24 #include "gui/app.h" |
33023 | 25 #include "gui/interface.h" |
32873 | 26 #include "gui/mplayer/widgets.h" |
33046 | 27 #include "gui/util/cut.h" |
33048 | 28 #include "gui/util/string.h" |
23077 | 29 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
30 #include "config.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
31 #include "help_mp.h" |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23077
diff
changeset
|
32 #include "libavutil/avstring.h" |
32944 | 33 #include "libavutil/common.h" |
32873 | 34 #include "mp_msg.h" |
23077 | 35 |
32873 | 36 typedef struct { |
37 const char *name; | |
38 int (*func)(char *in); | |
39 } _item; | |
23077 | 40 |
32937 | 41 static guiItems *skin; |
23077 | 42 |
32873 | 43 static int linenumber; |
44 static unsigned char path[512]; | |
23077 | 45 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
46 static unsigned char currWinName[32]; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
47 static wItem *currWin; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
48 static int *currWinItemIdx; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
49 static wItem *currWinItems; |
23077 | 50 |
33022 | 51 static void skin_error(const char *format, ...) |
23077 | 52 { |
32873 | 53 char p[512]; |
54 va_list ap; | |
55 | |
56 va_start(ap, format); | |
57 vsnprintf(p, sizeof(p), format, ap); | |
58 va_end(ap); | |
59 | |
33023 | 60 gmp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_ERRORMESSAGE, linenumber, p); |
23077 | 61 } |
62 | |
32873 | 63 #define CHECKDEFLIST(str) \ |
64 { \ | |
32937 | 65 if (skin == NULL) \ |
32873 | 66 { \ |
33022 | 67 skin_error(MSGTR_SKIN_ERROR_SECTION, str); \ |
32873 | 68 return 1; \ |
69 } \ | |
70 } | |
71 | |
72 #define CHECKWINLIST(str) \ | |
73 { \ | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
74 if (!currWinName[0]) \ |
32873 | 75 { \ |
33022 | 76 skin_error(MSGTR_SKIN_ERROR_WINDOW, str); \ |
32873 | 77 return 1; \ |
78 } \ | |
79 } | |
23077 | 80 |
32873 | 81 #define CHECK(name) \ |
82 { \ | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
83 if (!strcmp(currWinName, name)) \ |
32873 | 84 { \ |
33022 | 85 skin_error(MSGTR_SKIN_ERROR_IN_WINDOW, name); \ |
32873 | 86 return 1; \ |
87 } \ | |
88 } | |
89 | |
90 int skinBPRead(char *fname, txSample *bf) | |
91 { | |
92 int i = bpRead(fname, bf); | |
93 | |
94 switch (i) { | |
95 case -1: | |
33022 | 96 skin_error(MSGTR_SKIN_BITMAP_16bit, fname); |
32873 | 97 break; |
98 | |
99 case -2: | |
33022 | 100 skin_error(MSGTR_SKIN_BITMAP_FileNotFound, fname); |
32873 | 101 break; |
102 | |
103 case -3: | |
33022 | 104 skin_error(MSGTR_SKIN_BITMAP_BMPReadError, fname); |
32873 | 105 break; |
23077 | 106 |
32873 | 107 case -4: |
33022 | 108 skin_error(MSGTR_SKIN_BITMAP_TGAReadError, fname); |
32873 | 109 break; |
110 | |
111 case -5: | |
33022 | 112 skin_error(MSGTR_SKIN_BITMAP_PNGReadError, fname); |
32873 | 113 break; |
114 | |
115 case -6: | |
33022 | 116 skin_error(MSGTR_SKIN_BITMAP_RLENotSupported, fname); |
32873 | 117 break; |
118 | |
119 case -7: | |
33022 | 120 skin_error(MSGTR_SKIN_BITMAP_UnknownFileType, fname); |
32873 | 121 break; |
122 | |
123 case -8: | |
33022 | 124 skin_error(MSGTR_SKIN_BITMAP_ConversionError, fname); |
32873 | 125 break; |
126 } | |
127 | |
128 return i; | |
23077 | 129 } |
130 | |
32873 | 131 // section=movieplayer |
132 static int cmd_section(char *in) | |
23077 | 133 { |
32873 | 134 strlower(in); |
32937 | 135 skin = NULL; |
32873 | 136 |
137 if (!strcmp(in, "movieplayer")) | |
32937 | 138 skin = &appMPlayer; |
32873 | 139 |
32951 | 140 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] section: %s\n", in); |
32873 | 141 |
142 return 0; | |
23077 | 143 } |
144 | |
32873 | 145 // end |
146 static int cmd_end(char *in) | |
23077 | 147 { |
32958 | 148 #ifdef MP_DEBUG |
32951 | 149 char *space, *name; |
150 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
151 if (currWinName[0]) { |
32951 | 152 space = " "; |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
153 name = currWinName; |
32951 | 154 } else { |
155 space = ""; | |
156 name = "section"; | |
157 } | |
32958 | 158 #endif |
159 | |
160 (void)in; | |
32951 | 161 |
162 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %send (%s)\n", space, name); | |
163 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
164 if (currWinName[0]) { |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
165 currWinName[0] = 0; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
166 currWin = NULL; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
167 currWinItemIdx = NULL; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
168 currWinItems = NULL; |
32873 | 169 } else |
32937 | 170 skin = NULL; |
32873 | 171 |
172 return 0; | |
23077 | 173 } |
174 | |
32873 | 175 // window=main|sub|playbar|menu |
176 static int cmd_window(char *in) | |
23077 | 177 { |
32873 | 178 CHECKDEFLIST("window"); |
179 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
180 av_strlcpy(currWinName, strlower(in), sizeof(currWinName)); |
23077 | 181 |
32873 | 182 if (!strncmp(in, "main", 4)) { |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
183 currWin = &appMPlayer.main; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
184 currWinItemIdx = &appMPlayer.IndexOfMainItems; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
185 currWinItems = appMPlayer.mainItems; |
32873 | 186 } else if (!strncmp(in, "sub", 3)) |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
187 currWin = &appMPlayer.sub; |
32873 | 188 else if (!strncmp(in, "playbar", 7)) { |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
189 currWin = &appMPlayer.bar; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
190 currWinItemIdx = &appMPlayer.IndexOfBarItems; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
191 currWinItems = appMPlayer.barItems; |
32873 | 192 } else if (!strncmp(in, "menu", 4)) { |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
193 currWin = &appMPlayer.menuBase; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
194 currWinItemIdx = &appMPlayer.IndexOfMenuItems; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
195 currWinItems = appMPlayer.menuItems; |
32873 | 196 } else |
33022 | 197 skin_error(MSGTR_UNKNOWNWINDOWTYPE); |
32873 | 198 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
199 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] window: %s\n", currWinName); |
32873 | 200 |
201 return 0; | |
23077 | 202 } |
203 | |
32873 | 204 // base=image,x,y[,width,height] |
205 static int cmd_base(char *in) | |
23077 | 206 { |
32873 | 207 unsigned char fname[512]; |
208 unsigned char tmp[512]; | |
209 int x, y; | |
210 int sx = 0, sy = 0; | |
211 | |
212 CHECKDEFLIST("base"); | |
213 CHECKWINLIST("base"); | |
23077 | 214 |
32873 | 215 cutItem(in, fname, ',', 0); |
216 x = cutItemToInt(in, ',', 1); | |
217 y = cutItemToInt(in, ',', 2); | |
218 sx = cutItemToInt(in, ',', 3); | |
219 sy = cutItemToInt(in, ',', 4); | |
220 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
221 if (!strcmp(currWinName, "main")) { |
32951 | 222 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image: %s %d,%d\n", fname, x, y); |
23077 | 223 |
32937 | 224 skin->main.x = x; |
225 skin->main.y = y; | |
226 skin->main.type = itBase; | |
32873 | 227 |
228 av_strlcpy(tmp, path, sizeof(tmp)); | |
229 av_strlcat(tmp, fname, sizeof(tmp)); | |
230 | |
32937 | 231 if (skinBPRead(tmp, &skin->main.Bitmap) != 0) |
32873 | 232 return 1; |
233 | |
32937 | 234 skin->main.width = skin->main.Bitmap.Width; |
235 skin->main.height = skin->main.Bitmap.Height; | |
32873 | 236 |
32951 | 237 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", skin->main.width, skin->main.height); |
238 | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
239 #ifdef CONFIG_XSHAPE |
32937 | 240 Convert32to1(&skin->main.Bitmap, &skin->main.Mask, 0x00ff00ff); |
32951 | 241 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] mask: %lux%lu\n", skin->main.Mask.Width, skin->main.Mask.Height); |
23077 | 242 #else |
32937 | 243 skin->main.Mask.Image = NULL; |
23077 | 244 #endif |
245 } | |
32873 | 246 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
247 if (!strcmp(currWinName, "sub")) { |
32958 | 248 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image: %s %d,%d\n", fname, x, y); |
249 | |
32937 | 250 skin->sub.type = itBase; |
32873 | 251 |
252 av_strlcpy(tmp, path, sizeof(tmp)); | |
253 av_strlcat(tmp, fname, sizeof(tmp)); | |
254 | |
32937 | 255 if (skinBPRead(tmp, &skin->sub.Bitmap) != 0) |
32873 | 256 return 1; |
257 | |
32937 | 258 skin->sub.x = x; |
259 skin->sub.y = y; | |
260 skin->sub.width = skin->sub.Bitmap.Width; | |
261 skin->sub.height = skin->sub.Bitmap.Height; | |
32873 | 262 |
263 if (sx && sy) { | |
32937 | 264 skin->sub.width = sx; |
265 skin->sub.height = sy; | |
32873 | 266 } |
267 | |
32951 | 268 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", skin->sub.width, skin->sub.height); |
32873 | 269 } |
270 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
271 if (!strcmp(currWinName, "menu")) { |
32958 | 272 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image: %s\n", fname); |
273 | |
32937 | 274 skin->menuIsPresent = 1; |
275 skin->menuBase.type = itBase; | |
32873 | 276 |
277 av_strlcpy(tmp, path, sizeof(tmp)); | |
278 av_strlcat(tmp, fname, sizeof(tmp)); | |
279 | |
32937 | 280 if (skinBPRead(tmp, &skin->menuBase.Bitmap) != 0) |
32873 | 281 return 1; |
282 | |
32937 | 283 skin->menuBase.width = skin->menuBase.Bitmap.Width; |
284 skin->menuBase.height = skin->menuBase.Bitmap.Height; | |
32873 | 285 |
32951 | 286 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", skin->menuBase.width, skin->menuBase.height); |
287 | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
288 #ifdef CONFIG_XSHAPE |
32937 | 289 Convert32to1(&skin->menuBase.Bitmap, &skin->menuBase.Mask, 0x00ff00ff); |
32951 | 290 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] mask: %lux%lu\n", skin->menuBase.Mask.Width, skin->menuBase.Mask.Height); |
23077 | 291 #else |
32937 | 292 skin->menuBase.Mask.Image = NULL; |
23077 | 293 #endif |
32873 | 294 } |
295 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
296 if (!strcmp(currWinName, "playbar")) { |
32958 | 297 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image: %s %d,%d\n", fname, x, y); |
298 | |
32937 | 299 skin->barIsPresent = 1; |
300 skin->bar.x = x; | |
301 skin->bar.y = y; | |
302 skin->bar.type = itBase; | |
32873 | 303 |
304 av_strlcpy(tmp, path, sizeof(tmp)); | |
305 av_strlcat(tmp, fname, sizeof(tmp)); | |
306 | |
32937 | 307 if (skinBPRead(tmp, &skin->bar.Bitmap) != 0) |
32873 | 308 return 1; |
309 | |
32937 | 310 skin->bar.width = skin->bar.Bitmap.Width; |
311 skin->bar.height = skin->bar.Bitmap.Height; | |
32873 | 312 |
32951 | 313 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", skin->bar.width, skin->bar.height); |
314 | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
315 #ifdef CONFIG_XSHAPE |
32937 | 316 Convert32to1(&skin->bar.Bitmap, &skin->bar.Mask, 0x00ff00ff); |
32951 | 317 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] mask: %lux%lu\n", skin->bar.Mask.Width, skin->bar.Mask.Height); |
23077 | 318 #else |
32937 | 319 skin->bar.Mask.Image = NULL; |
23077 | 320 #endif |
32873 | 321 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
322 |
32873 | 323 return 0; |
23077 | 324 } |
325 | |
32873 | 326 // background=R,G,B |
327 static int cmd_background(char *in) | |
23077 | 328 { |
32873 | 329 CHECKDEFLIST("background"); |
330 CHECKWINLIST("background"); | |
23077 | 331 |
32873 | 332 CHECK("menu"); |
333 CHECK("main"); | |
23077 | 334 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
335 currWin->R = cutItemToInt(in, ',', 0); |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
336 currWin->G = cutItemToInt(in, ',', 1); |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
337 currWin->B = cutItemToInt(in, ',', 2); |
23077 | 338 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
339 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] background color: #%02x%02x%02x\n", currWin->R, currWin->G, currWin->B); |
23077 | 340 |
32873 | 341 return 0; |
23077 | 342 } |
343 | |
32873 | 344 // button=image,x,y,width,height,message |
345 static int cmd_button(char *in) | |
23077 | 346 { |
32873 | 347 unsigned char fname[512]; |
348 unsigned char tmp[512]; | |
349 int x, y, sx, sy; | |
350 char msg[32]; | |
351 | |
352 CHECKDEFLIST("button"); | |
353 CHECKWINLIST("button"); | |
354 | |
355 CHECK("sub"); | |
356 CHECK("menu"); | |
23077 | 357 |
32873 | 358 cutItem(in, fname, ',', 0); |
359 x = cutItemToInt(in, ',', 1); | |
360 y = cutItemToInt(in, ',', 2); | |
361 sx = cutItemToInt(in, ',', 3); | |
362 sy = cutItemToInt(in, ',', 4); | |
363 cutItem(in, msg, ',', 5); | |
364 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
365 (*currWinItemIdx)++; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
366 currWinItems[*currWinItemIdx].type = itButton; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
367 currWinItems[*currWinItemIdx].x = x; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
368 currWinItems[*currWinItemIdx].y = y; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
369 currWinItems[*currWinItemIdx].width = sx; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
370 currWinItems[*currWinItemIdx].height = sy; |
23077 | 371 |
32951 | 372 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] button image: %s %d,%d\n", fname, x, y); |
32873 | 373 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
374 if ((currWinItems[*currWinItemIdx].message = appFindMessage(msg)) == -1) { |
33022 | 375 skin_error(MSGTR_SKIN_BITMAP_UnknownMessage, msg); |
32873 | 376 return 0; |
377 } | |
378 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
379 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", msg, currWinItems[*currWinItemIdx].message); |
32951 | 380 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] size: %dx%d\n", sx, sy); |
381 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
382 currWinItems[*currWinItemIdx].pressed = btnReleased; |
32873 | 383 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
384 if (currWinItems[*currWinItemIdx].message == evPauseSwitchToPlay) |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
385 currWinItems[*currWinItemIdx].pressed = btnDisabled; |
23077 | 386 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
387 currWinItems[*currWinItemIdx].tmp = 1; |
32873 | 388 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
389 currWinItems[*currWinItemIdx].Bitmap.Image = NULL; |
32873 | 390 |
391 if (strcmp(fname, "NULL") != 0) { | |
392 av_strlcpy(tmp, path, sizeof(tmp)); | |
393 av_strlcat(tmp, fname, sizeof(tmp)); | |
394 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
395 if (skinBPRead(tmp, &currWinItems[*currWinItemIdx].Bitmap) != 0) |
32873 | 396 return 1; |
32951 | 397 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
398 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (bitmap: %lux%lu)\n", currWinItems[*currWinItemIdx].Bitmap.Width, currWinItems[*currWinItemIdx].Bitmap.Height); |
32873 | 399 } |
400 | |
401 return 0; | |
23077 | 402 } |
403 | |
32873 | 404 // selected=image |
405 static int cmd_selected(char *in) | |
406 { | |
407 unsigned char fname[512]; | |
408 unsigned char tmp[512]; | |
409 | |
410 CHECKDEFLIST("selected"); | |
411 CHECKWINLIST("selected"); | |
412 | |
413 CHECK("main"); | |
414 CHECK("sub"); | |
415 CHECK("playbar"); | |
416 | |
417 cutItem(in, fname, ',', 0); | |
23077 | 418 |
32937 | 419 skin->menuSelected.type = itBase; |
32873 | 420 |
421 av_strlcpy(tmp, path, sizeof(tmp)); | |
422 av_strlcat(tmp, fname, sizeof(tmp)); | |
423 | |
32951 | 424 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image selected: %s\n", fname); |
23077 | 425 |
32937 | 426 if (skinBPRead(tmp, &skin->menuSelected.Bitmap) != 0) |
32873 | 427 return 1; |
428 | |
32937 | 429 skin->menuSelected.width = skin->menuSelected.Bitmap.Width; |
430 skin->menuSelected.height = skin->menuSelected.Bitmap.Height; | |
32873 | 431 |
32951 | 432 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", skin->menuSelected.width, skin->menuSelected.height); |
32873 | 433 |
434 return 0; | |
435 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
436 |
32873 | 437 // menu=x,y,width,height,message |
438 static int cmd_menu(char *in) | |
439 { | |
32911 | 440 int x, y, sx, sy, message; |
32873 | 441 unsigned char tmp[64]; |
442 | |
443 CHECKDEFLIST("menu"); | |
444 CHECKWINLIST("menu"); | |
445 | |
446 CHECK("main"); | |
447 CHECK("sub"); | |
448 CHECK("playbar"); | |
449 | |
450 x = cutItemToInt(in, ',', 0); | |
451 y = cutItemToInt(in, ',', 1); | |
452 sx = cutItemToInt(in, ',', 2); | |
453 sy = cutItemToInt(in, ',', 3); | |
454 cutItem(in, tmp, ',', 4); | |
23077 | 455 |
32911 | 456 message = appFindMessage(tmp); |
32873 | 457 |
32937 | 458 skin->IndexOfMenuItems++; |
459 skin->menuItems[skin->IndexOfMenuItems].x = x; | |
460 skin->menuItems[skin->IndexOfMenuItems].y = y; | |
461 skin->menuItems[skin->IndexOfMenuItems].width = sx; | |
462 skin->menuItems[skin->IndexOfMenuItems].height = sy; | |
23077 | 463 |
32951 | 464 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] item #%d: %d,%d %dx%d\n", skin->IndexOfMenuItems, x, y, sx, sy); |
23077 | 465 |
32937 | 466 if ((skin->menuItems[skin->IndexOfMenuItems].message = message) == -1) |
33022 | 467 skin_error(MSGTR_SKIN_BITMAP_UnknownMessage, tmp); |
23077 | 468 |
32951 | 469 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", tmp, skin->menuItems[skin->IndexOfMenuItems].message); |
23077 | 470 |
32937 | 471 skin->menuItems[skin->IndexOfMenuItems].Bitmap.Image = NULL; |
33053 | 472 |
32873 | 473 return 0; |
23077 | 474 } |
475 | |
32873 | 476 // hpotmeter=button,bwidth,bheight,phases,numphases,default,x,y,width,height,message |
477 static int cmd_hpotmeter(char *in) | |
478 { | |
32911 | 479 int x, y, pwidth, pheight, ph, sx, sy, message, d; |
32873 | 480 unsigned char tmp[512]; |
481 unsigned char pfname[512]; | |
482 unsigned char phfname[512]; | |
483 wItem *item; | |
23077 | 484 |
32873 | 485 CHECKDEFLIST("hpotmeter"); |
486 CHECKWINLIST("hpotmeter"); | |
23077 | 487 |
32873 | 488 CHECK("sub"); |
489 CHECK("menu"); | |
23077 | 490 |
32873 | 491 cutItem(in, pfname, ',', 0); |
32911 | 492 pwidth = cutItemToInt(in, ',', 1); |
493 pheight = cutItemToInt(in, ',', 2); | |
32873 | 494 cutItem(in, phfname, ',', 3); |
495 ph = cutItemToInt(in, ',', 4); | |
496 d = cutItemToInt(in, ',', 5); | |
497 x = cutItemToInt(in, ',', 6); | |
498 y = cutItemToInt(in, ',', 7); | |
499 sx = cutItemToInt(in, ',', 8); | |
500 sy = cutItemToInt(in, ',', 9); | |
501 cutItem(in, tmp, ',', 10); | |
502 | |
32911 | 503 message = appFindMessage(tmp); |
23077 | 504 |
32951 | 505 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] h/v potmeter image: %s %d,%d %dx%d\n", phfname, x, y, sx, sy); |
506 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] button image: %s %dx%d\n", pfname, pwidth, pheight); | |
507 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] numphases: %d, default: %d%%\n", ph, d); | |
508 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", tmp, message); | |
23077 | 509 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
510 (*currWinItemIdx)++; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
511 item = &currWinItems[*currWinItemIdx]; |
32873 | 512 item->type = itHPotmeter; |
513 item->x = x; | |
514 item->y = y; | |
515 item->width = sx; | |
516 item->height = sy; | |
32911 | 517 item->numphases = ph; |
518 item->pwidth = pwidth; | |
519 item->pheight = pheight; | |
520 item->message = message; | |
32873 | 521 item->value = (float)d; |
522 item->pressed = btnReleased; | |
523 item->Bitmap.Image = NULL; | |
23077 | 524 |
32873 | 525 if (strcmp(phfname, "NULL") != 0) { |
526 av_strlcpy(tmp, path, sizeof(tmp)); | |
527 av_strlcat(tmp, phfname, sizeof(tmp)); | |
528 | |
529 if (skinBPRead(tmp, &item->Bitmap) != 0) | |
530 return 1; | |
32951 | 531 |
532 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (potmeter bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); | |
32873 | 533 } |
534 | |
535 item->Mask.Image = NULL; | |
23077 | 536 |
32873 | 537 if (strcmp(pfname, "NULL") != 0) { |
538 av_strlcpy(tmp, path, sizeof(tmp)); | |
539 av_strlcat(tmp, pfname, sizeof(tmp)); | |
540 | |
541 if (skinBPRead(tmp, &item->Mask) != 0) | |
542 return 1; | |
32951 | 543 |
544 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (button bitmap: %lux%lu)\n", item->Mask.Width, item->Mask.Height); | |
32873 | 545 } |
546 | |
547 return 0; | |
23077 | 548 } |
549 | |
32873 | 550 // vpotmeter=button,bwidth,bheight,phases,numphases,default,x,y,width,height,message |
551 static int cmd_vpotmeter(char *in) | |
23077 | 552 { |
32873 | 553 int r = cmd_hpotmeter(in); |
554 wItem *item; | |
23077 | 555 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
556 item = &currWinItems[*currWinItemIdx]; |
32873 | 557 item->type = itVPotmeter; |
33053 | 558 |
32873 | 559 return r; |
23077 | 560 } |
561 | |
32873 | 562 // potmeter=phases,numphases,default,x,y,width,height,message |
563 static int cmd_potmeter(char *in) | |
564 { | |
32911 | 565 int x, y, ph, sx, sy, message, d; |
32873 | 566 unsigned char tmp[512]; |
567 unsigned char phfname[512]; | |
568 wItem *item; | |
23077 | 569 |
32873 | 570 CHECKDEFLIST("potmeter"); |
571 CHECKWINLIST("potmeter"); | |
23077 | 572 |
32873 | 573 CHECK("sub"); |
574 CHECK("menu"); | |
23077 | 575 |
32873 | 576 cutItem(in, phfname, ',', 0); |
577 ph = cutItemToInt(in, ',', 1); | |
578 d = cutItemToInt(in, ',', 2); | |
579 x = cutItemToInt(in, ',', 3); | |
580 y = cutItemToInt(in, ',', 4); | |
581 sx = cutItemToInt(in, ',', 5); | |
582 sy = cutItemToInt(in, ',', 6); | |
583 cutItem(in, tmp, ',', 7); | |
584 | |
32911 | 585 message = appFindMessage(tmp); |
23077 | 586 |
32951 | 587 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] potmeter image: %s %d,%d %dx%d\n", phfname, x, y, sx, sy); |
588 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] numphases: %d, default: %d%%\n", ph, d); | |
589 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", tmp, message); | |
23077 | 590 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
591 (*currWinItemIdx)++; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
592 item = &currWinItems[*currWinItemIdx]; |
32873 | 593 item->type = itPotmeter; |
594 item->x = x; | |
595 item->y = y; | |
596 item->width = sx; | |
597 item->height = sy; | |
32911 | 598 item->numphases = ph; |
599 item->message = message; | |
32873 | 600 item->value = (float)d; |
601 item->Bitmap.Image = NULL; | |
23077 | 602 |
32873 | 603 if (strcmp(phfname, "NULL") != 0) { |
604 av_strlcpy(tmp, path, sizeof(tmp)); | |
605 av_strlcat(tmp, phfname, sizeof(tmp)); | |
606 | |
607 if (skinBPRead(tmp, &item->Bitmap) != 0) | |
608 return 1; | |
32951 | 609 |
610 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); | |
32873 | 611 } |
612 | |
613 return 0; | |
23077 | 614 } |
615 | |
32873 | 616 // font=fontfile |
617 static int cmd_font(char *in) | |
618 { | |
619 char name[512]; | |
620 wItem *item; | |
23077 | 621 |
32873 | 622 CHECKDEFLIST("font"); |
623 CHECKWINLIST("font"); | |
23077 | 624 |
32873 | 625 CHECK("sub"); |
626 CHECK("menu"); | |
23077 | 627 |
32873 | 628 cutItem(in, name, ',', 0); |
629 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
630 (*currWinItemIdx)++; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
631 item = &currWinItems[*currWinItemIdx]; |
32873 | 632 item->type = itFont; |
633 item->fontid = fntRead(path, name); | |
23077 | 634 |
32873 | 635 switch (item->fontid) { |
636 case -1: | |
33022 | 637 skin_error(MSGTR_SKIN_FONT_NotEnoughtMemory); |
32873 | 638 return 1; |
23077 | 639 |
32873 | 640 case -2: |
33022 | 641 skin_error(MSGTR_SKIN_FONT_TooManyFontsDeclared); |
32873 | 642 return 1; |
643 | |
644 case -3: | |
33022 | 645 skin_error(MSGTR_SKIN_FONT_FontFileNotFound); |
32873 | 646 return 1; |
647 | |
648 case -4: | |
33022 | 649 skin_error(MSGTR_SKIN_FONT_FontImageNotFound); |
32873 | 650 return 1; |
651 } | |
652 | |
32951 | 653 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", name, fntFindID(name)); |
654 | |
32873 | 655 return 0; |
23077 | 656 } |
657 | |
32873 | 658 // slabel=x,y,fontfile,"text" |
659 static int cmd_slabel(char *in) | |
23077 | 660 { |
32873 | 661 char tmp[512]; |
662 char sid[64]; | |
663 int x, y, id; | |
664 wItem *item; | |
665 | |
666 CHECKDEFLIST("slabel"); | |
667 CHECKWINLIST("slabel"); | |
23077 | 668 |
32873 | 669 CHECK("sub"); |
670 CHECK("menu"); | |
671 | |
672 x = cutItemToInt(in, ',', 0); | |
673 y = cutItemToInt(in, ',', 1); | |
674 cutItem(in, sid, ',', 2); | |
32951 | 675 cutItem(in, tmp, ',', 3); |
676 cutItem(tmp, tmp, '"', 1); | |
677 | |
678 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] slabel: \"%s\"\n", tmp); | |
679 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] pos: %d,%d\n", x, y); | |
23077 | 680 |
32873 | 681 id = fntFindID(sid); |
23077 | 682 |
32873 | 683 if (id < 0) { |
33022 | 684 skin_error(MSGTR_SKIN_FONT_NonExistentFontID, sid); |
32873 | 685 return 1; |
686 } | |
23077 | 687 |
32951 | 688 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", sid, id); |
23077 | 689 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
690 (*currWinItemIdx)++; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
691 item = &currWinItems[*currWinItemIdx]; |
32873 | 692 item->type = itSLabel; |
693 item->fontid = id; | |
694 item->x = x; | |
695 item->y = y; | |
696 item->width = -1; | |
697 item->height = -1; | |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
698 item->label = strdup(tmp); |
23077 | 699 |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
700 if (!item->label) { |
33022 | 701 skin_error(MSGTR_SKIN_FONT_NotEnoughtMemory); |
32873 | 702 return 1; |
703 } | |
23077 | 704 |
32873 | 705 return 0; |
23077 | 706 } |
707 | |
32910 | 708 // dlabel=x,y,width,align,fontfile,"text" |
32873 | 709 static int cmd_dlabel(char *in) |
710 { | |
711 char tmp[512]; | |
712 char sid[64]; | |
713 int x, y, sx, id, a; | |
714 wItem *item; | |
23077 | 715 |
32873 | 716 CHECKDEFLIST("dlabel"); |
717 CHECKWINLIST("dlabel"); | |
23077 | 718 |
32873 | 719 CHECK("sub"); |
720 CHECK("menu"); | |
721 | |
722 x = cutItemToInt(in, ',', 0); | |
723 y = cutItemToInt(in, ',', 1); | |
724 sx = cutItemToInt(in, ',', 2); | |
725 a = cutItemToInt(in, ',', 3); | |
726 cutItem(in, sid, ',', 4); | |
32951 | 727 cutItem(in, tmp, ',', 5); |
728 cutItem(tmp, tmp, '"', 1); | |
729 | |
730 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] dlabel: \"%s\"\n", tmp); | |
731 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] pos: %d,%d\n", x, y); | |
732 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] width: %d, align: %d\n", sx, a); | |
23077 | 733 |
32873 | 734 id = fntFindID(sid); |
23077 | 735 |
32873 | 736 if (id < 0) { |
33022 | 737 skin_error(MSGTR_SKIN_FONT_NonExistentFontID, sid); |
32873 | 738 return 1; |
739 } | |
23077 | 740 |
32951 | 741 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", sid, id); |
23077 | 742 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
743 (*currWinItemIdx)++; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
744 item = &currWinItems[*currWinItemIdx]; |
32873 | 745 item->type = itDLabel; |
746 item->fontid = id; | |
747 item->align = a; | |
748 item->x = x; | |
749 item->y = y; | |
750 item->width = sx; | |
751 item->height = -1; | |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
752 item->label = strdup(tmp); |
23077 | 753 |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
754 if (!item->label) { |
33022 | 755 skin_error(MSGTR_SKIN_FONT_NotEnoughtMemory); |
32873 | 756 return 1; |
757 } | |
23077 | 758 |
32873 | 759 return 0; |
23077 | 760 } |
761 | |
32873 | 762 // decoration=enable|disable |
763 static int cmd_decoration(char *in) | |
23077 | 764 { |
32873 | 765 char tmp[512]; |
766 | |
767 CHECKDEFLIST("decoration"); | |
768 CHECKWINLIST("decoration"); | |
769 | |
770 CHECK("sub"); | |
771 CHECK("menu"); | |
772 CHECK("playbar"); | |
773 | |
774 strlower(in); | |
775 cutItem(in, tmp, ',', 0); | |
776 | |
777 if (strcmp(tmp, "enable") != 0 && strcmp(tmp, "disable") != 0) { | |
33022 | 778 skin_error(MSGTR_SKIN_UnknownParameter, tmp); |
32873 | 779 return 1; |
780 } | |
23077 | 781 |
32873 | 782 if (strcmp(tmp, "enable") != 0) |
32937 | 783 skin->mainDecoration = 0; |
32873 | 784 else |
32937 | 785 skin->mainDecoration = 1; |
23077 | 786 |
32951 | 787 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] decoration: %s\n", tmp); |
32873 | 788 |
789 return 0; | |
23077 | 790 } |
791 | |
32878 | 792 static _item skinItem[] = { |
32873 | 793 { "section", cmd_section }, |
794 { "end", cmd_end }, | |
795 { "window", cmd_window }, | |
796 { "base", cmd_base }, | |
797 { "button", cmd_button }, | |
798 { "selected", cmd_selected }, | |
799 { "background", cmd_background }, | |
800 { "vpotmeter", cmd_vpotmeter }, | |
801 { "hpotmeter", cmd_hpotmeter }, | |
802 { "potmeter", cmd_potmeter }, | |
803 { "font", cmd_font }, | |
804 { "slabel", cmd_slabel }, | |
805 { "dlabel", cmd_dlabel }, | |
806 { "decoration", cmd_decoration }, | |
807 { "menu", cmd_menu } | |
808 }; | |
809 | |
810 static char *setname(char *item1, char *item2) | |
811 { | |
812 static char fn[512]; | |
813 | |
814 av_strlcpy(fn, item1, sizeof(fn)); | |
815 av_strlcat(fn, "/", sizeof(fn)); | |
816 av_strlcat(fn, item2, sizeof(fn)); | |
817 av_strlcpy(path, fn, sizeof(path)); | |
818 av_strlcat(path, "/", sizeof(path)); | |
819 av_strlcat(fn, "/skin", sizeof(fn)); | |
820 | |
821 return fn; | |
23077 | 822 } |
823 | |
32873 | 824 int skinRead(char *dname) |
23077 | 825 { |
32873 | 826 char *fn; |
827 FILE *skinFile; | |
828 unsigned char tmp[256]; | |
829 unsigned char *ptmp; | |
830 unsigned char command[32]; | |
831 unsigned char param[256]; | |
32944 | 832 unsigned int i; |
32873 | 833 |
834 fn = setname(skinDirInHome, dname); | |
23077 | 835 |
32873 | 836 if ((skinFile = fopen(fn, "rt")) == NULL) { |
837 fn = setname(skinMPlayerDir, dname); | |
838 | |
839 if ((skinFile = fopen(fn, "rt")) == NULL) { | |
32877 | 840 mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_SkinFileNotFound, fn); |
32873 | 841 return -1; |
842 } | |
23077 | 843 } |
32873 | 844 |
32951 | 845 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] configuration file: %s\n", fn); |
23077 | 846 |
32932 | 847 appFreeStruct(); |
23077 | 848 |
32873 | 849 linenumber = 0; |
23077 | 850 |
32873 | 851 while (fgets(tmp, sizeof(tmp), skinFile)) { |
852 linenumber++; | |
853 | |
854 tmp[strcspn(tmp, "\n\r")] = 0; // remove any kind of newline, if any | |
855 strswap(tmp, '\t', ' '); | |
856 trim(tmp); | |
857 ptmp = strchr(tmp, ';'); | |
858 | |
859 if (ptmp) | |
860 *ptmp = 0; | |
861 | |
862 if (!*tmp) | |
863 continue; | |
23077 | 864 |
32873 | 865 cutItem(tmp, command, '=', 0); |
866 cutItem(tmp, param, '=', 1); | |
867 strlower(command); | |
868 | |
32944 | 869 for (i = 0; i < FF_ARRAY_ELEMS(skinItem); i++) |
32873 | 870 if (!strcmp(command, skinItem[i].name)) |
871 if (skinItem[i].func(param) != 0) | |
872 return -2; | |
873 } | |
874 | |
875 if (linenumber == 0) { | |
32877 | 876 mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_SkinFileNotReadable, fn); |
32873 | 877 return -1; |
878 } | |
879 | |
880 return 0; | |
23077 | 881 } |