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