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