Mercurial > mplayer.hg
annotate gui/skin/skin.c @ 35360:a3e8af09792d
Close the skin file after reading.
author | ib |
---|---|
date | Fri, 23 Nov 2012 10:31:07 +0000 |
parents | 456784c6c904 |
children | 31a5320909f7 |
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 * | |
34697 | 249 * Syntax: window=main|video|playbar|menu |
33968 | 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 |
34697 | 267 if (strcmp(in, "sub") == 0) |
268 strcpy(in, "video"); // legacy | |
269 | |
33083 | 270 if (strcmp(in, "main") == 0) { |
33095 | 271 currWin = &skin->main; |
272 currWinItemIdx = &skin->IndexOfMainItems; | |
273 currWinItems = skin->mainItems; | |
34697 | 274 } else if (strcmp(in, "video") == 0) { |
275 currWin = &skin->video; | |
33083 | 276 currWinItemIdx = NULL; |
277 currWinItems = NULL; | |
278 } else if (strcmp(in, "playbar") == 0) { | |
33555 | 279 currWin = &skin->playbar; |
280 currWinItemIdx = &skin->IndexOfPlaybarItems; | |
281 currWinItems = skin->playbarItems; | |
33083 | 282 } else if (strcmp(in, "menu") == 0) { |
33095 | 283 currWin = &skin->menu; |
284 currWinItemIdx = &skin->IndexOfMenuItems; | |
285 currWinItems = skin->menuItems; | |
33066 | 286 } else { |
33065 | 287 skin_error(MSGTR_SKIN_UNKNOWN_NAME, in); |
33066 | 288 return 1; |
289 } | |
32873 | 290 |
33083 | 291 av_strlcpy(currWinName, in, sizeof(currWinName)); |
292 | |
33985 | 293 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] window: %s\n", currWinName); |
32873 | 294 |
295 return 0; | |
23077 | 296 } |
297 | |
33968 | 298 /** |
299 * @brief Parse a @a base definition. | |
300 * | |
301 * Syntax: base=image,x,y[,width,height] | |
302 * | |
303 * @param in definition to be analyzed | |
304 * | |
305 * @return 0 (ok) or 1 (error) | |
306 */ | |
33106 | 307 static int item_base(char *in) |
23077 | 308 { |
33090 | 309 unsigned char fname[256]; |
33089 | 310 unsigned char file[512]; |
32873 | 311 int x, y; |
33089 | 312 int w = 0, h = 0; |
34697 | 313 int is_video, is_bar, is_menu; |
32873 | 314 |
33106 | 315 if (!window_item("base")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
316 return 1; |
23077 | 317 |
34697 | 318 is_video = (strcmp(currWinName, "video") == 0); |
34698 | 319 is_bar = (strcmp(currWinName, "playbar") == 0); |
320 is_menu = (strcmp(currWinName, "menu") == 0); | |
33104 | 321 |
32873 | 322 cutItem(in, fname, ',', 0); |
33089 | 323 x = cutItemToInt(in, ',', 1); |
324 y = cutItemToInt(in, ',', 2); | |
325 w = cutItemToInt(in, ',', 3); | |
326 h = cutItemToInt(in, ',', 4); | |
32873 | 327 |
33985 | 328 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image: %s", fname); |
23077 | 329 |
33105 | 330 currWin->type = itBase; |
33104 | 331 |
33105 | 332 if (!is_menu) { |
333 currWin->x = x; | |
334 currWin->y = y; | |
32873 | 335 |
33985 | 336 mp_msg(MSGT_GPLAYER, MSGL_DBG2, " %d,%d", x, y); |
33105 | 337 } |
32951 | 338 |
33985 | 339 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "\n"); |
32873 | 340 |
33105 | 341 av_strlcpy(file, path, sizeof(file)); |
342 av_strlcat(file, fname, sizeof(file)); | |
32873 | 343 |
33969 | 344 if (skinImageRead(file, &currWin->Bitmap) != 0) |
33105 | 345 return 1; |
32873 | 346 |
33105 | 347 currWin->width = currWin->Bitmap.Width; |
348 currWin->height = currWin->Bitmap.Height; | |
32873 | 349 |
34697 | 350 if (is_video) { |
33089 | 351 if (w && h) { |
33096 | 352 currWin->width = w; |
353 currWin->height = h; | |
32873 | 354 } |
33105 | 355 } |
32873 | 356 |
33985 | 357 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", currWin->width, currWin->height); |
32951 | 358 |
34697 | 359 if (!is_video) { |
33555 | 360 if (!bpRenderMask(&currWin->Bitmap, &currWin->Mask)) { |
33114 | 361 skin_error(MSGTR_SKIN_NotEnoughMemory); |
362 return 1; | |
363 } | |
33985 | 364 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] mask: %lux%lu\n", currWin->Mask.Width, currWin->Mask.Height); |
33105 | 365 } |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
366 |
33105 | 367 if (is_bar) |
33555 | 368 skin->playbarIsPresent = 1; |
33105 | 369 if (is_menu) |
370 skin->menuIsPresent = 1; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
371 |
32873 | 372 return 0; |
23077 | 373 } |
374 | |
33968 | 375 /** |
376 * @brief Parse a @a background definition. | |
377 * | |
378 * Syntax: background=R,G,B | |
379 * | |
380 * @param in definition to be analyzed | |
381 * | |
382 * @return 0 (ok) or 1 (error) | |
383 */ | |
33106 | 384 static int item_background(char *in) |
23077 | 385 { |
33106 | 386 if (!window_item("background")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
387 return 1; |
23077 | 388 |
33058 | 389 if (in_window("main")) |
390 return 1; | |
33088 | 391 if (in_window("playbar")) |
392 return 1; | |
33058 | 393 if (in_window("menu")) |
394 return 1; | |
23077 | 395 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
396 currWin->R = cutItemToInt(in, ',', 0); |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
397 currWin->G = cutItemToInt(in, ',', 1); |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
398 currWin->B = cutItemToInt(in, ',', 2); |
23077 | 399 |
33985 | 400 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] background color: #%02x%02x%02x\n", currWin->R, currWin->G, currWin->B); |
23077 | 401 |
32873 | 402 return 0; |
23077 | 403 } |
404 | |
33968 | 405 /** |
406 * @brief Parse a @a button definition. | |
407 * | |
408 * Syntax: button=image,x,y,width,height,message | |
409 * | |
410 * @param in definition to be analyzed | |
411 * | |
412 * @return 0 (ok) or 1 (error) | |
413 */ | |
33106 | 414 static int item_button(char *in) |
23077 | 415 { |
33090 | 416 unsigned char fname[256]; |
33089 | 417 unsigned char file[512]; |
418 int x, y, w, h, message; | |
32873 | 419 char msg[32]; |
33098 | 420 wItem *item; |
32873 | 421 |
33106 | 422 if (!window_item("button")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
423 return 1; |
32873 | 424 |
34697 | 425 if (in_window("video")) |
33058 | 426 return 1; |
427 if (in_window("menu")) | |
428 return 1; | |
23077 | 429 |
32873 | 430 cutItem(in, fname, ',', 0); |
33089 | 431 x = cutItemToInt(in, ',', 1); |
432 y = cutItemToInt(in, ',', 2); | |
433 w = cutItemToInt(in, ',', 3); | |
434 h = cutItemToInt(in, ',', 4); | |
32873 | 435 cutItem(in, msg, ',', 5); |
436 | |
33071 | 437 message = appFindMessage(msg); |
438 | |
439 if (message == -1) { | |
440 skin_error(MSGTR_SKIN_UnknownMessage, msg); | |
441 return 1; | |
442 } | |
443 | |
33985 | 444 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] button image: %s %d,%d\n", fname, x, y); |
445 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", msg, message); | |
446 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
|
447 |
33098 | 448 item = next_item(); |
449 | |
450 if (!item) | |
451 return 1; | |
452 | |
453 item->type = itButton; | |
454 item->x = x; | |
455 item->y = y; | |
456 item->width = w; | |
457 item->height = h; | |
458 item->message = message; | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
459 item->pressed = btnReleased; |
23077 | 460 |
33098 | 461 if (item->message == evPauseSwitchToPlay) |
462 item->pressed = btnDisabled; | |
23077 | 463 |
33098 | 464 item->Bitmap.Image = NULL; |
32873 | 465 |
466 if (strcmp(fname, "NULL") != 0) { | |
33089 | 467 av_strlcpy(file, path, sizeof(file)); |
468 av_strlcat(file, fname, sizeof(file)); | |
32873 | 469 |
33969 | 470 if (skinImageRead(file, &item->Bitmap) != 0) |
32873 | 471 return 1; |
32951 | 472 |
33985 | 473 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); |
32873 | 474 } |
475 | |
476 return 0; | |
23077 | 477 } |
478 | |
33968 | 479 /** |
480 * @brief Parse a @a selected definition. | |
481 * | |
482 * Syntax: selected=image | |
483 * | |
484 * @param in definition to be analyzed | |
485 * | |
486 * @return 0 (ok) or 1 (error) | |
487 */ | |
33106 | 488 static int item_selected(char *in) |
32873 | 489 { |
33089 | 490 unsigned char file[512]; |
33096 | 491 wItem *currItem; |
32873 | 492 |
33106 | 493 if (!window_item("selected")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
494 return 1; |
32873 | 495 |
33058 | 496 if (in_window("main")) |
497 return 1; | |
34697 | 498 if (in_window("video")) |
33058 | 499 return 1; |
500 if (in_window("playbar")) | |
501 return 1; | |
32873 | 502 |
33985 | 503 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
|
504 |
33096 | 505 currItem = &skin->menuSelected; |
506 currItem->type = itBase; | |
32873 | 507 |
33089 | 508 av_strlcpy(file, path, sizeof(file)); |
33091 | 509 av_strlcat(file, in, sizeof(file)); |
32873 | 510 |
33969 | 511 if (skinImageRead(file, &currItem->Bitmap) != 0) |
32873 | 512 return 1; |
513 | |
33096 | 514 currItem->width = currItem->Bitmap.Width; |
515 currItem->height = currItem->Bitmap.Height; | |
32873 | 516 |
33985 | 517 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", currItem->width, currItem->height); |
32873 | 518 |
519 return 0; | |
520 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
521 |
33968 | 522 /** |
523 * @brief Parse a @a menu definition. | |
524 * | |
525 * Syntax: menu=x,y,width,height,message | |
526 * | |
527 * @param in definition to be analyzed | |
528 * | |
529 * @return 0 (ok) or 1 (error) | |
530 */ | |
33106 | 531 static int item_menu(char *in) |
32873 | 532 { |
33089 | 533 int x, y, w, h, message; |
33071 | 534 char msg[32]; |
33096 | 535 wItem *item; |
32873 | 536 |
33106 | 537 if (!window_item("menu")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
538 return 1; |
32873 | 539 |
33058 | 540 if (in_window("main")) |
541 return 1; | |
34697 | 542 if (in_window("video")) |
33058 | 543 return 1; |
544 if (in_window("playbar")) | |
545 return 1; | |
32873 | 546 |
33089 | 547 x = cutItemToInt(in, ',', 0); |
548 y = cutItemToInt(in, ',', 1); | |
549 w = cutItemToInt(in, ',', 2); | |
550 h = cutItemToInt(in, ',', 3); | |
33071 | 551 cutItem(in, msg, ',', 4); |
552 | |
553 message = appFindMessage(msg); | |
23077 | 554 |
33071 | 555 if (message == -1) { |
556 skin_error(MSGTR_SKIN_UnknownMessage, msg); | |
557 return 1; | |
558 } | |
32873 | 559 |
33098 | 560 item = next_item(); |
561 | |
562 if (!item) | |
563 return 1; | |
564 | |
33100 | 565 item->type = itMenu; |
33096 | 566 item->x = x; |
567 item->y = y; | |
568 item->width = w; | |
569 item->height = h; | |
570 item->message = message; | |
23077 | 571 |
33985 | 572 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] item #%d: %d,%d %dx%d\n", *currWinItemIdx, x, y, w, h); |
573 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", msg, message); | |
23077 | 574 |
33096 | 575 item->Bitmap.Image = NULL; |
33053 | 576 |
32873 | 577 return 0; |
23077 | 578 } |
579 | |
33968 | 580 /** |
581 * @brief Parse a @a hpotmeter definition. | |
582 * | |
583 * Syntax: hpotmeter=button,bwidth,bheight,phases,numphases,default,x,y,width,height,message | |
584 * | |
585 * @param in definition to be analyzed | |
586 * | |
587 * @return 0 (ok) or 1 (error) | |
588 */ | |
33106 | 589 static int item_hpotmeter(char *in) |
32873 | 590 { |
33090 | 591 unsigned char pfname[256]; |
592 unsigned char phfname[256]; | |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
593 unsigned char buf[512]; |
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
594 int pwidth, pheight, ph, d, x, y, w, h, message; |
32873 | 595 wItem *item; |
23077 | 596 |
33106 | 597 if (!window_item("h/v potmeter")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
598 return 1; |
23077 | 599 |
34697 | 600 if (in_window("video")) |
33058 | 601 return 1; |
602 if (in_window("menu")) | |
603 return 1; | |
23077 | 604 |
32873 | 605 cutItem(in, pfname, ',', 0); |
32911 | 606 pwidth = cutItemToInt(in, ',', 1); |
607 pheight = cutItemToInt(in, ',', 2); | |
32873 | 608 cutItem(in, phfname, ',', 3); |
609 ph = cutItemToInt(in, ',', 4); | |
610 d = cutItemToInt(in, ',', 5); | |
611 x = cutItemToInt(in, ',', 6); | |
612 y = cutItemToInt(in, ',', 7); | |
33089 | 613 w = cutItemToInt(in, ',', 8); |
614 h = cutItemToInt(in, ',', 9); | |
615 cutItem(in, buf, ',', 10); | |
32873 | 616 |
33089 | 617 message = appFindMessage(buf); |
23077 | 618 |
33069 | 619 if (message == -1) { |
33089 | 620 skin_error(MSGTR_SKIN_UnknownMessage, buf); |
33069 | 621 return 1; |
622 } | |
623 | |
33985 | 624 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] h/v potmeter image: %s %d,%d %dx%d\n", phfname, x, y, w, h); |
625 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] button image: %s %dx%d\n", pfname, pwidth, pheight); | |
626 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] numphases: %d, default: %d%%\n", ph, d); | |
627 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", buf, message); | |
23077 | 628 |
33098 | 629 item = next_item(); |
630 | |
631 if (!item) | |
632 return 1; | |
633 | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
634 item->type = itHPotmeter; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
635 item->x = x; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
636 item->y = y; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
637 item->width = w; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
638 item->height = h; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
639 item->pwidth = pwidth; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
640 item->pheight = pheight; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
641 item->numphases = ph; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
642 item->value = (float)d; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
643 item->message = message; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
644 item->pressed = btnReleased; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
645 |
32873 | 646 item->Bitmap.Image = NULL; |
23077 | 647 |
32873 | 648 if (strcmp(phfname, "NULL") != 0) { |
33089 | 649 av_strlcpy(buf, path, sizeof(buf)); |
650 av_strlcat(buf, phfname, sizeof(buf)); | |
32873 | 651 |
33969 | 652 if (skinImageRead(buf, &item->Bitmap) != 0) |
32873 | 653 return 1; |
32951 | 654 |
33985 | 655 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (potmeter bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); |
32873 | 656 } |
657 | |
658 item->Mask.Image = NULL; | |
23077 | 659 |
32873 | 660 if (strcmp(pfname, "NULL") != 0) { |
33089 | 661 av_strlcpy(buf, path, sizeof(buf)); |
662 av_strlcat(buf, pfname, sizeof(buf)); | |
32873 | 663 |
33969 | 664 if (skinImageRead(buf, &item->Mask) != 0) |
32873 | 665 return 1; |
32951 | 666 |
33985 | 667 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (button bitmap: %lux%lu)\n", item->Mask.Width, item->Mask.Height); |
32873 | 668 } |
669 | |
670 return 0; | |
23077 | 671 } |
672 | |
33968 | 673 /** |
674 * @brief Parse a @a vpotmeter definition. | |
675 * | |
676 * Syntax: vpotmeter=button,bwidth,bheight,phases,numphases,default,x,y,width,height,message | |
677 * | |
678 * @param in definition to be analyzed | |
679 * | |
680 * @return 0 (ok) or 1 (error) | |
681 */ | |
33106 | 682 static int item_vpotmeter(char *in) |
23077 | 683 { |
33056 | 684 int r; |
32873 | 685 wItem *item; |
23077 | 686 |
33106 | 687 r = item_hpotmeter(in); |
33056 | 688 |
689 if (r == 0) { | |
33057 | 690 item = &currWinItems[*currWinItemIdx]; |
691 item->type = itVPotmeter; | |
33056 | 692 } |
33053 | 693 |
32873 | 694 return r; |
23077 | 695 } |
696 | |
33968 | 697 /** |
698 * @brief Parse a @a potmeter definition. | |
699 * | |
700 * Syntax: potmeter=phases,numphases,default,x,y,width,height,message | |
701 * | |
702 * @param in definition to be analyzed | |
703 * | |
704 * @return 0 (ok) or 1 (error) | |
705 */ | |
33106 | 706 static int item_potmeter(char *in) |
32873 | 707 { |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
708 unsigned char phfname[256]; |
33089 | 709 unsigned char buf[512]; |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
710 int ph, d, x, y, w, h, message; |
32873 | 711 wItem *item; |
23077 | 712 |
33106 | 713 if (!window_item("potmeter")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
714 return 1; |
23077 | 715 |
34697 | 716 if (in_window("video")) |
33058 | 717 return 1; |
718 if (in_window("menu")) | |
719 return 1; | |
23077 | 720 |
32873 | 721 cutItem(in, phfname, ',', 0); |
722 ph = cutItemToInt(in, ',', 1); | |
723 d = cutItemToInt(in, ',', 2); | |
724 x = cutItemToInt(in, ',', 3); | |
725 y = cutItemToInt(in, ',', 4); | |
33089 | 726 w = cutItemToInt(in, ',', 5); |
727 h = cutItemToInt(in, ',', 6); | |
728 cutItem(in, buf, ',', 7); | |
32873 | 729 |
33089 | 730 message = appFindMessage(buf); |
23077 | 731 |
33069 | 732 if (message == -1) { |
33089 | 733 skin_error(MSGTR_SKIN_UnknownMessage, buf); |
33069 | 734 return 1; |
735 } | |
736 | |
33985 | 737 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] potmeter image: %s %d,%d %dx%d\n", phfname, x, y, w, h); |
738 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] numphases: %d, default: %d%%\n", ph, d); | |
739 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", buf, message); | |
23077 | 740 |
33098 | 741 item = next_item(); |
742 | |
743 if (!item) | |
744 return 1; | |
745 | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
746 item->type = itPotmeter; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
747 item->x = x; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
748 item->y = y; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
749 item->width = w; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
750 item->height = h; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
751 item->numphases = ph; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
752 item->value = (float)d; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
753 item->message = message; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
754 |
32873 | 755 item->Bitmap.Image = NULL; |
23077 | 756 |
32873 | 757 if (strcmp(phfname, "NULL") != 0) { |
33089 | 758 av_strlcpy(buf, path, sizeof(buf)); |
759 av_strlcat(buf, phfname, sizeof(buf)); | |
32873 | 760 |
33969 | 761 if (skinImageRead(buf, &item->Bitmap) != 0) |
32873 | 762 return 1; |
32951 | 763 |
33985 | 764 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); |
32873 | 765 } |
766 | |
767 return 0; | |
23077 | 768 } |
769 | |
33968 | 770 /** |
771 * @brief Parse a @a font definition. | |
772 * | |
773 * Syntax: font=fontfile | |
774 * | |
775 * @param in definition to be analyzed | |
776 * | |
777 * @return 0 (ok) or 1 (error) | |
778 */ | |
33106 | 779 static int item_font(char *in) |
32873 | 780 { |
33092
83052a4ac698
Use more appropriate name for variable and reduce it to reasonable size.
ib
parents:
33091
diff
changeset
|
781 char fnt[256]; |
23077 | 782 |
33106 | 783 if (!window_item("font")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
784 return 1; |
23077 | 785 |
34697 | 786 if (in_window("video")) |
33058 | 787 return 1; |
788 if (in_window("menu")) | |
789 return 1; | |
23077 | 790 |
33092
83052a4ac698
Use more appropriate name for variable and reduce it to reasonable size.
ib
parents:
33091
diff
changeset
|
791 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
|
792 // reasons with a meanwhile depreciated second parameter. |
33099
0b17f6bed6fc
Don't needlessly store font information in the wItems array
ib
parents:
33098
diff
changeset
|
793 switch (fntRead(path, fnt)) { |
32873 | 794 case -1: |
33097 | 795 skin_error(MSGTR_SKIN_NotEnoughMemory); |
32873 | 796 return 1; |
23077 | 797 |
32873 | 798 case -2: |
33022 | 799 skin_error(MSGTR_SKIN_FONT_TooManyFontsDeclared); |
32873 | 800 return 1; |
801 | |
802 case -3: | |
33022 | 803 skin_error(MSGTR_SKIN_FONT_FontFileNotFound); |
32873 | 804 return 1; |
805 | |
806 case -4: | |
33022 | 807 skin_error(MSGTR_SKIN_FONT_FontImageNotFound); |
32873 | 808 return 1; |
809 } | |
810 | |
33985 | 811 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, fntFindID(fnt)); |
32951 | 812 |
32873 | 813 return 0; |
23077 | 814 } |
815 | |
33968 | 816 /** |
817 * @brief Parse a @a slabel definition. | |
818 * | |
819 * Syntax: slabel=x,y,fontfile,"text" | |
820 * | |
821 * @param in definition to be analyzed | |
822 * | |
823 * @return 0 (ok) or 1 (error) | |
824 */ | |
33106 | 825 static int item_slabel(char *in) |
23077 | 826 { |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
827 int x, y, id; |
33090 | 828 char fnt[256]; |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
829 char txt[256]; |
32873 | 830 wItem *item; |
831 | |
33106 | 832 if (!window_item("slabel")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
833 return 1; |
23077 | 834 |
34697 | 835 if (in_window("video")) |
33058 | 836 return 1; |
837 if (in_window("menu")) | |
838 return 1; | |
32873 | 839 |
840 x = cutItemToInt(in, ',', 0); | |
841 y = cutItemToInt(in, ',', 1); | |
33089 | 842 cutItem(in, fnt, ',', 2); |
843 cutItem(in, txt, ',', 3); | |
844 cutItem(txt, txt, '"', 1); | |
32951 | 845 |
33985 | 846 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] slabel: \"%s\"\n", txt); |
847 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] pos: %d,%d\n", x, y); | |
23077 | 848 |
33089 | 849 id = fntFindID(fnt); |
23077 | 850 |
32873 | 851 if (id < 0) { |
33097 | 852 skin_error(MSGTR_SKIN_FONT_NonExistentFont, fnt); |
32873 | 853 return 1; |
854 } | |
23077 | 855 |
33985 | 856 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, id); |
23077 | 857 |
33098 | 858 item = next_item(); |
859 | |
860 if (!item) | |
861 return 1; | |
862 | |
32873 | 863 item->type = itSLabel; |
864 item->x = x; | |
865 item->y = y; | |
866 item->width = -1; | |
867 item->height = -1; | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
868 item->fontid = id; |
33089 | 869 item->label = strdup(txt); |
23077 | 870 |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
871 if (!item->label) { |
33097 | 872 skin_error(MSGTR_SKIN_NotEnoughMemory); |
32873 | 873 return 1; |
874 } | |
23077 | 875 |
32873 | 876 return 0; |
23077 | 877 } |
878 | |
33968 | 879 /** |
880 * @brief Parse a @a dlabel definition. | |
881 * | |
882 * Syntax: dlabel=x,y,width,align,fontfile,"text" | |
883 * | |
884 * @param in definition to be analyzed | |
885 * | |
886 * @return 0 (ok) or 1 (error) | |
887 */ | |
33106 | 888 static int item_dlabel(char *in) |
32873 | 889 { |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
890 int x, y, w, a, id; |
33090 | 891 char fnt[256]; |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
892 char txt[256]; |
32873 | 893 wItem *item; |
23077 | 894 |
33106 | 895 if (!window_item("dlabel")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
896 return 1; |
23077 | 897 |
34697 | 898 if (in_window("video")) |
33058 | 899 return 1; |
900 if (in_window("menu")) | |
901 return 1; | |
32873 | 902 |
33089 | 903 x = cutItemToInt(in, ',', 0); |
904 y = cutItemToInt(in, ',', 1); | |
905 w = cutItemToInt(in, ',', 2); | |
906 a = cutItemToInt(in, ',', 3); | |
907 cutItem(in, fnt, ',', 4); | |
908 cutItem(in, txt, ',', 5); | |
909 cutItem(txt, txt, '"', 1); | |
32951 | 910 |
33985 | 911 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] dlabel: \"%s\"\n", txt); |
912 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] pos: %d,%d\n", x, y); | |
913 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] width: %d, align: %d\n", w, a); | |
23077 | 914 |
33089 | 915 id = fntFindID(fnt); |
23077 | 916 |
32873 | 917 if (id < 0) { |
33097 | 918 skin_error(MSGTR_SKIN_FONT_NonExistentFont, fnt); |
32873 | 919 return 1; |
920 } | |
23077 | 921 |
33985 | 922 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, id); |
23077 | 923 |
33098 | 924 item = next_item(); |
925 | |
926 if (!item) | |
927 return 1; | |
928 | |
32873 | 929 item->type = itDLabel; |
930 item->x = x; | |
931 item->y = y; | |
33089 | 932 item->width = w; |
32873 | 933 item->height = -1; |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
934 item->fontid = id; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
935 item->align = a; |
33089 | 936 item->label = strdup(txt); |
23077 | 937 |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
938 if (!item->label) { |
33097 | 939 skin_error(MSGTR_SKIN_NotEnoughMemory); |
32873 | 940 return 1; |
941 } | |
23077 | 942 |
32873 | 943 return 0; |
23077 | 944 } |
945 | |
33968 | 946 /** |
947 * @brief Parse a @a decoration definition. | |
948 * | |
949 * Syntax: decoration=enable|disable | |
950 * | |
951 * @param in definition to be analyzed | |
952 * | |
953 * @return 0 (ok) or 1 (error) | |
954 */ | |
33106 | 955 static int item_decoration(char *in) |
23077 | 956 { |
33106 | 957 if (!window_item("decoration")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
958 return 1; |
32873 | 959 |
34697 | 960 if (in_window("video")) |
33058 | 961 return 1; |
962 if (in_window("playbar")) | |
963 return 1; | |
964 if (in_window("menu")) | |
965 return 1; | |
32873 | 966 |
33086 | 967 strlower(in); |
32873 | 968 |
33086 | 969 if (strcmp(in, "enable") != 0 && strcmp(in, "disable") != 0) { |
970 skin_error(MSGTR_SKIN_UnknownParameter, in); | |
32873 | 971 return 1; |
972 } | |
23077 | 973 |
33087 | 974 skin->mainDecoration = (strcmp(in, "enable") == 0); |
23077 | 975 |
33985 | 976 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] decoration: %s\n", in); |
32873 | 977 |
978 return 0; | |
23077 | 979 } |
980 | |
33968 | 981 /** |
982 * @brief Parsing functions responsible for skin item definitions. | |
983 */ | |
32878 | 984 static _item skinItem[] = { |
33106 | 985 { "background", item_background }, |
986 { "base", item_base }, | |
987 { "button", item_button }, | |
988 { "decoration", item_decoration }, | |
989 { "dlabel", item_dlabel }, | |
990 { "end", item_end }, | |
991 { "font", item_font }, | |
992 { "hpotmeter", item_hpotmeter }, | |
993 { "menu", item_menu }, | |
994 { "potmeter", item_potmeter }, | |
995 { "section", item_section }, | |
996 { "selected", item_selected }, | |
997 { "slabel", item_slabel }, | |
998 { "vpotmeter", item_vpotmeter }, | |
999 { "window", item_window } | |
32873 | 1000 }; |
1001 | |
33968 | 1002 /** |
1003 * @brief Build the skin file path for a skin name. | |
1004 * | |
1005 * @param dir skins directory | |
1006 * @param sname name of the skin | |
1007 * | |
1008 * @return skin file path | |
1009 * | |
1010 * @note As a side effect, variable #path gets set to the skin path. | |
1011 */ | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1012 static char *setname(char *dir, char *sname) |
32873 | 1013 { |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1014 static char skinfname[512]; |
32873 | 1015 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1016 av_strlcpy(skinfname, dir, sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1017 av_strlcat(skinfname, "/", sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1018 av_strlcat(skinfname, sname, sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1019 av_strlcat(skinfname, "/", sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1020 av_strlcpy(path, skinfname, sizeof(path)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1021 av_strlcat(skinfname, "skin", sizeof(skinfname)); |
32873 | 1022 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1023 return skinfname; |
23077 | 1024 } |
1025 | |
33968 | 1026 /** |
1027 * @brief Read and parse a skin. | |
1028 * | |
1029 * @param sname name of the skin | |
1030 * | |
1031 * @return 0 (ok), -1 (skin file not found or not readable) or -2 (parsing error) | |
1032 */ | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1033 int skinRead(char *sname) |
23077 | 1034 { |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1035 char *skinfname; |
34578 | 1036 FILE *skinfile; |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1037 unsigned char line[256]; |
33075 | 1038 unsigned char item[32]; |
32873 | 1039 unsigned char param[256]; |
32944 | 1040 unsigned int i; |
32873 | 1041 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1042 skinfname = setname(skinDirInHome, sname); |
23077 | 1043 |
34578 | 1044 if ((skinfile = fopen(skinfname, "rt")) == NULL) { |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1045 skinfname = setname(skinMPlayerDir, sname); |
32873 | 1046 |
34578 | 1047 if ((skinfile = fopen(skinfname, "rt")) == NULL) { |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1048 mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_SkinFileNotFound, skinfname); |
32873 | 1049 return -1; |
1050 } | |
23077 | 1051 } |
32873 | 1052 |
33985 | 1053 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] configuration file: %s\n", skinfname); |
23077 | 1054 |
32932 | 1055 appFreeStruct(); |
23077 | 1056 |
33078 | 1057 skin = NULL; |
1058 currWinName[0] = 0; | |
33079 | 1059 linenumber = 0; |
23077 | 1060 |
34578 | 1061 while (fgetstr(line, sizeof(line), skinfile)) { |
32873 | 1062 linenumber++; |
1063 | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1064 strswap(line, '\t', ' '); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1065 trim(line); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1066 decomment(line); |
32873 | 1067 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1068 if (!*line) |
32873 | 1069 continue; |
23077 | 1070 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1071 cutItem(line, item, '=', 0); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1072 cutItem(line, param, '=', 1); |
33075 | 1073 strlower(item); |
32873 | 1074 |
33076
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1075 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
|
1076 if (!strcmp(item, skinItem[i].name)) { |
35360 | 1077 if (skinItem[i].func(param) != 0) { |
1078 fclose(skinfile); | |
32873 | 1079 return -2; |
35360 | 1080 } else |
33076
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1081 break; |
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1082 } |
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1083 } |
33077 | 1084 |
1085 if (i == FF_ARRAY_ELEMS(skinItem)) { | |
1086 skin_error(MSGTR_SKIN_UNKNOWN_ITEM, item); | |
35360 | 1087 fclose(skinfile); |
33077 | 1088 return -2; |
1089 } | |
32873 | 1090 } |
1091 | |
35360 | 1092 fclose(skinfile); |
1093 | |
32873 | 1094 if (linenumber == 0) { |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1095 mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_SkinFileNotReadable, skinfname); |
32873 | 1096 return -1; |
1097 } | |
1098 | |
1099 return 0; | |
23077 | 1100 } |