Mercurial > mplayer.hg
annotate gui/skin/skin.c @ 35673:2b7f93ef711d
Make functions static that only have file scope.
author | ib |
---|---|
date | Thu, 17 Jan 2013 16:51:50 +0000 |
parents | 782461b26312 |
children | 6fd886ce32b9 |
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" |
35525 | 29 #include "gui/app/app.h" |
30 #include "gui/app/gui.h" | |
35529 | 31 #include "gui/dialog/dialog.h" |
33023 | 32 #include "gui/interface.h" |
33046 | 33 #include "gui/util/cut.h" |
33048 | 34 #include "gui/util/string.h" |
23077 | 35 |
26382
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 * | |
35493 | 82 * @return #True (ok) or #False (error) |
33968 | 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); |
35493 | 88 return False; |
32873 | 89 } |
90 | |
35493 | 91 return True; |
33054
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 * | |
35493 | 99 * @return #True (ok) or #False (error) |
33968 | 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); |
35493 | 105 return False; |
32873 | 106 } |
23077 | 107 |
35493 | 108 return True; |
33054
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 Get next free item in current @a window. | |
130 * | |
131 * @return pointer to next free item (ok) or NULL (error) | |
132 */ | |
33098 | 133 static wItem *next_item(void) |
134 { | |
135 wItem *item = NULL; | |
136 | |
137 if (*currWinItemIdx < MAX_ITEMS - 1) { | |
138 (*currWinItemIdx)++; | |
139 item = &currWinItems[*currWinItemIdx]; | |
140 } else | |
141 skin_error(MSGTR_SKIN_TooManyItemsDeclared); | |
142 | |
143 return item; | |
144 } | |
145 | |
33968 | 146 /** |
147 * @brief Parse a @a section definition. | |
148 * | |
149 * Syntax: section=movieplayer | |
150 * | |
151 * @param in definition to be analyzed | |
152 * | |
153 * @return 0 (ok) or 1 (error) | |
154 */ | |
33106 | 155 static int item_section(char *in) |
23077 | 156 { |
33064 | 157 if (skin) { |
158 skin_error(MSGTR_SKIN_ERROR_ITEM, "section"); | |
159 return 1; | |
160 } | |
161 | |
33055 | 162 if (!strcmp(strlower(in), "movieplayer")) |
33555 | 163 skin = &guiApp; |
33067 | 164 else { |
165 skin_error(MSGTR_SKIN_UNKNOWN_NAME, in); | |
166 return 1; | |
167 } | |
32873 | 168 |
33985 | 169 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] section: %s\n", in); |
32873 | 170 |
171 return 0; | |
23077 | 172 } |
173 | |
33968 | 174 /** |
175 * @brief Parse an @a end definition. | |
176 * | |
177 * Syntax: end | |
178 * | |
179 * @param in definition to be analyzed | |
180 * | |
181 * @return 0 (ok) or 1 (error) | |
182 */ | |
33106 | 183 static int item_end(char *in) |
23077 | 184 { |
32951 | 185 char *space, *name; |
186 | |
33985 | 187 (void)in; |
188 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
189 if (currWinName[0]) { |
32951 | 190 space = " "; |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
191 name = currWinName; |
32951 | 192 } else { |
193 space = ""; | |
194 name = "section"; | |
195 } | |
196 | |
33106 | 197 if (!section_item("end")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
198 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
199 |
33985 | 200 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %send (%s)\n", space, name); |
32951 | 201 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
202 if (currWinName[0]) { |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
203 currWinName[0] = 0; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
204 currWin = NULL; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
205 currWinItemIdx = NULL; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
206 currWinItems = NULL; |
32873 | 207 } else |
32937 | 208 skin = NULL; |
32873 | 209 |
210 return 0; | |
23077 | 211 } |
212 | |
33968 | 213 /** |
214 * @brief Parse a @a window definition. | |
215 * | |
34697 | 216 * Syntax: window=main|video|playbar|menu |
33968 | 217 * |
218 * @param in definition to be analyzed | |
219 * | |
220 * @return 0 (ok) or 1 (error) | |
221 */ | |
33106 | 222 static int item_window(char *in) |
23077 | 223 { |
33106 | 224 if (!section_item("window")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
225 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
226 |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
227 if (currWinName[0]) { |
33062 | 228 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
|
229 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
230 } |
32873 | 231 |
33083 | 232 strlower(in); |
23077 | 233 |
34697 | 234 if (strcmp(in, "sub") == 0) |
235 strcpy(in, "video"); // legacy | |
236 | |
33083 | 237 if (strcmp(in, "main") == 0) { |
33095 | 238 currWin = &skin->main; |
239 currWinItemIdx = &skin->IndexOfMainItems; | |
240 currWinItems = skin->mainItems; | |
34697 | 241 } else if (strcmp(in, "video") == 0) { |
242 currWin = &skin->video; | |
33083 | 243 currWinItemIdx = NULL; |
244 currWinItems = NULL; | |
245 } else if (strcmp(in, "playbar") == 0) { | |
33555 | 246 currWin = &skin->playbar; |
247 currWinItemIdx = &skin->IndexOfPlaybarItems; | |
248 currWinItems = skin->playbarItems; | |
33083 | 249 } else if (strcmp(in, "menu") == 0) { |
33095 | 250 currWin = &skin->menu; |
251 currWinItemIdx = &skin->IndexOfMenuItems; | |
252 currWinItems = skin->menuItems; | |
33066 | 253 } else { |
33065 | 254 skin_error(MSGTR_SKIN_UNKNOWN_NAME, in); |
33066 | 255 return 1; |
256 } | |
32873 | 257 |
33083 | 258 av_strlcpy(currWinName, in, sizeof(currWinName)); |
259 | |
33985 | 260 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] window: %s\n", currWinName); |
32873 | 261 |
262 return 0; | |
23077 | 263 } |
264 | |
33968 | 265 /** |
266 * @brief Parse a @a base definition. | |
267 * | |
268 * Syntax: base=image,x,y[,width,height] | |
269 * | |
270 * @param in definition to be analyzed | |
271 * | |
272 * @return 0 (ok) or 1 (error) | |
273 */ | |
33106 | 274 static int item_base(char *in) |
23077 | 275 { |
33090 | 276 unsigned char fname[256]; |
33089 | 277 unsigned char file[512]; |
32873 | 278 int x, y; |
33089 | 279 int w = 0, h = 0; |
34697 | 280 int is_video, is_bar, is_menu; |
32873 | 281 |
33106 | 282 if (!window_item("base")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
283 return 1; |
23077 | 284 |
34697 | 285 is_video = (strcmp(currWinName, "video") == 0); |
34698 | 286 is_bar = (strcmp(currWinName, "playbar") == 0); |
287 is_menu = (strcmp(currWinName, "menu") == 0); | |
33104 | 288 |
32873 | 289 cutItem(in, fname, ',', 0); |
33089 | 290 x = cutItemToInt(in, ',', 1); |
291 y = cutItemToInt(in, ',', 2); | |
292 w = cutItemToInt(in, ',', 3); | |
293 h = cutItemToInt(in, ',', 4); | |
32873 | 294 |
33985 | 295 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image: %s", fname); |
23077 | 296 |
33105 | 297 currWin->type = itBase; |
33104 | 298 |
33105 | 299 if (!is_menu) { |
300 currWin->x = x; | |
301 currWin->y = y; | |
32873 | 302 |
33985 | 303 mp_msg(MSGT_GPLAYER, MSGL_DBG2, " %d,%d", x, y); |
33105 | 304 } |
32951 | 305 |
33985 | 306 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "\n"); |
32873 | 307 |
33105 | 308 av_strlcpy(file, path, sizeof(file)); |
309 av_strlcat(file, fname, sizeof(file)); | |
32873 | 310 |
33969 | 311 if (skinImageRead(file, &currWin->Bitmap) != 0) |
33105 | 312 return 1; |
32873 | 313 |
33105 | 314 currWin->width = currWin->Bitmap.Width; |
315 currWin->height = currWin->Bitmap.Height; | |
32873 | 316 |
34697 | 317 if (is_video) { |
33089 | 318 if (w && h) { |
33096 | 319 currWin->width = w; |
320 currWin->height = h; | |
32873 | 321 } |
33105 | 322 } |
32873 | 323 |
33985 | 324 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", currWin->width, currWin->height); |
32951 | 325 |
34697 | 326 if (!is_video) { |
33555 | 327 if (!bpRenderMask(&currWin->Bitmap, &currWin->Mask)) { |
33114 | 328 skin_error(MSGTR_SKIN_NotEnoughMemory); |
329 return 1; | |
330 } | |
33985 | 331 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] mask: %lux%lu\n", currWin->Mask.Width, currWin->Mask.Height); |
33105 | 332 } |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
333 |
33105 | 334 if (is_bar) |
35493 | 335 skin->playbarIsPresent = True; |
33105 | 336 if (is_menu) |
35493 | 337 skin->menuIsPresent = True; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
338 |
32873 | 339 return 0; |
23077 | 340 } |
341 | |
33968 | 342 /** |
343 * @brief Parse a @a background definition. | |
344 * | |
345 * Syntax: background=R,G,B | |
346 * | |
347 * @param in definition to be analyzed | |
348 * | |
349 * @return 0 (ok) or 1 (error) | |
350 */ | |
33106 | 351 static int item_background(char *in) |
23077 | 352 { |
33106 | 353 if (!window_item("background")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
354 return 1; |
23077 | 355 |
33058 | 356 if (in_window("main")) |
357 return 1; | |
33088 | 358 if (in_window("playbar")) |
359 return 1; | |
33058 | 360 if (in_window("menu")) |
361 return 1; | |
23077 | 362 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
363 currWin->R = cutItemToInt(in, ',', 0); |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
364 currWin->G = cutItemToInt(in, ',', 1); |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
365 currWin->B = cutItemToInt(in, ',', 2); |
23077 | 366 |
33985 | 367 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] background color: #%02x%02x%02x\n", currWin->R, currWin->G, currWin->B); |
23077 | 368 |
32873 | 369 return 0; |
23077 | 370 } |
371 | |
33968 | 372 /** |
373 * @brief Parse a @a button definition. | |
374 * | |
375 * Syntax: button=image,x,y,width,height,message | |
376 * | |
377 * @param in definition to be analyzed | |
378 * | |
379 * @return 0 (ok) or 1 (error) | |
380 */ | |
33106 | 381 static int item_button(char *in) |
23077 | 382 { |
33090 | 383 unsigned char fname[256]; |
33089 | 384 unsigned char file[512]; |
385 int x, y, w, h, message; | |
32873 | 386 char msg[32]; |
33098 | 387 wItem *item; |
32873 | 388 |
33106 | 389 if (!window_item("button")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
390 return 1; |
32873 | 391 |
34697 | 392 if (in_window("video")) |
33058 | 393 return 1; |
394 if (in_window("menu")) | |
395 return 1; | |
23077 | 396 |
32873 | 397 cutItem(in, fname, ',', 0); |
33089 | 398 x = cutItemToInt(in, ',', 1); |
399 y = cutItemToInt(in, ',', 2); | |
400 w = cutItemToInt(in, ',', 3); | |
401 h = cutItemToInt(in, ',', 4); | |
32873 | 402 cutItem(in, msg, ',', 5); |
403 | |
33071 | 404 message = appFindMessage(msg); |
405 | |
406 if (message == -1) { | |
407 skin_error(MSGTR_SKIN_UnknownMessage, msg); | |
408 return 1; | |
409 } | |
410 | |
33985 | 411 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] button image: %s %d,%d\n", fname, x, y); |
412 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", msg, message); | |
413 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
|
414 |
33098 | 415 item = next_item(); |
416 | |
417 if (!item) | |
418 return 1; | |
419 | |
420 item->type = itButton; | |
421 item->x = x; | |
422 item->y = y; | |
423 item->width = w; | |
424 item->height = h; | |
425 item->message = message; | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
426 item->pressed = btnReleased; |
23077 | 427 |
33098 | 428 if (item->message == evPauseSwitchToPlay) |
429 item->pressed = btnDisabled; | |
23077 | 430 |
33098 | 431 item->Bitmap.Image = NULL; |
32873 | 432 |
433 if (strcmp(fname, "NULL") != 0) { | |
33089 | 434 av_strlcpy(file, path, sizeof(file)); |
435 av_strlcat(file, fname, sizeof(file)); | |
32873 | 436 |
33969 | 437 if (skinImageRead(file, &item->Bitmap) != 0) |
32873 | 438 return 1; |
32951 | 439 |
33985 | 440 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); |
32873 | 441 } |
442 | |
443 return 0; | |
23077 | 444 } |
445 | |
33968 | 446 /** |
447 * @brief Parse a @a selected definition. | |
448 * | |
449 * Syntax: selected=image | |
450 * | |
451 * @param in definition to be analyzed | |
452 * | |
453 * @return 0 (ok) or 1 (error) | |
454 */ | |
33106 | 455 static int item_selected(char *in) |
32873 | 456 { |
33089 | 457 unsigned char file[512]; |
33096 | 458 wItem *currItem; |
32873 | 459 |
33106 | 460 if (!window_item("selected")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
461 return 1; |
32873 | 462 |
33058 | 463 if (in_window("main")) |
464 return 1; | |
34697 | 465 if (in_window("video")) |
33058 | 466 return 1; |
467 if (in_window("playbar")) | |
468 return 1; | |
32873 | 469 |
33985 | 470 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
|
471 |
33096 | 472 currItem = &skin->menuSelected; |
473 currItem->type = itBase; | |
32873 | 474 |
33089 | 475 av_strlcpy(file, path, sizeof(file)); |
33091 | 476 av_strlcat(file, in, sizeof(file)); |
32873 | 477 |
33969 | 478 if (skinImageRead(file, &currItem->Bitmap) != 0) |
32873 | 479 return 1; |
480 | |
33096 | 481 currItem->width = currItem->Bitmap.Width; |
482 currItem->height = currItem->Bitmap.Height; | |
32873 | 483 |
33985 | 484 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", currItem->width, currItem->height); |
32873 | 485 |
486 return 0; | |
487 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
488 |
33968 | 489 /** |
490 * @brief Parse a @a menu definition. | |
491 * | |
492 * Syntax: menu=x,y,width,height,message | |
493 * | |
494 * @param in definition to be analyzed | |
495 * | |
496 * @return 0 (ok) or 1 (error) | |
497 */ | |
33106 | 498 static int item_menu(char *in) |
32873 | 499 { |
33089 | 500 int x, y, w, h, message; |
33071 | 501 char msg[32]; |
33096 | 502 wItem *item; |
32873 | 503 |
33106 | 504 if (!window_item("menu")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
505 return 1; |
32873 | 506 |
33058 | 507 if (in_window("main")) |
508 return 1; | |
34697 | 509 if (in_window("video")) |
33058 | 510 return 1; |
511 if (in_window("playbar")) | |
512 return 1; | |
32873 | 513 |
33089 | 514 x = cutItemToInt(in, ',', 0); |
515 y = cutItemToInt(in, ',', 1); | |
516 w = cutItemToInt(in, ',', 2); | |
517 h = cutItemToInt(in, ',', 3); | |
33071 | 518 cutItem(in, msg, ',', 4); |
519 | |
520 message = appFindMessage(msg); | |
23077 | 521 |
33071 | 522 if (message == -1) { |
523 skin_error(MSGTR_SKIN_UnknownMessage, msg); | |
524 return 1; | |
525 } | |
32873 | 526 |
33098 | 527 item = next_item(); |
528 | |
529 if (!item) | |
530 return 1; | |
531 | |
33100 | 532 item->type = itMenu; |
33096 | 533 item->x = x; |
534 item->y = y; | |
535 item->width = w; | |
536 item->height = h; | |
537 item->message = message; | |
23077 | 538 |
33985 | 539 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] item #%d: %d,%d %dx%d\n", *currWinItemIdx, x, y, w, h); |
540 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", msg, message); | |
23077 | 541 |
33096 | 542 item->Bitmap.Image = NULL; |
33053 | 543 |
32873 | 544 return 0; |
23077 | 545 } |
546 | |
33968 | 547 /** |
548 * @brief Parse a @a hpotmeter definition. | |
549 * | |
550 * Syntax: hpotmeter=button,bwidth,bheight,phases,numphases,default,x,y,width,height,message | |
551 * | |
552 * @param in definition to be analyzed | |
553 * | |
554 * @return 0 (ok) or 1 (error) | |
555 */ | |
33106 | 556 static int item_hpotmeter(char *in) |
32873 | 557 { |
33090 | 558 unsigned char pfname[256]; |
559 unsigned char phfname[256]; | |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
560 unsigned char buf[512]; |
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
561 int pwidth, pheight, ph, d, x, y, w, h, message; |
32873 | 562 wItem *item; |
23077 | 563 |
33106 | 564 if (!window_item("h/v potmeter")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
565 return 1; |
23077 | 566 |
34697 | 567 if (in_window("video")) |
33058 | 568 return 1; |
569 if (in_window("menu")) | |
570 return 1; | |
23077 | 571 |
32873 | 572 cutItem(in, pfname, ',', 0); |
32911 | 573 pwidth = cutItemToInt(in, ',', 1); |
574 pheight = cutItemToInt(in, ',', 2); | |
32873 | 575 cutItem(in, phfname, ',', 3); |
576 ph = cutItemToInt(in, ',', 4); | |
577 d = cutItemToInt(in, ',', 5); | |
578 x = cutItemToInt(in, ',', 6); | |
579 y = cutItemToInt(in, ',', 7); | |
33089 | 580 w = cutItemToInt(in, ',', 8); |
581 h = cutItemToInt(in, ',', 9); | |
582 cutItem(in, buf, ',', 10); | |
32873 | 583 |
33089 | 584 message = appFindMessage(buf); |
23077 | 585 |
33069 | 586 if (message == -1) { |
33089 | 587 skin_error(MSGTR_SKIN_UnknownMessage, buf); |
33069 | 588 return 1; |
589 } | |
590 | |
33985 | 591 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] h/v potmeter image: %s %d,%d %dx%d\n", phfname, x, y, w, h); |
592 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] button image: %s %dx%d\n", pfname, pwidth, pheight); | |
593 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] numphases: %d, default: %d%%\n", ph, d); | |
594 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", buf, message); | |
23077 | 595 |
33098 | 596 item = next_item(); |
597 | |
598 if (!item) | |
599 return 1; | |
600 | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
601 item->type = itHPotmeter; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
602 item->x = x; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
603 item->y = y; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
604 item->width = w; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
605 item->height = h; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
606 item->pwidth = pwidth; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
607 item->pheight = pheight; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
608 item->numphases = ph; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
609 item->value = (float)d; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
610 item->message = message; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
611 item->pressed = btnReleased; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
612 |
32873 | 613 item->Bitmap.Image = NULL; |
23077 | 614 |
32873 | 615 if (strcmp(phfname, "NULL") != 0) { |
33089 | 616 av_strlcpy(buf, path, sizeof(buf)); |
617 av_strlcat(buf, phfname, sizeof(buf)); | |
32873 | 618 |
33969 | 619 if (skinImageRead(buf, &item->Bitmap) != 0) |
32873 | 620 return 1; |
32951 | 621 |
33985 | 622 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (potmeter bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); |
32873 | 623 } |
624 | |
625 item->Mask.Image = NULL; | |
23077 | 626 |
32873 | 627 if (strcmp(pfname, "NULL") != 0) { |
33089 | 628 av_strlcpy(buf, path, sizeof(buf)); |
629 av_strlcat(buf, pfname, sizeof(buf)); | |
32873 | 630 |
33969 | 631 if (skinImageRead(buf, &item->Mask) != 0) |
32873 | 632 return 1; |
32951 | 633 |
33985 | 634 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (button bitmap: %lux%lu)\n", item->Mask.Width, item->Mask.Height); |
32873 | 635 } |
636 | |
637 return 0; | |
23077 | 638 } |
639 | |
33968 | 640 /** |
641 * @brief Parse a @a vpotmeter definition. | |
642 * | |
643 * Syntax: vpotmeter=button,bwidth,bheight,phases,numphases,default,x,y,width,height,message | |
644 * | |
645 * @param in definition to be analyzed | |
646 * | |
647 * @return 0 (ok) or 1 (error) | |
648 */ | |
33106 | 649 static int item_vpotmeter(char *in) |
23077 | 650 { |
33056 | 651 int r; |
32873 | 652 wItem *item; |
23077 | 653 |
33106 | 654 r = item_hpotmeter(in); |
33056 | 655 |
656 if (r == 0) { | |
33057 | 657 item = &currWinItems[*currWinItemIdx]; |
658 item->type = itVPotmeter; | |
33056 | 659 } |
33053 | 660 |
32873 | 661 return r; |
23077 | 662 } |
663 | |
33968 | 664 /** |
665 * @brief Parse a @a potmeter definition. | |
666 * | |
667 * Syntax: potmeter=phases,numphases,default,x,y,width,height,message | |
668 * | |
669 * @param in definition to be analyzed | |
670 * | |
671 * @return 0 (ok) or 1 (error) | |
672 */ | |
33106 | 673 static int item_potmeter(char *in) |
32873 | 674 { |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
675 unsigned char phfname[256]; |
33089 | 676 unsigned char buf[512]; |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
677 int ph, d, x, y, w, h, message; |
32873 | 678 wItem *item; |
23077 | 679 |
33106 | 680 if (!window_item("potmeter")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
681 return 1; |
23077 | 682 |
34697 | 683 if (in_window("video")) |
33058 | 684 return 1; |
685 if (in_window("menu")) | |
686 return 1; | |
23077 | 687 |
32873 | 688 cutItem(in, phfname, ',', 0); |
689 ph = cutItemToInt(in, ',', 1); | |
690 d = cutItemToInt(in, ',', 2); | |
691 x = cutItemToInt(in, ',', 3); | |
692 y = cutItemToInt(in, ',', 4); | |
33089 | 693 w = cutItemToInt(in, ',', 5); |
694 h = cutItemToInt(in, ',', 6); | |
695 cutItem(in, buf, ',', 7); | |
32873 | 696 |
33089 | 697 message = appFindMessage(buf); |
23077 | 698 |
33069 | 699 if (message == -1) { |
33089 | 700 skin_error(MSGTR_SKIN_UnknownMessage, buf); |
33069 | 701 return 1; |
702 } | |
703 | |
33985 | 704 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] potmeter image: %s %d,%d %dx%d\n", phfname, x, y, w, h); |
705 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] numphases: %d, default: %d%%\n", ph, d); | |
706 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", buf, message); | |
23077 | 707 |
33098 | 708 item = next_item(); |
709 | |
710 if (!item) | |
711 return 1; | |
712 | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
713 item->type = itPotmeter; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
714 item->x = x; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
715 item->y = y; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
716 item->width = w; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
717 item->height = h; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
718 item->numphases = ph; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
719 item->value = (float)d; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
720 item->message = message; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
721 |
32873 | 722 item->Bitmap.Image = NULL; |
23077 | 723 |
32873 | 724 if (strcmp(phfname, "NULL") != 0) { |
33089 | 725 av_strlcpy(buf, path, sizeof(buf)); |
726 av_strlcat(buf, phfname, sizeof(buf)); | |
32873 | 727 |
33969 | 728 if (skinImageRead(buf, &item->Bitmap) != 0) |
32873 | 729 return 1; |
32951 | 730 |
33985 | 731 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); |
32873 | 732 } |
733 | |
734 return 0; | |
23077 | 735 } |
736 | |
33968 | 737 /** |
738 * @brief Parse a @a font definition. | |
739 * | |
740 * Syntax: font=fontfile | |
741 * | |
742 * @param in definition to be analyzed | |
743 * | |
744 * @return 0 (ok) or 1 (error) | |
745 */ | |
33106 | 746 static int item_font(char *in) |
32873 | 747 { |
33092
83052a4ac698
Use more appropriate name for variable and reduce it to reasonable size.
ib
parents:
33091
diff
changeset
|
748 char fnt[256]; |
23077 | 749 |
33106 | 750 if (!window_item("font")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
751 return 1; |
23077 | 752 |
34697 | 753 if (in_window("video")) |
33058 | 754 return 1; |
755 if (in_window("menu")) | |
756 return 1; | |
23077 | 757 |
33092
83052a4ac698
Use more appropriate name for variable and reduce it to reasonable size.
ib
parents:
33091
diff
changeset
|
758 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
|
759 // reasons with a meanwhile depreciated second parameter. |
33099
0b17f6bed6fc
Don't needlessly store font information in the wItems array
ib
parents:
33098
diff
changeset
|
760 switch (fntRead(path, fnt)) { |
32873 | 761 case -1: |
33097 | 762 skin_error(MSGTR_SKIN_NotEnoughMemory); |
32873 | 763 return 1; |
23077 | 764 |
32873 | 765 case -2: |
33022 | 766 skin_error(MSGTR_SKIN_FONT_TooManyFontsDeclared); |
32873 | 767 return 1; |
768 | |
769 case -3: | |
33022 | 770 skin_error(MSGTR_SKIN_FONT_FontFileNotFound); |
32873 | 771 return 1; |
772 | |
773 case -4: | |
33022 | 774 skin_error(MSGTR_SKIN_FONT_FontImageNotFound); |
32873 | 775 return 1; |
776 } | |
777 | |
33985 | 778 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, fntFindID(fnt)); |
32951 | 779 |
32873 | 780 return 0; |
23077 | 781 } |
782 | |
33968 | 783 /** |
784 * @brief Parse a @a slabel definition. | |
785 * | |
786 * Syntax: slabel=x,y,fontfile,"text" | |
787 * | |
788 * @param in definition to be analyzed | |
789 * | |
790 * @return 0 (ok) or 1 (error) | |
791 */ | |
33106 | 792 static int item_slabel(char *in) |
23077 | 793 { |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
794 int x, y, id; |
33090 | 795 char fnt[256]; |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
796 char txt[256]; |
32873 | 797 wItem *item; |
798 | |
33106 | 799 if (!window_item("slabel")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
800 return 1; |
23077 | 801 |
34697 | 802 if (in_window("video")) |
33058 | 803 return 1; |
804 if (in_window("menu")) | |
805 return 1; | |
32873 | 806 |
807 x = cutItemToInt(in, ',', 0); | |
808 y = cutItemToInt(in, ',', 1); | |
33089 | 809 cutItem(in, fnt, ',', 2); |
810 cutItem(in, txt, ',', 3); | |
811 cutItem(txt, txt, '"', 1); | |
32951 | 812 |
33985 | 813 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] slabel: \"%s\"\n", txt); |
814 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] pos: %d,%d\n", x, y); | |
23077 | 815 |
33089 | 816 id = fntFindID(fnt); |
23077 | 817 |
32873 | 818 if (id < 0) { |
33097 | 819 skin_error(MSGTR_SKIN_FONT_NonExistentFont, fnt); |
32873 | 820 return 1; |
821 } | |
23077 | 822 |
33985 | 823 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, id); |
23077 | 824 |
33098 | 825 item = next_item(); |
826 | |
827 if (!item) | |
828 return 1; | |
829 | |
32873 | 830 item->type = itSLabel; |
831 item->x = x; | |
832 item->y = y; | |
833 item->width = -1; | |
834 item->height = -1; | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
835 item->fontid = id; |
33089 | 836 item->label = strdup(txt); |
23077 | 837 |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
838 if (!item->label) { |
33097 | 839 skin_error(MSGTR_SKIN_NotEnoughMemory); |
32873 | 840 return 1; |
841 } | |
23077 | 842 |
32873 | 843 return 0; |
23077 | 844 } |
845 | |
33968 | 846 /** |
847 * @brief Parse a @a dlabel definition. | |
848 * | |
849 * Syntax: dlabel=x,y,width,align,fontfile,"text" | |
850 * | |
851 * @param in definition to be analyzed | |
852 * | |
853 * @return 0 (ok) or 1 (error) | |
854 */ | |
33106 | 855 static int item_dlabel(char *in) |
32873 | 856 { |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
857 int x, y, w, a, id; |
33090 | 858 char fnt[256]; |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
859 char txt[256]; |
32873 | 860 wItem *item; |
23077 | 861 |
33106 | 862 if (!window_item("dlabel")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
863 return 1; |
23077 | 864 |
34697 | 865 if (in_window("video")) |
33058 | 866 return 1; |
867 if (in_window("menu")) | |
868 return 1; | |
32873 | 869 |
33089 | 870 x = cutItemToInt(in, ',', 0); |
871 y = cutItemToInt(in, ',', 1); | |
872 w = cutItemToInt(in, ',', 2); | |
873 a = cutItemToInt(in, ',', 3); | |
874 cutItem(in, fnt, ',', 4); | |
875 cutItem(in, txt, ',', 5); | |
876 cutItem(txt, txt, '"', 1); | |
32951 | 877 |
33985 | 878 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] dlabel: \"%s\"\n", txt); |
879 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] pos: %d,%d\n", x, y); | |
880 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] width: %d, align: %d\n", w, a); | |
23077 | 881 |
33089 | 882 id = fntFindID(fnt); |
23077 | 883 |
32873 | 884 if (id < 0) { |
33097 | 885 skin_error(MSGTR_SKIN_FONT_NonExistentFont, fnt); |
32873 | 886 return 1; |
887 } | |
23077 | 888 |
33985 | 889 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, id); |
23077 | 890 |
33098 | 891 item = next_item(); |
892 | |
893 if (!item) | |
894 return 1; | |
895 | |
32873 | 896 item->type = itDLabel; |
897 item->x = x; | |
898 item->y = y; | |
33089 | 899 item->width = w; |
32873 | 900 item->height = -1; |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
901 item->fontid = id; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
902 item->align = a; |
33089 | 903 item->label = strdup(txt); |
23077 | 904 |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
905 if (!item->label) { |
33097 | 906 skin_error(MSGTR_SKIN_NotEnoughMemory); |
32873 | 907 return 1; |
908 } | |
23077 | 909 |
32873 | 910 return 0; |
23077 | 911 } |
912 | |
33968 | 913 /** |
914 * @brief Parse a @a decoration definition. | |
915 * | |
916 * Syntax: decoration=enable|disable | |
917 * | |
918 * @param in definition to be analyzed | |
919 * | |
920 * @return 0 (ok) or 1 (error) | |
921 */ | |
33106 | 922 static int item_decoration(char *in) |
23077 | 923 { |
33106 | 924 if (!window_item("decoration")) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
925 return 1; |
32873 | 926 |
34697 | 927 if (in_window("video")) |
33058 | 928 return 1; |
929 if (in_window("playbar")) | |
930 return 1; | |
931 if (in_window("menu")) | |
932 return 1; | |
32873 | 933 |
33086 | 934 strlower(in); |
32873 | 935 |
33086 | 936 if (strcmp(in, "enable") != 0 && strcmp(in, "disable") != 0) { |
937 skin_error(MSGTR_SKIN_UnknownParameter, in); | |
32873 | 938 return 1; |
939 } | |
23077 | 940 |
33087 | 941 skin->mainDecoration = (strcmp(in, "enable") == 0); |
23077 | 942 |
33985 | 943 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] decoration: %s\n", in); |
32873 | 944 |
945 return 0; | |
23077 | 946 } |
947 | |
33968 | 948 /** |
949 * @brief Parsing functions responsible for skin item definitions. | |
950 */ | |
32878 | 951 static _item skinItem[] = { |
33106 | 952 { "background", item_background }, |
953 { "base", item_base }, | |
954 { "button", item_button }, | |
955 { "decoration", item_decoration }, | |
956 { "dlabel", item_dlabel }, | |
957 { "end", item_end }, | |
958 { "font", item_font }, | |
959 { "hpotmeter", item_hpotmeter }, | |
960 { "menu", item_menu }, | |
961 { "potmeter", item_potmeter }, | |
962 { "section", item_section }, | |
963 { "selected", item_selected }, | |
964 { "slabel", item_slabel }, | |
965 { "vpotmeter", item_vpotmeter }, | |
966 { "window", item_window } | |
32873 | 967 }; |
968 | |
33968 | 969 /** |
35662 | 970 * @brief Read a skin @a image file. |
971 * | |
972 * @param fname filename (with path) | |
973 * @param img pointer suitable to store the image data | |
974 * | |
975 * @return return code of #bpRead() | |
976 */ | |
977 int skinImageRead(char *fname, guiImage *img) | |
978 { | |
979 int i = bpRead(fname, img); | |
980 | |
981 switch (i) { | |
982 case -1: | |
983 skin_error(MSGTR_SKIN_BITMAP_16bit, fname); | |
984 break; | |
985 | |
986 case -2: | |
987 skin_error(MSGTR_SKIN_BITMAP_FileNotFound, fname); | |
988 break; | |
989 | |
990 case -5: | |
991 skin_error(MSGTR_SKIN_BITMAP_PNGReadError, fname); | |
992 break; | |
993 | |
994 case -8: | |
995 skin_error(MSGTR_SKIN_BITMAP_ConversionError, fname); | |
996 break; | |
997 } | |
998 | |
999 return i; | |
1000 } | |
1001 | |
1002 /** | |
33968 | 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 } |