Mercurial > mplayer.hg
annotate gui/skin/skin.c @ 37082:9e3b2b71a146
Remove pointless statement.
The 'menu' item doesn't have an image,
so no need to care about Bitmap.Image.
author | ib |
---|---|
date | Sat, 26 Apr 2014 16:30:54 +0000 |
parents | b28b632efeef |
children |
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 | |
37053 | 24 #include <math.h> |
23077 | 25 #include <stdio.h> |
26 #include <string.h> | |
27 | |
32873 | 28 #include "skin.h" |
23077 | 29 #include "font.h" |
36032 | 30 #include "gui/interface.h" |
35525 | 31 #include "gui/app/app.h" |
32 #include "gui/app/gui.h" | |
35529 | 33 #include "gui/dialog/dialog.h" |
37024 | 34 #include "gui/util/misc.h" |
33048 | 35 #include "gui/util/string.h" |
23077 | 36 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
37 #include "help_mp.h" |
36032 | 38 #include "mp_msg.h" |
37053 | 39 #include "libavutil/attributes.h" |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23077
diff
changeset
|
40 #include "libavutil/avstring.h" |
32944 | 41 #include "libavutil/common.h" |
23077 | 42 |
32873 | 43 typedef struct { |
44 const char *name; | |
45 int (*func)(char *in); | |
46 } _item; | |
23077 | 47 |
33749 | 48 char *skinDirInHome; |
36043 | 49 char *skinDirInData; |
33749 | 50 |
32937 | 51 static guiItems *skin; |
23077 | 52 |
32873 | 53 static int linenumber; |
37028 | 54 static unsigned char currItem[32]; |
32873 | 55 static unsigned char path[512]; |
23077 | 56 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
57 static unsigned char currWinName[32]; |
35688 | 58 static guiItem *currWin; |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
59 static int *currWinItemIdx; |
35688 | 60 static guiItem *currWinItems; |
23077 | 61 |
33968 | 62 /** |
36891
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
63 * @brief Print a legacy information on an entry. |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
64 * |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
65 * @param old identifier (and deprecated entry) |
37065 | 66 * @param data string necessary for checking and to print the information on @a old |
36891
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
67 */ |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
68 static void skin_legacy(const char *old, const char *data) |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
69 { |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
70 const char *p; |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
71 |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
72 if (strcmp(old, "fontid") == 0) { |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
73 p = strchr(data, ','); |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
74 |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
75 if (p) |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
76 mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_GUI_MSG_SkinLegacy, linenumber, p, "font = fontfile"); |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
77 } else if (strcmp(old, "$l") == 0) { |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
78 p = strstr(old, data); |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
79 |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
80 if (p && (p == data || p[-1] != '$')) |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
81 mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_GUI_MSG_SkinLegacy, linenumber, old, "$p"); |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
82 } else if (strcmp(old, "evSetURL") == 0 && strcmp(data, old) == 0) |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
83 mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_GUI_MSG_SkinLegacy, linenumber, old, "evLoadURL"); |
36892 | 84 else if (strcmp(old, "sub") == 0 || strcmp(old, "potmeter") == 0) |
36891
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
85 mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_GUI_MSG_SkinLegacy, linenumber, old, data); |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
86 } |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
87 |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
88 /** |
33968 | 89 * @brief Display a skin error message. |
90 * | |
91 * @param format format string | |
92 * @param ... arguments | |
93 */ | |
33022 | 94 static void skin_error(const char *format, ...) |
23077 | 95 { |
32873 | 96 char p[512]; |
97 va_list ap; | |
98 | |
99 va_start(ap, format); | |
100 vsnprintf(p, sizeof(p), format, ap); | |
101 va_end(ap); | |
102 | |
36694 | 103 gmp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_GUI_MSG_SkinErrorMessage, linenumber, p); |
23077 | 104 } |
105 | |
33968 | 106 /** |
107 * @brief Check whether a @a section definition has started. | |
108 * | |
109 * @param item name of the item to be put in a message in case of an error | |
110 * | |
35493 | 111 * @return #True (ok) or #False (error) |
33968 | 112 */ |
33106 | 113 static int section_item(char *item) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
114 { |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
115 if (!skin) { |
36694 | 116 skin_error(MSGTR_GUI_MSG_SkinErrorSection, item); |
35493 | 117 return False; |
32873 | 118 } |
119 | |
35493 | 120 return True; |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
121 } |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
122 |
33968 | 123 /** |
124 * @brief Check whether a @a window definition has started. | |
125 * | |
126 * @param item name of the item to be put in a message in case of an error | |
127 * | |
35493 | 128 * @return #True (ok) or #False (error) |
33968 | 129 */ |
33106 | 130 static int window_item(char *item) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
131 { |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
132 if (!currWinName[0]) { |
36694 | 133 skin_error(MSGTR_GUI_MSG_SkinErrorWindow, item); |
35493 | 134 return False; |
32873 | 135 } |
23077 | 136 |
35493 | 137 return True; |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
138 } |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
139 |
33968 | 140 /** |
141 * @brief Check whether a specific @a window definition has started. | |
142 * | |
143 * @param name name of the window to be checked | |
144 * | |
145 * @return 0 (ok) or 1 (error) | |
146 */ | |
33058 | 147 static int in_window(char *name) |
148 { | |
149 if (strcmp(currWinName, name) == 0) { | |
36694 | 150 skin_error(MSGTR_GUI_MSG_SkinErrorItem, name); |
33058 | 151 return 1; |
32873 | 152 } |
153 | |
33058 | 154 return 0; |
155 } | |
156 | |
33968 | 157 /** |
158 * @brief Get next free item in current @a window. | |
159 * | |
160 * @return pointer to next free item (ok) or NULL (error) | |
161 */ | |
35688 | 162 static guiItem *next_item(void) |
33098 | 163 { |
35688 | 164 guiItem *item = NULL; |
33098 | 165 |
166 if (*currWinItemIdx < MAX_ITEMS - 1) { | |
167 (*currWinItemIdx)++; | |
168 item = &currWinItems[*currWinItemIdx]; | |
169 } else | |
36694 | 170 skin_error(MSGTR_GUI_MSG_SkinTooManyItems); |
33098 | 171 |
172 return item; | |
173 } | |
174 | |
33968 | 175 /** |
176 * @brief Parse a @a section definition. | |
177 * | |
178 * Syntax: section=movieplayer | |
179 * | |
180 * @param in definition to be analyzed | |
181 * | |
182 * @return 0 (ok) or 1 (error) | |
183 */ | |
33106 | 184 static int item_section(char *in) |
23077 | 185 { |
33064 | 186 if (skin) { |
37028 | 187 skin_error(MSGTR_GUI_MSG_SkinErrorItem, currItem); |
33064 | 188 return 1; |
189 } | |
190 | |
33055 | 191 if (!strcmp(strlower(in), "movieplayer")) |
33555 | 192 skin = &guiApp; |
33067 | 193 else { |
36694 | 194 skin_error(MSGTR_GUI_MSG_SkinUnknownName, in); |
33067 | 195 return 1; |
196 } | |
32873 | 197 |
37028 | 198 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %s: %s\n", currItem, in); |
32873 | 199 |
200 return 0; | |
23077 | 201 } |
202 | |
33968 | 203 /** |
204 * @brief Parse an @a end definition. | |
205 * | |
206 * Syntax: end | |
207 * | |
208 * @param in definition to be analyzed | |
209 * | |
210 * @return 0 (ok) or 1 (error) | |
211 */ | |
33106 | 212 static int item_end(char *in) |
23077 | 213 { |
32951 | 214 char *space, *name; |
215 | |
33985 | 216 (void)in; |
217 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
218 if (currWinName[0]) { |
32951 | 219 space = " "; |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
220 name = currWinName; |
32951 | 221 } else { |
222 space = ""; | |
223 name = "section"; | |
224 } | |
225 | |
37028 | 226 if (!section_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
227 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
228 |
37028 | 229 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %s%s (%s)\n", space, currItem, name); |
32951 | 230 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
231 if (currWinName[0]) { |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
232 currWinName[0] = 0; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
233 currWin = NULL; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
234 currWinItemIdx = NULL; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
235 currWinItems = NULL; |
32873 | 236 } else |
32937 | 237 skin = NULL; |
32873 | 238 |
239 return 0; | |
23077 | 240 } |
241 | |
33968 | 242 /** |
243 * @brief Parse a @a window definition. | |
244 * | |
34697 | 245 * Syntax: window=main|video|playbar|menu |
33968 | 246 * |
247 * @param in definition to be analyzed | |
248 * | |
249 * @return 0 (ok) or 1 (error) | |
250 */ | |
33106 | 251 static int item_window(char *in) |
23077 | 252 { |
37028 | 253 if (!section_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
254 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
255 |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
256 if (currWinName[0]) { |
37028 | 257 skin_error(MSGTR_GUI_MSG_SkinErrorItem, currItem); |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
258 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
259 } |
32873 | 260 |
33083 | 261 strlower(in); |
23077 | 262 |
36891
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
263 // legacy |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
264 if (strcmp(in, "sub") == 0) { |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
265 strcpy(in, "video"); |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
266 skin_legacy("sub", in); |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
267 } |
34697 | 268 |
33083 | 269 if (strcmp(in, "main") == 0) { |
33095 | 270 currWin = &skin->main; |
271 currWinItemIdx = &skin->IndexOfMainItems; | |
272 currWinItems = skin->mainItems; | |
34697 | 273 } else if (strcmp(in, "video") == 0) { |
274 currWin = &skin->video; | |
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 { |
36694 | 286 skin_error(MSGTR_GUI_MSG_SkinUnknownName, in); |
33066 | 287 return 1; |
288 } | |
32873 | 289 |
33083 | 290 av_strlcpy(currWinName, in, sizeof(currWinName)); |
291 | |
37028 | 292 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %s: %s\n", currItem, 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]; |
37051 | 310 int x, y, w, h; |
34697 | 311 int is_video, is_bar, is_menu; |
32873 | 312 |
37028 | 313 if (!window_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
314 return 1; |
23077 | 315 |
34697 | 316 is_video = (strcmp(currWinName, "video") == 0); |
34698 | 317 is_bar = (strcmp(currWinName, "playbar") == 0); |
318 is_menu = (strcmp(currWinName, "menu") == 0); | |
33104 | 319 |
36991 | 320 cutStr(in, fname, ',', 0); |
321 x = cutInt(in, ',', 1); | |
322 y = cutInt(in, ',', 2); | |
323 w = cutInt(in, ',', 3); | |
324 h = cutInt(in, ',', 4); | |
32873 | 325 |
33985 | 326 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image: %s", fname); |
23077 | 327 |
33105 | 328 currWin->type = itBase; |
33104 | 329 |
33105 | 330 if (!is_menu) { |
331 currWin->x = x; | |
332 currWin->y = y; | |
32873 | 333 |
33985 | 334 mp_msg(MSGT_GPLAYER, MSGL_DBG2, " %d,%d", x, y); |
33105 | 335 } |
32951 | 336 |
33985 | 337 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "\n"); |
32873 | 338 |
35785 | 339 if (is_video && (strcmp(fname, "NULL") == 0)) { |
340 currWin->width = 0; | |
341 currWin->height = 0; | |
342 } else { | |
35786 | 343 av_strlcpy(file, path, sizeof(file)); |
344 av_strlcat(file, fname, sizeof(file)); | |
32873 | 345 |
35786 | 346 if (skinImageRead(file, &currWin->Bitmap) != 0) |
347 return 1; | |
32873 | 348 |
35786 | 349 currWin->width = currWin->Bitmap.Width; |
350 currWin->height = currWin->Bitmap.Height; | |
35785 | 351 } |
32873 | 352 |
34697 | 353 if (is_video) { |
33089 | 354 if (w && h) { |
33096 | 355 currWin->width = w; |
356 currWin->height = h; | |
32873 | 357 } |
33105 | 358 } |
32873 | 359 |
35785 | 360 if (currWin->width == 0 || currWin->height == 0) |
361 return 1; | |
362 | |
36975 | 363 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %s: %dx%d\n", is_video && w && h ? "size" : " bitmap", currWin->width, currWin->height); |
32951 | 364 |
34697 | 365 if (!is_video) { |
33555 | 366 if (!bpRenderMask(&currWin->Bitmap, &currWin->Mask)) { |
36694 | 367 skin_error(MSGTR_GUI_MSG_SkinMemoryError); |
33114 | 368 return 1; |
369 } | |
36996 | 370 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] mask: %ux%u\n", currWin->Mask.Width, currWin->Mask.Height); |
33105 | 371 } |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
372 |
33105 | 373 if (is_bar) |
35493 | 374 skin->playbarIsPresent = True; |
33105 | 375 if (is_menu) |
35493 | 376 skin->menuIsPresent = True; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
377 |
32873 | 378 return 0; |
23077 | 379 } |
380 | |
33968 | 381 /** |
382 * @brief Parse a @a background definition. | |
383 * | |
384 * Syntax: background=R,G,B | |
385 * | |
386 * @param in definition to be analyzed | |
387 * | |
388 * @return 0 (ok) or 1 (error) | |
389 */ | |
33106 | 390 static int item_background(char *in) |
23077 | 391 { |
37028 | 392 if (!window_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
393 return 1; |
23077 | 394 |
33058 | 395 if (in_window("main")) |
396 return 1; | |
33088 | 397 if (in_window("playbar")) |
398 return 1; | |
33058 | 399 if (in_window("menu")) |
400 return 1; | |
23077 | 401 |
36991 | 402 currWin->R = cutInt(in, ',', 0); |
403 currWin->G = cutInt(in, ',', 1); | |
404 currWin->B = cutInt(in, ',', 2); | |
23077 | 405 |
37028 | 406 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %s color: #%02x%02x%02x\n", currItem, currWin->R, currWin->G, currWin->B); |
23077 | 407 |
32873 | 408 return 0; |
23077 | 409 } |
410 | |
33968 | 411 /** |
412 * @brief Parse a @a button definition. | |
413 * | |
414 * Syntax: button=image,x,y,width,height,message | |
415 * | |
416 * @param in definition to be analyzed | |
417 * | |
418 * @return 0 (ok) or 1 (error) | |
419 */ | |
33106 | 420 static int item_button(char *in) |
23077 | 421 { |
33090 | 422 unsigned char fname[256]; |
33089 | 423 unsigned char file[512]; |
424 int x, y, w, h, message; | |
32873 | 425 char msg[32]; |
35688 | 426 guiItem *item; |
32873 | 427 |
37028 | 428 if (!window_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
429 return 1; |
32873 | 430 |
34697 | 431 if (in_window("video")) |
33058 | 432 return 1; |
433 if (in_window("menu")) | |
434 return 1; | |
23077 | 435 |
36991 | 436 cutStr(in, fname, ',', 0); |
437 x = cutInt(in, ',', 1); | |
438 y = cutInt(in, ',', 2); | |
439 w = cutInt(in, ',', 3); | |
440 h = cutInt(in, ',', 4); | |
441 cutStr(in, msg, ',', 5); | |
32873 | 442 |
33071 | 443 message = appFindMessage(msg); |
444 | |
445 if (message == -1) { | |
36694 | 446 skin_error(MSGTR_GUI_MSG_SkinUnknownMessage, msg); |
33071 | 447 return 1; |
448 } | |
36891
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
449 // legacy |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
450 else |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
451 skin_legacy("evSetURL", msg); |
33071 | 452 |
37028 | 453 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %s image: %s %d,%d\n", currItem, fname, x, y); |
33985 | 454 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", msg, message); |
455 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
|
456 |
33098 | 457 item = next_item(); |
458 | |
459 if (!item) | |
460 return 1; | |
461 | |
462 item->type = itButton; | |
463 item->x = x; | |
464 item->y = y; | |
465 item->width = w; | |
466 item->height = h; | |
467 item->message = message; | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
468 item->pressed = btnReleased; |
23077 | 469 |
33098 | 470 if (item->message == evPauseSwitchToPlay) |
471 item->pressed = btnDisabled; | |
23077 | 472 |
33098 | 473 item->Bitmap.Image = NULL; |
32873 | 474 |
475 if (strcmp(fname, "NULL") != 0) { | |
33089 | 476 av_strlcpy(file, path, sizeof(file)); |
477 av_strlcat(file, fname, sizeof(file)); | |
32873 | 478 |
33969 | 479 if (skinImageRead(file, &item->Bitmap) != 0) |
32873 | 480 return 1; |
32951 | 481 |
36996 | 482 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (bitmap: %ux%u)\n", item->Bitmap.Width, item->Bitmap.Height); |
32873 | 483 } |
484 | |
485 return 0; | |
23077 | 486 } |
487 | |
33968 | 488 /** |
489 * @brief Parse a @a selected definition. | |
490 * | |
491 * Syntax: selected=image | |
492 * | |
493 * @param in definition to be analyzed | |
494 * | |
495 * @return 0 (ok) or 1 (error) | |
496 */ | |
33106 | 497 static int item_selected(char *in) |
32873 | 498 { |
33089 | 499 unsigned char file[512]; |
37028 | 500 guiItem *item; |
32873 | 501 |
37028 | 502 if (!window_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
503 return 1; |
32873 | 504 |
33058 | 505 if (in_window("main")) |
506 return 1; | |
34697 | 507 if (in_window("video")) |
33058 | 508 return 1; |
509 if (in_window("playbar")) | |
510 return 1; | |
32873 | 511 |
37028 | 512 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image %s: %s\n", currItem, in); |
33102
de688a61e439
Move debug messages so that they will be processed earlier.
ib
parents:
33101
diff
changeset
|
513 |
37028 | 514 item = &skin->menuSelected; |
515 item->type = itBase; | |
32873 | 516 |
33089 | 517 av_strlcpy(file, path, sizeof(file)); |
33091 | 518 av_strlcat(file, in, sizeof(file)); |
32873 | 519 |
37028 | 520 if (skinImageRead(file, &item->Bitmap) != 0) |
32873 | 521 return 1; |
522 | |
37028 | 523 item->width = item->Bitmap.Width; |
524 item->height = item->Bitmap.Height; | |
32873 | 525 |
37028 | 526 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", item->width, item->height); |
32873 | 527 |
528 return 0; | |
529 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
530 |
33968 | 531 /** |
532 * @brief Parse a @a menu definition. | |
533 * | |
534 * Syntax: menu=x,y,width,height,message | |
535 * | |
536 * @param in definition to be analyzed | |
537 * | |
538 * @return 0 (ok) or 1 (error) | |
539 */ | |
33106 | 540 static int item_menu(char *in) |
32873 | 541 { |
33089 | 542 int x, y, w, h, message; |
33071 | 543 char msg[32]; |
35688 | 544 guiItem *item; |
32873 | 545 |
37028 | 546 if (!window_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
547 return 1; |
32873 | 548 |
33058 | 549 if (in_window("main")) |
550 return 1; | |
34697 | 551 if (in_window("video")) |
33058 | 552 return 1; |
553 if (in_window("playbar")) | |
554 return 1; | |
32873 | 555 |
36991 | 556 x = cutInt(in, ',', 0); |
557 y = cutInt(in, ',', 1); | |
558 w = cutInt(in, ',', 2); | |
559 h = cutInt(in, ',', 3); | |
560 cutStr(in, msg, ',', 4); | |
33071 | 561 |
562 message = appFindMessage(msg); | |
23077 | 563 |
33071 | 564 if (message == -1) { |
36694 | 565 skin_error(MSGTR_GUI_MSG_SkinUnknownMessage, msg); |
33071 | 566 return 1; |
567 } | |
36891
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
568 // legacy |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
569 else |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
570 skin_legacy("evSetURL", msg); |
32873 | 571 |
33098 | 572 item = next_item(); |
573 | |
574 if (!item) | |
575 return 1; | |
576 | |
33100 | 577 item->type = itMenu; |
33096 | 578 item->x = x; |
579 item->y = y; | |
580 item->width = w; | |
581 item->height = h; | |
582 item->message = message; | |
23077 | 583 |
33985 | 584 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] item #%d: %d,%d %dx%d\n", *currWinItemIdx, x, y, w, h); |
585 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", msg, message); | |
23077 | 586 |
32873 | 587 return 0; |
23077 | 588 } |
589 | |
33968 | 590 /** |
37053 | 591 * @brief Parse a hpotmeter, vpotmeter or rpotmeter definition. |
33968 | 592 * |
37053 | 593 * Parameters: button,bwidth,bheight,phases,numphases,[x0,y0,x1,y1,]default,x,y,width,height,message |
33968 | 594 * |
37065 | 595 * @param item memory location of an item to store the parameters in |
33968 | 596 * @param in definition to be analyzed |
597 * | |
37053 | 598 * @note item->type is already available. |
599 * | |
33968 | 600 * @return 0 (ok) or 1 (error) |
601 */ | |
37027 | 602 static int parse_potmeter(guiItem *item, char *in) |
32873 | 603 { |
36999 | 604 unsigned char bfname[256]; |
33090 | 605 unsigned char phfname[256]; |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
606 unsigned char buf[512]; |
37053 | 607 int i = 0, av_uninit(x0), av_uninit(y0), av_uninit(x1), av_uninit(y1); |
36999 | 608 int bwidth, bheight, num, d, x, y, w, h, message; |
23077 | 609 |
37028 | 610 if (!window_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
611 return 1; |
23077 | 612 |
34697 | 613 if (in_window("video")) |
33058 | 614 return 1; |
615 if (in_window("menu")) | |
616 return 1; | |
23077 | 617 |
37053 | 618 cutStr(in, bfname, ',', i++); |
619 bwidth = cutInt(in, ',', i++); | |
620 bheight = cutInt(in, ',', i++); | |
621 cutStr(in, phfname, ',', i++); | |
622 num = cutInt(in, ',', i++); | |
623 | |
624 if (item->type == itRPotmeter) { | |
625 x0 = cutInt(in, ',', i++); | |
626 y0 = cutInt(in, ',', i++); | |
627 x1 = cutInt(in, ',', i++); | |
628 y1 = cutInt(in, ',', i++); | |
629 } | |
630 | |
631 d = cutInt(in, ',', i++); | |
632 x = cutInt(in, ',', i++); | |
633 y = cutInt(in, ',', i++); | |
634 w = cutInt(in, ',', i++); | |
635 h = cutInt(in, ',', i++); | |
636 cutStr(in, buf, ',', i++); | |
32873 | 637 |
33089 | 638 message = appFindMessage(buf); |
23077 | 639 |
33069 | 640 if (message == -1) { |
36694 | 641 skin_error(MSGTR_GUI_MSG_SkinUnknownMessage, buf); |
33069 | 642 return 1; |
643 } | |
36891
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
644 // legacy |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
645 else |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
646 skin_legacy("evSetURL", buf); |
33069 | 647 |
37050 | 648 if (d < 0 || d > 100) { |
649 skin_error(MSGTR_GUI_MSG_SkinErrorDefault, d); | |
650 return 1; | |
651 } | |
652 | |
37028 | 653 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %s image: %s %d,%d %dx%d\n", currItem, phfname, x, y, w, h); |
36999 | 654 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] button image: %s %dx%d\n", bfname, bwidth, bheight); |
655 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] numphases: %d, default: %d%%\n", num, d); | |
33985 | 656 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", buf, message); |
23077 | 657 |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
658 item->x = x; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
659 item->y = y; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
660 item->width = w; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
661 item->height = h; |
37020 | 662 item->pbwidth = bwidth; |
663 item->pbheight = bheight; | |
36999 | 664 item->numphases = num; |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
665 item->value = (float)d; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
666 item->message = message; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
667 item->pressed = btnReleased; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
668 |
37053 | 669 if (item->type == itRPotmeter) { |
670 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] start: %d,%d / stop: %d,%d\n", x0, y0, x1, y1); | |
671 | |
672 item->zeropoint = appRadian(item, x0, y0); | |
673 item->arclength = appRadian(item, x1, y1) - item->zeropoint; | |
674 | |
675 if (item->arclength < 0.0) | |
676 item->arclength += 2 * M_PI; | |
677 // else check if radians of (x0,y0) and (x1,y1) only differ below threshold | |
678 else if (item->arclength < 0.05) | |
679 item->arclength = 2 * M_PI; | |
680 } | |
681 | |
32873 | 682 item->Bitmap.Image = NULL; |
23077 | 683 |
32873 | 684 if (strcmp(phfname, "NULL") != 0) { |
37001 | 685 if (num == 0) { |
686 skin_error(MSGTR_GUI_MSG_SkinErrorNumphases); | |
687 return 1; | |
688 } | |
689 | |
33089 | 690 av_strlcpy(buf, path, sizeof(buf)); |
691 av_strlcat(buf, phfname, sizeof(buf)); | |
32873 | 692 |
33969 | 693 if (skinImageRead(buf, &item->Bitmap) != 0) |
32873 | 694 return 1; |
32951 | 695 |
37028 | 696 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (%s bitmap: %ux%u)\n", currItem, item->Bitmap.Width, item->Bitmap.Height); |
32873 | 697 } |
698 | |
699 item->Mask.Image = NULL; | |
23077 | 700 |
36999 | 701 if (strcmp(bfname, "NULL") != 0) { |
33089 | 702 av_strlcpy(buf, path, sizeof(buf)); |
36999 | 703 av_strlcat(buf, bfname, sizeof(buf)); |
32873 | 704 |
33969 | 705 if (skinImageRead(buf, &item->Mask) != 0) |
32873 | 706 return 1; |
32951 | 707 |
36996 | 708 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (button bitmap: %ux%u)\n", item->Mask.Width, item->Mask.Height); |
32873 | 709 } |
710 | |
711 return 0; | |
23077 | 712 } |
713 | |
33968 | 714 /** |
37027 | 715 * @brief Parse a @a hpotmeter definition. |
716 * | |
717 * Syntax: hpotmeter=button,bwidth,bheight,phases,numphases,default,x,y,width,height,message | |
718 * | |
719 * @param in definition to be analyzed | |
720 * | |
721 * @return 0 (ok) or 1 (error) | |
722 */ | |
723 static int item_hpotmeter(char *in) | |
724 { | |
725 guiItem *item; | |
726 | |
727 item = next_item(); | |
728 | |
729 if (!item) | |
730 return 1; | |
731 | |
732 item->type = itHPotmeter; | |
733 | |
734 return parse_potmeter(item, in); | |
735 } | |
736 | |
737 /** | |
33968 | 738 * @brief Parse a @a vpotmeter definition. |
739 * | |
740 * Syntax: vpotmeter=button,bwidth,bheight,phases,numphases,default,x,y,width,height,message | |
741 * | |
742 * @param in definition to be analyzed | |
743 * | |
744 * @return 0 (ok) or 1 (error) | |
745 */ | |
33106 | 746 static int item_vpotmeter(char *in) |
23077 | 747 { |
35688 | 748 guiItem *item; |
23077 | 749 |
37027 | 750 item = next_item(); |
33056 | 751 |
37027 | 752 if (!item) |
753 return 1; | |
33053 | 754 |
37027 | 755 item->type = itVPotmeter; |
756 | |
757 return parse_potmeter(item, in); | |
23077 | 758 } |
759 | |
33968 | 760 /** |
37053 | 761 * @brief Parse a @a rpotmeter definition. |
762 * | |
763 * Syntax: rpotmeter=button,bwidth,bheight,phases,numphases,x0,y0,x1,y1,default,x,y,width,height,message | |
764 * | |
765 * @param in definition to be analyzed | |
766 * | |
767 * @return 0 (ok) or 1 (error) | |
768 */ | |
769 static int item_rpotmeter(char *in) | |
770 { | |
771 guiItem *item; | |
772 | |
773 item = next_item(); | |
774 | |
775 if (!item) | |
776 return 1; | |
777 | |
778 item->type = itRPotmeter; | |
779 | |
780 return parse_potmeter(item, in); | |
781 } | |
782 | |
783 /** | |
33968 | 784 * @brief Parse a @a potmeter definition. |
785 * | |
786 * Syntax: potmeter=phases,numphases,default,x,y,width,height,message | |
787 * | |
36920 | 788 * @note THIS ITEM IS DEPRECATED. |
789 * | |
33968 | 790 * @param in definition to be analyzed |
791 * | |
792 * @return 0 (ok) or 1 (error) | |
793 */ | |
33106 | 794 static int item_potmeter(char *in) |
32873 | 795 { |
36892 | 796 char param[256]; |
797 | |
798 // legacy | |
37028 | 799 skin_legacy(currItem, "hpotmeter"); |
36892 | 800 |
801 snprintf(param, sizeof(param), "NULL,0,0,%s", in); | |
802 | |
803 return item_hpotmeter(param); | |
36920 | 804 } |
805 | |
806 /** | |
807 * @brief Parse a @a pimage definition. | |
808 * | |
809 * Syntax: pimage=phases,numphases,default,x,y,width,height,message | |
810 * | |
811 * @param in definition to be analyzed | |
812 * | |
813 * @return 0 (ok) or 1 (error) | |
814 */ | |
815 static int item_pimage(char *in) | |
816 { | |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
817 unsigned char phfname[256]; |
33089 | 818 unsigned char buf[512]; |
36999 | 819 int num, d, x, y, w, h, message; |
35688 | 820 guiItem *item; |
23077 | 821 |
37028 | 822 if (!window_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
823 return 1; |
23077 | 824 |
34697 | 825 if (in_window("video")) |
33058 | 826 return 1; |
827 if (in_window("menu")) | |
828 return 1; | |
23077 | 829 |
36991 | 830 cutStr(in, phfname, ',', 0); |
36999 | 831 num = cutInt(in, ',', 1); |
37000 | 832 d = cutInt(in, ',', 2); |
833 x = cutInt(in, ',', 3); | |
834 y = cutInt(in, ',', 4); | |
835 w = cutInt(in, ',', 5); | |
836 h = cutInt(in, ',', 6); | |
36991 | 837 cutStr(in, buf, ',', 7); |
32873 | 838 |
33089 | 839 message = appFindMessage(buf); |
23077 | 840 |
33069 | 841 if (message == -1) { |
36694 | 842 skin_error(MSGTR_GUI_MSG_SkinUnknownMessage, buf); |
33069 | 843 return 1; |
844 } | |
36891
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
845 // legacy |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
846 else |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
847 skin_legacy("evSetURL", buf); |
33069 | 848 |
37050 | 849 if (d < 0 || d > 100) { |
850 skin_error(MSGTR_GUI_MSG_SkinErrorDefault, d); | |
851 return 1; | |
852 } | |
853 | |
37028 | 854 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %s image: %s %d,%d %dx%d\n", currItem, phfname, x, y, w, h); |
36999 | 855 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] numphases: %d, default: %d%%\n", num, d); |
33985 | 856 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", buf, message); |
23077 | 857 |
33098 | 858 item = next_item(); |
859 | |
860 if (!item) | |
861 return 1; | |
862 | |
36920 | 863 item->type = itPimage; |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
864 item->x = x; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
865 item->y = y; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
866 item->width = w; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
867 item->height = h; |
36999 | 868 item->numphases = num; |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
869 item->value = (float)d; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
870 item->message = message; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
871 |
32873 | 872 item->Bitmap.Image = NULL; |
23077 | 873 |
32873 | 874 if (strcmp(phfname, "NULL") != 0) { |
37001 | 875 if (num == 0) { |
876 skin_error(MSGTR_GUI_MSG_SkinErrorNumphases); | |
877 return 1; | |
878 } | |
879 | |
33089 | 880 av_strlcpy(buf, path, sizeof(buf)); |
881 av_strlcat(buf, phfname, sizeof(buf)); | |
32873 | 882 |
33969 | 883 if (skinImageRead(buf, &item->Bitmap) != 0) |
32873 | 884 return 1; |
32951 | 885 |
36996 | 886 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (bitmap: %ux%u)\n", item->Bitmap.Width, item->Bitmap.Height); |
32873 | 887 } |
888 | |
889 return 0; | |
23077 | 890 } |
891 | |
33968 | 892 /** |
893 * @brief Parse a @a font definition. | |
894 * | |
895 * Syntax: font=fontfile | |
896 * | |
897 * @param in definition to be analyzed | |
898 * | |
899 * @return 0 (ok) or 1 (error) | |
900 */ | |
33106 | 901 static int item_font(char *in) |
32873 | 902 { |
33092
83052a4ac698
Use more appropriate name for variable and reduce it to reasonable size.
ib
parents:
33091
diff
changeset
|
903 char fnt[256]; |
23077 | 904 |
37028 | 905 if (!window_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
906 return 1; |
23077 | 907 |
34697 | 908 if (in_window("video")) |
33058 | 909 return 1; |
910 if (in_window("menu")) | |
911 return 1; | |
23077 | 912 |
36991 | 913 cutStr(in, fnt, ',', 0); // Note: This seems needless but isn't for compatibility |
914 // reasons with a meanwhile deprecated second parameter. | |
36891
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
915 // legacy |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
916 skin_legacy("fontid", in); |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
917 |
33099
0b17f6bed6fc
Don't needlessly store font information in the wItems array
ib
parents:
33098
diff
changeset
|
918 switch (fntRead(path, fnt)) { |
32873 | 919 case -1: |
36694 | 920 skin_error(MSGTR_GUI_MSG_SkinMemoryError); |
32873 | 921 return 1; |
23077 | 922 |
32873 | 923 case -2: |
36694 | 924 skin_error(MSGTR_GUI_MSG_SkinTooManyFonts); |
32873 | 925 return 1; |
926 | |
927 case -3: | |
36694 | 928 skin_error(MSGTR_GUI_MSG_SkinFontFileNotFound); |
32873 | 929 return 1; |
930 | |
931 case -4: | |
36694 | 932 skin_error(MSGTR_GUI_MSG_SkinFontImageNotFound); |
32873 | 933 return 1; |
934 } | |
935 | |
37028 | 936 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %s: %s (#%d)\n", currItem, fnt, fntFindID(fnt)); |
32951 | 937 |
32873 | 938 return 0; |
23077 | 939 } |
940 | |
33968 | 941 /** |
942 * @brief Parse a @a slabel definition. | |
943 * | |
944 * Syntax: slabel=x,y,fontfile,"text" | |
945 * | |
946 * @param in definition to be analyzed | |
947 * | |
948 * @return 0 (ok) or 1 (error) | |
949 */ | |
33106 | 950 static int item_slabel(char *in) |
23077 | 951 { |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
952 int x, y, id; |
33090 | 953 char fnt[256]; |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
954 char txt[256]; |
35688 | 955 guiItem *item; |
32873 | 956 |
37028 | 957 if (!window_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
958 return 1; |
23077 | 959 |
34697 | 960 if (in_window("video")) |
33058 | 961 return 1; |
962 if (in_window("menu")) | |
963 return 1; | |
32873 | 964 |
36991 | 965 x = cutInt(in, ',', 0); |
966 y = cutInt(in, ',', 1); | |
967 cutStr(in, fnt, ',', 2); | |
968 cutStr(in, txt, ',', 3); | |
969 cutStr(txt, txt, '"', 1); | |
32951 | 970 |
37028 | 971 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %s: \"%s\"\n", currItem, txt); |
33985 | 972 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] pos: %d,%d\n", x, y); |
23077 | 973 |
33089 | 974 id = fntFindID(fnt); |
23077 | 975 |
32873 | 976 if (id < 0) { |
36694 | 977 skin_error(MSGTR_GUI_MSG_SkinFontNotFound, fnt); |
32873 | 978 return 1; |
979 } | |
23077 | 980 |
33985 | 981 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, id); |
23077 | 982 |
33098 | 983 item = next_item(); |
984 | |
985 if (!item) | |
986 return 1; | |
987 | |
32873 | 988 item->type = itSLabel; |
989 item->x = x; | |
990 item->y = y; | |
991 item->width = -1; | |
992 item->height = -1; | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
993 item->fontid = id; |
33089 | 994 item->label = strdup(txt); |
23077 | 995 |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
996 if (!item->label) { |
36694 | 997 skin_error(MSGTR_GUI_MSG_SkinMemoryError); |
32873 | 998 return 1; |
999 } | |
23077 | 1000 |
32873 | 1001 return 0; |
23077 | 1002 } |
1003 | |
33968 | 1004 /** |
1005 * @brief Parse a @a dlabel definition. | |
1006 * | |
1007 * Syntax: dlabel=x,y,width,align,fontfile,"text" | |
1008 * | |
1009 * @param in definition to be analyzed | |
1010 * | |
1011 * @return 0 (ok) or 1 (error) | |
1012 */ | |
33106 | 1013 static int item_dlabel(char *in) |
32873 | 1014 { |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
1015 int x, y, w, a, id; |
33090 | 1016 char fnt[256]; |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
1017 char txt[256]; |
35688 | 1018 guiItem *item; |
23077 | 1019 |
37028 | 1020 if (!window_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
1021 return 1; |
23077 | 1022 |
34697 | 1023 if (in_window("video")) |
33058 | 1024 return 1; |
1025 if (in_window("menu")) | |
1026 return 1; | |
32873 | 1027 |
36991 | 1028 x = cutInt(in, ',', 0); |
1029 y = cutInt(in, ',', 1); | |
1030 w = cutInt(in, ',', 2); | |
1031 a = cutInt(in, ',', 3); | |
1032 cutStr(in, fnt, ',', 4); | |
1033 cutStr(in, txt, ',', 5); | |
1034 cutStr(txt, txt, '"', 1); | |
32951 | 1035 |
36891
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
1036 // legacy |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
1037 skin_legacy("$l", txt); |
c5ee0fc2ec75
Print an information on deprecated skin config file entries.
ib
parents:
36876
diff
changeset
|
1038 |
37028 | 1039 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %s: \"%s\"\n", currItem, txt); |
33985 | 1040 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] pos: %d,%d\n", x, y); |
1041 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] width: %d, align: %d\n", w, a); | |
23077 | 1042 |
33089 | 1043 id = fntFindID(fnt); |
23077 | 1044 |
32873 | 1045 if (id < 0) { |
36694 | 1046 skin_error(MSGTR_GUI_MSG_SkinFontNotFound, fnt); |
32873 | 1047 return 1; |
1048 } | |
23077 | 1049 |
33985 | 1050 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, id); |
23077 | 1051 |
33098 | 1052 item = next_item(); |
1053 | |
1054 if (!item) | |
1055 return 1; | |
1056 | |
32873 | 1057 item->type = itDLabel; |
1058 item->x = x; | |
1059 item->y = y; | |
33089 | 1060 item->width = w; |
32873 | 1061 item->height = -1; |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
1062 item->fontid = id; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
1063 item->align = a; |
33089 | 1064 item->label = strdup(txt); |
23077 | 1065 |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
1066 if (!item->label) { |
36694 | 1067 skin_error(MSGTR_GUI_MSG_SkinMemoryError); |
32873 | 1068 return 1; |
1069 } | |
23077 | 1070 |
32873 | 1071 return 0; |
23077 | 1072 } |
1073 | |
33968 | 1074 /** |
1075 * @brief Parse a @a decoration definition. | |
1076 * | |
1077 * Syntax: decoration=enable|disable | |
1078 * | |
1079 * @param in definition to be analyzed | |
1080 * | |
1081 * @return 0 (ok) or 1 (error) | |
1082 */ | |
33106 | 1083 static int item_decoration(char *in) |
23077 | 1084 { |
37028 | 1085 if (!window_item(currItem)) |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
1086 return 1; |
32873 | 1087 |
34697 | 1088 if (in_window("video")) |
33058 | 1089 return 1; |
1090 if (in_window("playbar")) | |
1091 return 1; | |
1092 if (in_window("menu")) | |
1093 return 1; | |
32873 | 1094 |
33086 | 1095 strlower(in); |
32873 | 1096 |
33086 | 1097 if (strcmp(in, "enable") != 0 && strcmp(in, "disable") != 0) { |
36694 | 1098 skin_error(MSGTR_GUI_MSG_SkinUnknownParameter, in); |
32873 | 1099 return 1; |
1100 } | |
23077 | 1101 |
33087 | 1102 skin->mainDecoration = (strcmp(in, "enable") == 0); |
23077 | 1103 |
37028 | 1104 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %s: %s\n", currItem, in); |
32873 | 1105 |
1106 return 0; | |
23077 | 1107 } |
1108 | |
33968 | 1109 /** |
1110 * @brief Parsing functions responsible for skin item definitions. | |
1111 */ | |
32878 | 1112 static _item skinItem[] = { |
33106 | 1113 { "background", item_background }, |
1114 { "base", item_base }, | |
1115 { "button", item_button }, | |
1116 { "decoration", item_decoration }, | |
1117 { "dlabel", item_dlabel }, | |
1118 { "end", item_end }, | |
1119 { "font", item_font }, | |
1120 { "hpotmeter", item_hpotmeter }, | |
1121 { "menu", item_menu }, | |
36920 | 1122 { "pimage", item_pimage }, |
36892 | 1123 { "potmeter", item_potmeter }, // legacy |
37053 | 1124 { "rpotmeter", item_rpotmeter }, |
33106 | 1125 { "section", item_section }, |
1126 { "selected", item_selected }, | |
1127 { "slabel", item_slabel }, | |
1128 { "vpotmeter", item_vpotmeter }, | |
1129 { "window", item_window } | |
32873 | 1130 }; |
1131 | |
33968 | 1132 /** |
35662 | 1133 * @brief Read a skin @a image file. |
1134 * | |
1135 * @param fname filename (with path) | |
37065 | 1136 * @param img memory location to store the image data |
35662 | 1137 * |
1138 * @return return code of #bpRead() | |
1139 */ | |
1140 int skinImageRead(char *fname, guiImage *img) | |
1141 { | |
1142 int i = bpRead(fname, img); | |
1143 | |
1144 switch (i) { | |
1145 case -1: | |
36694 | 1146 skin_error(MSGTR_GUI_MSG_SkinErrorBitmap16Bit, fname); |
35662 | 1147 break; |
1148 | |
1149 case -2: | |
36694 | 1150 skin_error(MSGTR_GUI_MSG_SkinBitmapNotFound, fname); |
35662 | 1151 break; |
1152 | |
1153 case -5: | |
36694 | 1154 skin_error(MSGTR_GUI_MSG_SkinBitmapPngReadError, fname); |
35662 | 1155 break; |
1156 | |
1157 case -8: | |
36694 | 1158 skin_error(MSGTR_GUI_MSG_SkinBitmapConversionError, fname); |
35662 | 1159 break; |
1160 } | |
1161 | |
1162 return i; | |
1163 } | |
1164 | |
1165 /** | |
33968 | 1166 * @brief Build the skin file path for a skin name. |
1167 * | |
1168 * @param dir skins directory | |
1169 * @param sname name of the skin | |
1170 * | |
1171 * @return skin file path | |
1172 * | |
1173 * @note As a side effect, variable #path gets set to the skin path. | |
1174 */ | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1175 static char *setname(char *dir, char *sname) |
32873 | 1176 { |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1177 static char skinfname[512]; |
32873 | 1178 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1179 av_strlcpy(skinfname, dir, sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1180 av_strlcat(skinfname, "/", sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1181 av_strlcat(skinfname, sname, sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1182 av_strlcat(skinfname, "/", sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1183 av_strlcpy(path, skinfname, sizeof(path)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1184 av_strlcat(skinfname, "skin", sizeof(skinfname)); |
32873 | 1185 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1186 return skinfname; |
23077 | 1187 } |
1188 | |
33968 | 1189 /** |
1190 * @brief Read and parse a skin. | |
1191 * | |
1192 * @param sname name of the skin | |
1193 * | |
1194 * @return 0 (ok), -1 (skin file not found or not readable) or -2 (parsing error) | |
1195 */ | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1196 int skinRead(char *sname) |
23077 | 1197 { |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1198 char *skinfname; |
34578 | 1199 FILE *skinfile; |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1200 unsigned char line[256]; |
32873 | 1201 unsigned char param[256]; |
32944 | 1202 unsigned int i; |
32873 | 1203 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1204 skinfname = setname(skinDirInHome, sname); |
23077 | 1205 |
34578 | 1206 if ((skinfile = fopen(skinfname, "rt")) == NULL) { |
36043 | 1207 skinfname = setname(skinDirInData, sname); |
32873 | 1208 |
34578 | 1209 if ((skinfile = fopen(skinfname, "rt")) == NULL) { |
36694 | 1210 mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_GUI_MSG_SkinFileNotFound, skinfname); |
32873 | 1211 return -1; |
1212 } | |
23077 | 1213 } |
32873 | 1214 |
33985 | 1215 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] configuration file: %s\n", skinfname); |
23077 | 1216 |
32932 | 1217 appFreeStruct(); |
23077 | 1218 |
33078 | 1219 skin = NULL; |
1220 currWinName[0] = 0; | |
33079 | 1221 linenumber = 0; |
23077 | 1222 |
34578 | 1223 while (fgetstr(line, sizeof(line), skinfile)) { |
32873 | 1224 linenumber++; |
1225 | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1226 strswap(line, '\t', ' '); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1227 trim(line); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1228 decomment(line); |
32873 | 1229 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
1230 if (!*line) |
32873 | 1231 continue; |
23077 | 1232 |
37028 | 1233 cutStr(line, currItem, '=', 0); |
36991 | 1234 cutStr(line, param, '=', 1); |
37028 | 1235 strlower(currItem); |
32873 | 1236 |
33076
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1237 for (i = 0; i < FF_ARRAY_ELEMS(skinItem); i++) { |
37028 | 1238 if (!strcmp(currItem, skinItem[i].name)) { |
35360 | 1239 if (skinItem[i].func(param) != 0) { |
1240 fclose(skinfile); | |
32873 | 1241 return -2; |
35360 | 1242 } else |
33076
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1243 break; |
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1244 } |
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
1245 } |
33077 | 1246 |
1247 if (i == FF_ARRAY_ELEMS(skinItem)) { | |
37028 | 1248 skin_error(MSGTR_GUI_MSG_SkinUnknownItem, currItem); |
35360 | 1249 fclose(skinfile); |
33077 | 1250 return -2; |
1251 } | |
32873 | 1252 } |
1253 | |
35360 | 1254 fclose(skinfile); |
1255 | |
32873 | 1256 if (linenumber == 0) { |
36694 | 1257 mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_GUI_MSG_SkinFileNotReadable, skinfname); |
32873 | 1258 return -1; |
1259 } | |
1260 | |
1261 return 0; | |
23077 | 1262 } |