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