Mercurial > mplayer.hg
annotate gui/skin/skin.c @ 34121:fbfde63a7e82
Fix include condition.
Don't explicitly list the sytems that need the windows.h header file.
Only OS/2 doesn't need it.
author | ib |
---|---|
date | Mon, 17 Oct 2011 10:46:38 +0000 |
parents | d99f341d8442 |
children | 251018f5254b |
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 |
33968 | 19 /** |
20 * @file | |
21 * @brief Skin parser | |
22 */ | |
23 | |
23077 | 24 #include <stdio.h> |
25 #include <string.h> | |
26 | |
32873 | 27 #include "skin.h" |
23077 | 28 #include "font.h" |
32893 | 29 #include "gui/app.h" |
33023 | 30 #include "gui/interface.h" |
33556 | 31 #include "gui/ui/widgets.h" |
33046 | 32 #include "gui/util/cut.h" |
33048 | 33 #include "gui/util/string.h" |
23077 | 34 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
35 #include "config.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
36 #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
|
37 #include "libavutil/avstring.h" |
32944 | 38 #include "libavutil/common.h" |
32873 | 39 #include "mp_msg.h" |
23077 | 40 |
32873 | 41 typedef struct { |
42 const char *name; | |
43 int (*func)(char *in); | |
44 } _item; | |
23077 | 45 |
33749 | 46 char *skinDirInHome; |
47 char *skinMPlayerDir; | |
48 | |
32937 | 49 static guiItems *skin; |
23077 | 50 |
32873 | 51 static int linenumber; |
52 static unsigned char path[512]; | |
23077 | 53 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
54 static unsigned char currWinName[32]; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
55 static wItem *currWin; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
56 static int *currWinItemIdx; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
57 static wItem *currWinItems; |
23077 | 58 |
33968 | 59 /** |
60 * @brief Display a skin error message. | |
61 * | |
62 * @param format format string | |
63 * @param ... arguments | |
64 */ | |
33022 | 65 static void skin_error(const char *format, ...) |
23077 | 66 { |
32873 | 67 char p[512]; |
68 va_list ap; | |
69 | |
70 va_start(ap, format); | |
71 vsnprintf(p, sizeof(p), format, ap); | |
72 va_end(ap); | |
73 | |
33023 | 74 gmp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_ERRORMESSAGE, linenumber, p); |
23077 | 75 } |
76 | |
33968 | 77 /** |
78 * @brief Check whether a @a section definition has started. | |
79 * | |
80 * @param item name of the item to be put in a message in case of an error | |
81 * | |
82 * @return 1 (ok) or 0 (error) | |
83 */ | |
33106 | 84 static int section_item(char *item) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
85 { |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
86 if (!skin) { |
33106 | 87 skin_error(MSGTR_SKIN_ERROR_SECTION, item); |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
88 return 0; |
32873 | 89 } |
90 | |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
91 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
92 } |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
93 |
33968 | 94 /** |
95 * @brief Check whether a @a window definition has started. | |
96 * | |
97 * @param item name of the item to be put in a message in case of an error | |
98 * | |
99 * @return 1 (ok) or 0 (error) | |
100 */ | |
33106 | 101 static int window_item(char *item) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
102 { |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
103 if (!currWinName[0]) { |
33106 | 104 skin_error(MSGTR_SKIN_ERROR_WINDOW, item); |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
105 return 0; |
32873 | 106 } |
23077 | 107 |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
108 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
109 } |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
110 |
33968 | 111 /** |
112 * @brief Check whether a specific @a window definition has started. | |
113 * | |
114 * @param name name of the window to be checked | |
115 * | |
116 * @return 0 (ok) or 1 (error) | |
117 */ | |
33058 | 118 static int in_window(char *name) |
119 { | |
120 if (strcmp(currWinName, name) == 0) { | |
33062 | 121 skin_error(MSGTR_SKIN_ERROR_ITEM, name); |
33058 | 122 return 1; |
32873 | 123 } |
124 | |
33058 | 125 return 0; |
126 } | |
127 | |
33968 | 128 /** |
129 * @brief Read a skin @a image file. | |
130 * | |
131 * @param fname filename (with path) | |
33972
91882b432024
Cosmetic: Rename skinImageRead() parameter bf img in doxygen comment.
ib
parents:
33969
diff
changeset
|
132 * @param img pointer suitable to store the image data |
33968 | 133 * |
134 * @return return code of #bpRead() | |
135 */ | |
33969 | 136 int skinImageRead(char *fname, guiImage *img) |
32873 | 137 { |
33969 | 138 int i = bpRead(fname, img); |
32873 | 139 |
140 switch (i) { | |
141 case -1: | |
33022 | 142 skin_error(MSGTR_SKIN_BITMAP_16bit, fname); |
32873 | 143 break; |
144 | |
145 case -2: | |
33022 | 146 skin_error(MSGTR_SKIN_BITMAP_FileNotFound, fname); |
32873 | 147 break; |
148 | |
149 case -5: | |
33022 | 150 skin_error(MSGTR_SKIN_BITMAP_PNGReadError, fname); |
32873 | 151 break; |
152 | |
153 case -8: | |
33022 | 154 skin_error(MSGTR_SKIN_BITMAP_ConversionError, fname); |
32873 | 155 break; |
156 } | |
157 | |
158 return i; | |
23077 | 159 } |
160 | |
33968 | 161 /** |
162 * @brief Get next free item in current @a window. | |
163 * | |
164 * @return pointer to next free item (ok) or NULL (error) | |
165 */ | |
33098 | 166 static wItem *next_item(void) |
167 { | |
168 wItem *item = NULL; | |
169 | |
170 if (*currWinItemIdx < MAX_ITEMS - 1) { | |
171 (*currWinItemIdx)++; | |
172 item = &currWinItems[*currWinItemIdx]; | |
173 } else | |
174 skin_error(MSGTR_SKIN_TooManyItemsDeclared); | |
175 | |
176 return item; | |
177 } | |
178 | |
33968 | 179 /** |
180 * @brief Parse a @a section definition. | |
181 * | |
182 * Syntax: section=movieplayer | |
183 * | |
184 * @param in definition to be analyzed | |
185 * | |
186 * @return 0 (ok) or 1 (error) | |
187 */ | |
33106 | 188 static int item_section(char *in) |
23077 | 189 { |
33064 | 190 if (skin) { |
191 skin_error(MSGTR_SKIN_ERROR_ITEM, "section"); | |
192 return 1; | |
193 } | |
194 | |
33055 | 195 if (!strcmp(strlower(in), "movieplayer")) |
33555 | 196 skin = &guiApp; |
33067 | 197 else { |
198 skin_error(MSGTR_SKIN_UNKNOWN_NAME, in); | |
199 return 1; | |
200 } | |
32873 | 201 |
33985 | 202 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] section: %s\n", in); |
32873 | 203 |
204 return 0; | |
23077 | 205 } |
206 | |
33968 | 207 /** |
208 * @brief Parse an @a end definition. | |
209 * | |
210 * Syntax: end | |
211 * | |
212 * @param in definition to be analyzed | |
213 * | |
214 * @return 0 (ok) or 1 (error) | |
215 */ | |
33106 | 216 static int item_end(char *in) |
23077 | 217 { |
32951 | 218 char *space, *name; |
219 | |
33985 | 220 (void)in; |
221 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
222 if (currWinName[0]) { |
32951 | 223 space = " "; |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
224 name = currWinName; |
32951 | 225 } else { |
226 space = ""; | |
227 name = "section"; | |
228 } | |
229 | |
33106 | 230 if (!section_item("end")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
231 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
232 |
33985 | 233 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %send (%s)\n", space, name); |
32951 | 234 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
235 if (currWinName[0]) { |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
236 currWinName[0] = 0; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
237 currWin = NULL; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
238 currWinItemIdx = NULL; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
239 currWinItems = NULL; |
32873 | 240 } else |
32937 | 241 skin = NULL; |
32873 | 242 |
243 return 0; | |
23077 | 244 } |
245 | |
33968 | 246 /** |
247 * @brief Parse a @a window definition. | |
248 * | |
249 * Syntax: window=main|sub|playbar|menu | |
250 * | |
251 * @param in definition to be analyzed | |
252 * | |
253 * @return 0 (ok) or 1 (error) | |
254 */ | |
33106 | 255 static int item_window(char *in) |
23077 | 256 { |
33106 | 257 if (!section_item("window")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
258 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
259 |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
260 if (currWinName[0]) { |
33062 | 261 skin_error(MSGTR_SKIN_ERROR_ITEM, "window"); |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
262 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
263 } |
32873 | 264 |
33083 | 265 strlower(in); |
23077 | 266 |
33083 | 267 if (strcmp(in, "main") == 0) { |
33095 | 268 currWin = &skin->main; |
269 currWinItemIdx = &skin->IndexOfMainItems; | |
270 currWinItems = skin->mainItems; | |
33083 | 271 } else if (strcmp(in, "sub") == 0) { |
33095 | 272 currWin = &skin->sub; |
33083 | 273 currWinItemIdx = NULL; |
274 currWinItems = NULL; | |
275 } else if (strcmp(in, "playbar") == 0) { | |
33555 | 276 currWin = &skin->playbar; |
277 currWinItemIdx = &skin->IndexOfPlaybarItems; | |
278 currWinItems = skin->playbarItems; | |
33083 | 279 } else if (strcmp(in, "menu") == 0) { |
33095 | 280 currWin = &skin->menu; |
281 currWinItemIdx = &skin->IndexOfMenuItems; | |
282 currWinItems = skin->menuItems; | |
33066 | 283 } else { |
33065 | 284 skin_error(MSGTR_SKIN_UNKNOWN_NAME, in); |
33066 | 285 return 1; |
286 } | |
32873 | 287 |
33083 | 288 av_strlcpy(currWinName, in, sizeof(currWinName)); |
289 | |
33985 | 290 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] window: %s\n", currWinName); |
32873 | 291 |
292 return 0; | |
23077 | 293 } |
294 | |
33968 | 295 /** |
296 * @brief Parse a @a base definition. | |
297 * | |
298 * Syntax: base=image,x,y[,width,height] | |
299 * | |
300 * @param in definition to be analyzed | |
301 * | |
302 * @return 0 (ok) or 1 (error) | |
303 */ | |
33106 | 304 static int item_base(char *in) |
23077 | 305 { |
33090 | 306 unsigned char fname[256]; |
33089 | 307 unsigned char file[512]; |
32873 | 308 int x, y; |
33089 | 309 int w = 0, h = 0; |
33104 | 310 int is_sub, is_bar, is_menu; |
32873 | 311 |
33106 | 312 if (!window_item("base")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
313 return 1; |
23077 | 314 |
33104 | 315 is_sub = (strcmp(currWinName, "sub") == 0); |
316 is_bar = (strcmp(currWinName, "playbar") == 0); | |
317 is_menu = (strcmp(currWinName, "menu") == 0); | |
318 | |
32873 | 319 cutItem(in, fname, ',', 0); |
33089 | 320 x = cutItemToInt(in, ',', 1); |
321 y = cutItemToInt(in, ',', 2); | |
322 w = cutItemToInt(in, ',', 3); | |
323 h = cutItemToInt(in, ',', 4); | |
32873 | 324 |
33985 | 325 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image: %s", fname); |
23077 | 326 |
33105 | 327 currWin->type = itBase; |
33104 | 328 |
33105 | 329 if (!is_menu) { |
330 currWin->x = x; | |
331 currWin->y = y; | |
32873 | 332 |
33985 | 333 mp_msg(MSGT_GPLAYER, MSGL_DBG2, " %d,%d", x, y); |
33105 | 334 } |
32951 | 335 |
33985 | 336 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "\n"); |
32873 | 337 |
33105 | 338 av_strlcpy(file, path, sizeof(file)); |
339 av_strlcat(file, fname, sizeof(file)); | |
32873 | 340 |
33969 | 341 if (skinImageRead(file, &currWin->Bitmap) != 0) |
33105 | 342 return 1; |
32873 | 343 |
33105 | 344 currWin->width = currWin->Bitmap.Width; |
345 currWin->height = currWin->Bitmap.Height; | |
32873 | 346 |
33105 | 347 if (is_sub) { |
33089 | 348 if (w && h) { |
33096 | 349 currWin->width = w; |
350 currWin->height = h; | |
32873 | 351 } |
33105 | 352 } |
32873 | 353 |
33985 | 354 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", currWin->width, currWin->height); |
32951 | 355 |
33105 | 356 if (!is_sub) { |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
357 #ifdef CONFIG_XSHAPE |
33555 | 358 if (!bpRenderMask(&currWin->Bitmap, &currWin->Mask)) { |
33114 | 359 skin_error(MSGTR_SKIN_NotEnoughMemory); |
360 return 1; | |
361 } | |
33985 | 362 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] mask: %lux%lu\n", currWin->Mask.Width, currWin->Mask.Height); |
23077 | 363 #else |
33096 | 364 currWin->Mask.Image = NULL; |
23077 | 365 #endif |
33105 | 366 } |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
367 |
33105 | 368 if (is_bar) |
33555 | 369 skin->playbarIsPresent = 1; |
33105 | 370 if (is_menu) |
371 skin->menuIsPresent = 1; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
372 |
32873 | 373 return 0; |
23077 | 374 } |
375 | |
33968 | 376 /** |
377 * @brief Parse a @a background definition. | |
378 * | |
379 * Syntax: background=R,G,B | |
380 * | |
381 * @param in definition to be analyzed | |
382 * | |
383 * @return 0 (ok) or 1 (error) | |
384 */ | |
33106 | 385 static int item_background(char *in) |
23077 | 386 { |
33106 | 387 if (!window_item("background")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
388 return 1; |
23077 | 389 |
33058 | 390 if (in_window("main")) |
391 return 1; | |
33088 | 392 if (in_window("playbar")) |
393 return 1; | |
33058 | 394 if (in_window("menu")) |
395 return 1; | |
23077 | 396 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
397 currWin->R = cutItemToInt(in, ',', 0); |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
398 currWin->G = cutItemToInt(in, ',', 1); |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
399 currWin->B = cutItemToInt(in, ',', 2); |
23077 | 400 |
33985 | 401 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] background color: #%02x%02x%02x\n", currWin->R, currWin->G, currWin->B); |
23077 | 402 |
32873 | 403 return 0; |
23077 | 404 } |
405 | |
33968 | 406 /** |
407 * @brief Parse a @a button definition. | |
408 * | |
409 * Syntax: button=image,x,y,width,height,message | |
410 * | |
411 * @param in definition to be analyzed | |
412 * | |
413 * @return 0 (ok) or 1 (error) | |
414 */ | |
33106 | 415 static int item_button(char *in) |
23077 | 416 { |
33090 | 417 unsigned char fname[256]; |
33089 | 418 unsigned char file[512]; |
419 int x, y, w, h, message; | |
32873 | 420 char msg[32]; |
33098 | 421 wItem *item; |
32873 | 422 |
33106 | 423 if (!window_item("button")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
424 return 1; |
32873 | 425 |
33058 | 426 if (in_window("sub")) |
427 return 1; | |
428 if (in_window("menu")) | |
429 return 1; | |
23077 | 430 |
32873 | 431 cutItem(in, fname, ',', 0); |
33089 | 432 x = cutItemToInt(in, ',', 1); |
433 y = cutItemToInt(in, ',', 2); | |
434 w = cutItemToInt(in, ',', 3); | |
435 h = cutItemToInt(in, ',', 4); | |
32873 | 436 cutItem(in, msg, ',', 5); |
437 | |
33071 | 438 message = appFindMessage(msg); |
439 | |
440 if (message == -1) { | |
441 skin_error(MSGTR_SKIN_UnknownMessage, msg); | |
442 return 1; | |
443 } | |
444 | |
33985 | 445 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] button image: %s %d,%d\n", fname, x, y); |
446 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", msg, message); | |
447 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] size: %dx%d\n", w, h); | |
33102
de688a61e439
Move debug messages so that they will be processed earlier.
ib
parents:
33101
diff
changeset
|
448 |
33098 | 449 item = next_item(); |
450 | |
451 if (!item) | |
452 return 1; | |
453 | |
454 item->type = itButton; | |
455 item->x = x; | |
456 item->y = y; | |
457 item->width = w; | |
458 item->height = h; | |
459 item->message = message; | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
460 item->pressed = btnReleased; |
23077 | 461 |
33098 | 462 if (item->message == evPauseSwitchToPlay) |
463 item->pressed = btnDisabled; | |
23077 | 464 |
33098 | 465 item->Bitmap.Image = NULL; |
32873 | 466 |
467 if (strcmp(fname, "NULL") != 0) { | |
33089 | 468 av_strlcpy(file, path, sizeof(file)); |
469 av_strlcat(file, fname, sizeof(file)); | |
32873 | 470 |
33969 | 471 if (skinImageRead(file, &item->Bitmap) != 0) |
32873 | 472 return 1; |
32951 | 473 |
33985 | 474 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); |
32873 | 475 } |
476 | |
477 return 0; | |
23077 | 478 } |
479 | |
33968 | 480 /** |
481 * @brief Parse a @a selected definition. | |
482 * | |
483 * Syntax: selected=image | |
484 * | |
485 * @param in definition to be analyzed | |
486 * | |
487 * @return 0 (ok) or 1 (error) | |
488 */ | |
33106 | 489 static int item_selected(char *in) |
32873 | 490 { |
33089 | 491 unsigned char file[512]; |
33096 | 492 wItem *currItem; |
32873 | 493 |
33106 | 494 if (!window_item("selected")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
495 return 1; |
32873 | 496 |
33058 | 497 if (in_window("main")) |
498 return 1; | |
499 if (in_window("sub")) | |
500 return 1; | |
501 if (in_window("playbar")) | |
502 return 1; | |
32873 | 503 |
33985 | 504 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image selected: %s\n", in); |
33102
de688a61e439
Move debug messages so that they will be processed earlier.
ib
parents:
33101
diff
changeset
|
505 |
33096 | 506 currItem = &skin->menuSelected; |
507 currItem->type = itBase; | |
32873 | 508 |
33089 | 509 av_strlcpy(file, path, sizeof(file)); |
33091 | 510 av_strlcat(file, in, sizeof(file)); |
32873 | 511 |
33969 | 512 if (skinImageRead(file, &currItem->Bitmap) != 0) |
32873 | 513 return 1; |
514 | |
33096 | 515 currItem->width = currItem->Bitmap.Width; |
516 currItem->height = currItem->Bitmap.Height; | |
32873 | 517 |
33985 | 518 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", currItem->width, currItem->height); |
32873 | 519 |
520 return 0; | |
521 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
522 |
33968 | 523 /** |
524 * @brief Parse a @a menu definition. | |
525 * | |
526 * Syntax: menu=x,y,width,height,message | |
527 * | |
528 * @param in definition to be analyzed | |
529 * | |
530 * @return 0 (ok) or 1 (error) | |
531 */ | |
33106 | 532 static int item_menu(char *in) |
32873 | 533 { |
33089 | 534 int x, y, w, h, message; |
33071 | 535 char msg[32]; |
33096 | 536 wItem *item; |
32873 | 537 |
33106 | 538 if (!window_item("menu")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
539 return 1; |
32873 | 540 |
33058 | 541 if (in_window("main")) |
542 return 1; | |
543 if (in_window("sub")) | |
544 return 1; | |
545 if (in_window("playbar")) | |
546 return 1; | |
32873 | 547 |
33089 | 548 x = cutItemToInt(in, ',', 0); |
549 y = cutItemToInt(in, ',', 1); | |
550 w = cutItemToInt(in, ',', 2); | |
551 h = cutItemToInt(in, ',', 3); | |
33071 | 552 cutItem(in, msg, ',', 4); |
553 | |
554 message = appFindMessage(msg); | |
23077 | 555 |
33071 | 556 if (message == -1) { |
557 skin_error(MSGTR_SKIN_UnknownMessage, msg); | |
558 return 1; | |
559 } | |
32873 | 560 |
33098 | 561 item = next_item(); |
562 | |
563 if (!item) | |
564 return 1; | |
565 | |
33100 | 566 item->type = itMenu; |
33096 | 567 item->x = x; |
568 item->y = y; | |
569 item->width = w; | |
570 item->height = h; | |
571 item->message = message; | |
23077 | 572 |
33985 | 573 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] item #%d: %d,%d %dx%d\n", *currWinItemIdx, x, y, w, h); |
574 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", msg, message); | |
23077 | 575 |
33096 | 576 item->Bitmap.Image = NULL; |
33053 | 577 |
32873 | 578 return 0; |
23077 | 579 } |
580 | |
33968 | 581 /** |
582 * @brief Parse a @a hpotmeter definition. | |
583 * | |
584 * Syntax: hpotmeter=button,bwidth,bheight,phases,numphases,default,x,y,width,height,message | |
585 * | |
586 * @param in definition to be analyzed | |
587 * | |
588 * @return 0 (ok) or 1 (error) | |
589 */ | |
33106 | 590 static int item_hpotmeter(char *in) |
32873 | 591 { |
33090 | 592 unsigned char pfname[256]; |
593 unsigned char phfname[256]; | |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
594 unsigned char buf[512]; |
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
595 int pwidth, pheight, ph, d, x, y, w, h, message; |
32873 | 596 wItem *item; |
23077 | 597 |
33106 | 598 if (!window_item("h/v potmeter")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
599 return 1; |
23077 | 600 |
33058 | 601 if (in_window("sub")) |
602 return 1; | |
603 if (in_window("menu")) | |
604 return 1; | |
23077 | 605 |
32873 | 606 cutItem(in, pfname, ',', 0); |
32911 | 607 pwidth = cutItemToInt(in, ',', 1); |
608 pheight = cutItemToInt(in, ',', 2); | |
32873 | 609 cutItem(in, phfname, ',', 3); |
610 ph = cutItemToInt(in, ',', 4); | |
611 d = cutItemToInt(in, ',', 5); | |
612 x = cutItemToInt(in, ',', 6); | |
613 y = cutItemToInt(in, ',', 7); | |
33089 | 614 w = cutItemToInt(in, ',', 8); |
615 h = cutItemToInt(in, ',', 9); | |
616 cutItem(in, buf, ',', 10); | |
32873 | 617 |
33089 | 618 message = appFindMessage(buf); |
23077 | 619 |
33069 | 620 if (message == -1) { |
33089 | 621 skin_error(MSGTR_SKIN_UnknownMessage, buf); |
33069 | 622 return 1; |
623 } | |
624 | |
33985 | 625 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] h/v potmeter image: %s %d,%d %dx%d\n", phfname, x, y, w, h); |
626 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] button image: %s %dx%d\n", pfname, pwidth, pheight); | |
627 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] numphases: %d, default: %d%%\n", ph, d); | |
628 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", buf, message); | |
23077 | 629 |
33098 | 630 item = next_item(); |
631 | |
632 if (!item) | |
633 return 1; | |
634 | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
635 item->type = itHPotmeter; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
636 item->x = x; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
637 item->y = y; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
638 item->width = w; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
639 item->height = h; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
640 item->pwidth = pwidth; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
641 item->pheight = pheight; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
642 item->numphases = ph; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
643 item->value = (float)d; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
644 item->message = message; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
645 item->pressed = btnReleased; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
646 |
32873 | 647 item->Bitmap.Image = NULL; |
23077 | 648 |
32873 | 649 if (strcmp(phfname, "NULL") != 0) { |
33089 | 650 av_strlcpy(buf, path, sizeof(buf)); |
651 av_strlcat(buf, phfname, sizeof(buf)); | |
32873 | 652 |
33969 | 653 if (skinImageRead(buf, &item->Bitmap) != 0) |
32873 | 654 return 1; |
32951 | 655 |
33985 | 656 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (potmeter bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); |
32873 | 657 } |
658 | |
659 item->Mask.Image = NULL; | |
23077 | 660 |
32873 | 661 if (strcmp(pfname, "NULL") != 0) { |
33089 | 662 av_strlcpy(buf, path, sizeof(buf)); |
663 av_strlcat(buf, pfname, sizeof(buf)); | |
32873 | 664 |
33969 | 665 if (skinImageRead(buf, &item->Mask) != 0) |
32873 | 666 return 1; |
32951 | 667 |
33985 | 668 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (button bitmap: %lux%lu)\n", item->Mask.Width, item->Mask.Height); |
32873 | 669 } |
670 | |
671 return 0; | |
23077 | 672 } |
673 | |
33968 | 674 /** |
675 * @brief Parse a @a vpotmeter definition. | |
676 * | |
677 * Syntax: vpotmeter=button,bwidth,bheight,phases,numphases,default,x,y,width,height,message | |
678 * | |
679 * @param in definition to be analyzed | |
680 * | |
681 * @return 0 (ok) or 1 (error) | |
682 */ | |
33106 | 683 static int item_vpotmeter(char *in) |
23077 | 684 { |
33056 | 685 int r; |
32873 | 686 wItem *item; |
23077 | 687 |
33106 | 688 r = item_hpotmeter(in); |
33056 | 689 |
690 if (r == 0) { | |
33057 | 691 item = &currWinItems[*currWinItemIdx]; |
692 item->type = itVPotmeter; | |
33056 | 693 } |
33053 | 694 |
32873 | 695 return r; |
23077 | 696 } |
697 | |
33968 | 698 /** |
699 * @brief Parse a @a potmeter definition. | |
700 * | |
701 * Syntax: potmeter=phases,numphases,default,x,y,width,height,message | |
702 * | |
703 * @param in definition to be analyzed | |
704 * | |
705 * @return 0 (ok) or 1 (error) | |
706 */ | |
33106 | 707 static int item_potmeter(char *in) |
32873 | 708 { |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
709 unsigned char phfname[256]; |
33089 | 710 unsigned char buf[512]; |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
711 int ph, d, x, y, w, h, message; |
32873 | 712 wItem *item; |
23077 | 713 |
33106 | 714 if (!window_item("potmeter")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
715 return 1; |
23077 | 716 |
33058 | 717 if (in_window("sub")) |
718 return 1; | |
719 if (in_window("menu")) | |
720 return 1; | |
23077 | 721 |
32873 | 722 cutItem(in, phfname, ',', 0); |
723 ph = cutItemToInt(in, ',', 1); | |
724 d = cutItemToInt(in, ',', 2); | |
725 x = cutItemToInt(in, ',', 3); | |
726 y = cutItemToInt(in, ',', 4); | |
33089 | 727 w = cutItemToInt(in, ',', 5); |
728 h = cutItemToInt(in, ',', 6); | |
729 cutItem(in, buf, ',', 7); | |
32873 | 730 |
33089 | 731 message = appFindMessage(buf); |
23077 | 732 |
33069 | 733 if (message == -1) { |
33089 | 734 skin_error(MSGTR_SKIN_UnknownMessage, buf); |
33069 | 735 return 1; |
736 } | |
737 | |
33985 | 738 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] potmeter image: %s %d,%d %dx%d\n", phfname, x, y, w, h); |
739 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] numphases: %d, default: %d%%\n", ph, d); | |
740 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", buf, message); | |
23077 | 741 |
33098 | 742 item = next_item(); |
743 | |
744 if (!item) | |
745 return 1; | |
746 | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
747 item->type = itPotmeter; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
748 item->x = x; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
749 item->y = y; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
750 item->width = w; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
751 item->height = h; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
752 item->numphases = ph; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
753 item->value = (float)d; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
754 item->message = message; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
755 |
32873 | 756 item->Bitmap.Image = NULL; |
23077 | 757 |
32873 | 758 if (strcmp(phfname, "NULL") != 0) { |
33089 | 759 av_strlcpy(buf, path, sizeof(buf)); |
760 av_strlcat(buf, phfname, sizeof(buf)); | |
32873 | 761 |
33969 | 762 if (skinImageRead(buf, &item->Bitmap) != 0) |
32873 | 763 return 1; |
32951 | 764 |
33985 | 765 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); |
32873 | 766 } |
767 | |
768 return 0; | |
23077 | 769 } |
770 | |
33968 | 771 /** |
772 * @brief Parse a @a font definition. | |
773 * | |
774 * Syntax: font=fontfile | |
775 * | |
776 * @param in definition to be analyzed | |
777 * | |
778 * @return 0 (ok) or 1 (error) | |
779 */ | |
33106 | 780 static int item_font(char *in) |
32873 | 781 { |
33092
83052a4ac698
Use more appropriate name for variable and reduce it to reasonable size.
ib
parents:
33091
diff
changeset
|
782 char fnt[256]; |
23077 | 783 |
33106 | 784 if (!window_item("font")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
785 return 1; |
23077 | 786 |
33058 | 787 if (in_window("sub")) |
788 return 1; | |
789 if (in_window("menu")) | |
790 return 1; | |
23077 | 791 |
33092
83052a4ac698
Use more appropriate name for variable and reduce it to reasonable size.
ib
parents:
33091
diff
changeset
|
792 cutItem(in, fnt, ',', 0); // Note: This seems needless but isn't for compatibility |
83052a4ac698
Use more appropriate name for variable and reduce it to reasonable size.
ib
parents:
33091
diff
changeset
|
793 // reasons with a meanwhile depreciated second parameter. |
33099
0b17f6bed6fc
Don't needlessly store font information in the wItems array
ib
parents:
33098
diff
changeset
|
794 switch (fntRead(path, fnt)) { |
32873 | 795 case -1: |
33097 | 796 skin_error(MSGTR_SKIN_NotEnoughMemory); |
32873 | 797 return 1; |
23077 | 798 |
32873 | 799 case -2: |
33022 | 800 skin_error(MSGTR_SKIN_FONT_TooManyFontsDeclared); |
32873 | 801 return 1; |
802 | |
803 case -3: | |
33022 | 804 skin_error(MSGTR_SKIN_FONT_FontFileNotFound); |
32873 | 805 return 1; |
806 | |
807 case -4: | |
33022 | 808 skin_error(MSGTR_SKIN_FONT_FontImageNotFound); |
32873 | 809 return 1; |
810 } | |
811 | |
33985 | 812 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, fntFindID(fnt)); |
32951 | 813 |
32873 | 814 return 0; |
23077 | 815 } |
816 | |
33968 | 817 /** |
818 * @brief Parse a @a slabel definition. | |
819 * | |
820 * Syntax: slabel=x,y,fontfile,"text" | |
821 * | |
822 * @param in definition to be analyzed | |
823 * | |
824 * @return 0 (ok) or 1 (error) | |
825 */ | |
33106 | 826 static int item_slabel(char *in) |
23077 | 827 { |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
828 int x, y, id; |
33090 | 829 char fnt[256]; |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
830 char txt[256]; |
32873 | 831 wItem *item; |
832 | |
33106 | 833 if (!window_item("slabel")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
834 return 1; |
23077 | 835 |
33058 | 836 if (in_window("sub")) |
837 return 1; | |
838 if (in_window("menu")) | |
839 return 1; | |
32873 | 840 |
841 x = cutItemToInt(in, ',', 0); | |
842 y = cutItemToInt(in, ',', 1); | |
33089 | 843 cutItem(in, fnt, ',', 2); |
844 cutItem(in, txt, ',', 3); | |
845 cutItem(txt, txt, '"', 1); | |
32951 | 846 |
33985 | 847 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] slabel: \"%s\"\n", txt); |
848 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] pos: %d,%d\n", x, y); | |
23077 | 849 |
33089 | 850 id = fntFindID(fnt); |
23077 | 851 |
32873 | 852 if (id < 0) { |
33097 | 853 skin_error(MSGTR_SKIN_FONT_NonExistentFont, fnt); |
32873 | 854 return 1; |
855 } | |
23077 | 856 |
33985 | 857 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, id); |
23077 | 858 |
33098 | 859 item = next_item(); |
860 | |
861 if (!item) | |
862 return 1; | |
863 | |
32873 | 864 item->type = itSLabel; |
865 item->x = x; | |
866 item->y = y; | |
867 item->width = -1; | |
868 item->height = -1; | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
869 item->fontid = id; |
33089 | 870 item->label = strdup(txt); |
23077 | 871 |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
872 if (!item->label) { |
33097 | 873 skin_error(MSGTR_SKIN_NotEnoughMemory); |
32873 | 874 return 1; |
875 } | |
23077 | 876 |
32873 | 877 return 0; |
23077 | 878 } |
879 | |
33968 | 880 /** |
881 * @brief Parse a @a dlabel definition. | |
882 * | |
883 * Syntax: dlabel=x,y,width,align,fontfile,"text" | |
884 * | |
885 * @param in definition to be analyzed | |
886 * | |
887 * @return 0 (ok) or 1 (error) | |
888 */ | |
33106 | 889 static int item_dlabel(char *in) |
32873 | 890 { |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
891 int x, y, w, a, id; |
33090 | 892 char fnt[256]; |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
893 char txt[256]; |
32873 | 894 wItem *item; |
23077 | 895 |
33106 | 896 if (!window_item("dlabel")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
897 return 1; |
23077 | 898 |
33058 | 899 if (in_window("sub")) |
900 return 1; | |
901 if (in_window("menu")) | |
902 return 1; | |
32873 | 903 |
33089 | 904 x = cutItemToInt(in, ',', 0); |
905 y = cutItemToInt(in, ',', 1); | |
906 w = cutItemToInt(in, ',', 2); | |
907 a = cutItemToInt(in, ',', 3); | |
908 cutItem(in, fnt, ',', 4); | |
909 cutItem(in, txt, ',', 5); | |
910 cutItem(txt, txt, '"', 1); | |
32951 | 911 |
33985 | 912 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] dlabel: \"%s\"\n", txt); |
913 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] pos: %d,%d\n", x, y); | |
914 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] width: %d, align: %d\n", w, a); | |
23077 | 915 |
33089 | 916 id = fntFindID(fnt); |
23077 | 917 |
32873 | 918 if (id < 0) { |
33097 | 919 skin_error(MSGTR_SKIN_FONT_NonExistentFont, fnt); |
32873 | 920 return 1; |
921 } | |
23077 | 922 |
33985 | 923 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, id); |
23077 | 924 |
33098 | 925 item = next_item(); |
926 | |
927 if (!item) | |
928 return 1; | |
929 | |
32873 | 930 item->type = itDLabel; |
931 item->x = x; | |
932 item->y = y; | |
33089 | 933 item->width = w; |
32873 | 934 item->height = -1; |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
935 item->fontid = id; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
936 item->align = a; |
33089 | 937 item->label = strdup(txt); |
23077 | 938 |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
939 if (!item->label) { |
33097 | 940 skin_error(MSGTR_SKIN_NotEnoughMemory); |
32873 | 941 return 1; |
942 } | |
23077 | 943 |
32873 | 944 return 0; |
23077 | 945 } |
946 | |
33968 | 947 /** |
948 * @brief Parse a @a decoration definition. | |
949 * | |
950 * Syntax: decoration=enable|disable | |
951 * | |
952 * @param in definition to be analyzed | |
953 * | |
954 * @return 0 (ok) or 1 (error) | |
955 */ | |
33106 | 956 static int item_decoration(char *in) |
23077 | 957 { |
33106 | 958 if (!window_item("decoration")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
959 return 1; |
32873 | 960 |
33058 | 961 if (in_window("sub")) |
962 return 1; | |
963 if (in_window("playbar")) | |
964 return 1; | |
965 if (in_window("menu")) | |
966 return 1; | |
32873 | 967 |
33086 | 968 strlower(in); |
32873 | 969 |
33086 | 970 if (strcmp(in, "enable") != 0 && strcmp(in, "disable") != 0) { |
971 skin_error(MSGTR_SKIN_UnknownParameter, in); | |
32873 | 972 return 1; |
973 } | |
23077 | 974 |
33087 | 975 skin->mainDecoration = (strcmp(in, "enable") == 0); |
23077 | 976 |
33985 | 977 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] decoration: %s\n", in); |
32873 | 978 |
979 return 0; | |
23077 | 980 } |
981 | |
33968 | 982 /** |
983 * @brief Parsing functions responsible for skin item definitions. | |
984 */ | |
32878 | 985 static _item skinItem[] = { |
33106 | 986 { "background", item_background }, |
987 { "base", item_base }, | |
988 { "button", item_button }, | |
989 { "decoration", item_decoration }, | |
990 { "dlabel", item_dlabel }, | |
991 { "end", item_end }, | |
992 { "font", item_font }, | |
993 { "hpotmeter", item_hpotmeter }, | |
994 { "menu", item_menu }, | |
995 { "potmeter", item_potmeter }, | |
996 { "section", item_section }, | |
997 { "selected", item_selected }, | |
998 { "slabel", item_slabel }, | |
999 { "vpotmeter", item_vpotmeter }, | |
1000 { "window", item_window } | |
32873 | 1001 }; |
1002 | |
33968 | 1003 /** |
1004 * @brief Build the skin file path for a skin name. | |
1005 * | |
1006 * @param dir skins directory | |
1007 * @param sname name of the skin | |
1008 * | |
1009 * @return skin file path | |
1010 * | |
1011 * @note As a side effect, variable #path gets set to the skin path. | |
1012 */ | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1013 static char *setname(char *dir, char *sname) |
32873 | 1014 { |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1015 static char skinfname[512]; |
32873 | 1016 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1017 av_strlcpy(skinfname, dir, sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1018 av_strlcat(skinfname, "/", sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1019 av_strlcat(skinfname, sname, sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1020 av_strlcat(skinfname, "/", sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1021 av_strlcpy(path, skinfname, sizeof(path)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1022 av_strlcat(skinfname, "skin", sizeof(skinfname)); |
32873 | 1023 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1024 return skinfname; |
23077 | 1025 } |
1026 | |
33968 | 1027 /** |
1028 * @brief Read and parse a skin. | |
1029 * | |
1030 * @param sname name of the skin | |
1031 * | |
1032 * @return 0 (ok), -1 (skin file not found or not readable) or -2 (parsing error) | |
1033 */ | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1034 int skinRead(char *sname) |
23077 | 1035 { |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1036 char *skinfname; |
32873 | 1037 FILE *skinFile; |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1038 unsigned char line[256]; |
33075 | 1039 unsigned char item[32]; |
32873 | 1040 unsigned char param[256]; |
32944 | 1041 unsigned int i; |
32873 | 1042 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1043 skinfname = setname(skinDirInHome, sname); |
23077 | 1044 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1045 if ((skinFile = fopen(skinfname, "rt")) == NULL) { |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1046 skinfname = setname(skinMPlayerDir, sname); |
32873 | 1047 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1048 if ((skinFile = fopen(skinfname, "rt")) == NULL) { |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1049 mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_SkinFileNotFound, skinfname); |
32873 | 1050 return -1; |
1051 } | |
23077 | 1052 } |
32873 | 1053 |
33985 | 1054 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] configuration file: %s\n", skinfname); |
23077 | 1055 |
32932 | 1056 appFreeStruct(); |
23077 | 1057 |
33078 | 1058 skin = NULL; |
1059 currWinName[0] = 0; | |
33079 | 1060 linenumber = 0; |
23077 | 1061 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1062 while (fgets(line, sizeof(line), skinFile)) { |
32873 | 1063 linenumber++; |
1064 | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1065 line[strcspn(line, "\n\r")] = 0; // remove any kind of newline, if any |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1066 strswap(line, '\t', ' '); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1067 trim(line); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1068 decomment(line); |
32873 | 1069 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1070 if (!*line) |
32873 | 1071 continue; |
23077 | 1072 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1073 cutItem(line, item, '=', 0); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1074 cutItem(line, param, '=', 1); |
33075 | 1075 strlower(item); |
32873 | 1076 |
33076
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1077 for (i = 0; i < FF_ARRAY_ELEMS(skinItem); i++) { |
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1078 if (!strcmp(item, skinItem[i].name)) { |
32873 | 1079 if (skinItem[i].func(param) != 0) |
1080 return -2; | |
33076
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1081 else |
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1082 break; |
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1083 } |
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1084 } |
33077 | 1085 |
1086 if (i == FF_ARRAY_ELEMS(skinItem)) { | |
1087 skin_error(MSGTR_SKIN_UNKNOWN_ITEM, item); | |
1088 return -2; | |
1089 } | |
32873 | 1090 } |
1091 | |
1092 if (linenumber == 0) { | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1093 mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_SkinFileNotReadable, skinfname); |
32873 | 1094 return -1; |
1095 } | |
1096 | |
1097 return 0; | |
23077 | 1098 } |