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