Mercurial > mplayer.hg
annotate gui/skin/skin.c @ 33104:65827197d1af
Simplify cmd_base().
All four window types use (almost) exactly the same code in cmd_base().
Reduce its size to (almost) 1/4 by using the main parts of the code together.
author | ib |
---|---|
date | Sun, 03 Apr 2011 10:31:11 +0000 |
parents | eabc2472e7eb |
children | 1cd1adf9ee6c |
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 |
19 #include <stdio.h> | |
20 #include <string.h> | |
21 | |
32873 | 22 #include "skin.h" |
23077 | 23 #include "font.h" |
32893 | 24 #include "gui/app.h" |
33023 | 25 #include "gui/interface.h" |
32873 | 26 #include "gui/mplayer/widgets.h" |
33046 | 27 #include "gui/util/cut.h" |
33048 | 28 #include "gui/util/string.h" |
23077 | 29 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
30 #include "config.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
31 #include "help_mp.h" |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23077
diff
changeset
|
32 #include "libavutil/avstring.h" |
32944 | 33 #include "libavutil/common.h" |
32873 | 34 #include "mp_msg.h" |
23077 | 35 |
32873 | 36 typedef struct { |
37 const char *name; | |
38 int (*func)(char *in); | |
39 } _item; | |
23077 | 40 |
32937 | 41 static guiItems *skin; |
23077 | 42 |
32873 | 43 static int linenumber; |
44 static unsigned char path[512]; | |
23077 | 45 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
46 static unsigned char currWinName[32]; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
47 static wItem *currWin; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
48 static int *currWinItemIdx; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
49 static wItem *currWinItems; |
23077 | 50 |
33022 | 51 static void skin_error(const char *format, ...) |
23077 | 52 { |
32873 | 53 char p[512]; |
54 va_list ap; | |
55 | |
56 va_start(ap, format); | |
57 vsnprintf(p, sizeof(p), format, ap); | |
58 va_end(ap); | |
59 | |
33023 | 60 gmp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_ERRORMESSAGE, linenumber, p); |
23077 | 61 } |
62 | |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
63 static int section_cmd(char *cmd) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
64 { |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
65 if (!skin) { |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
66 skin_error(MSGTR_SKIN_ERROR_SECTION, cmd); |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
67 return 0; |
32873 | 68 } |
69 | |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
70 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
71 } |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
72 |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
73 static int window_cmd(char *cmd) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
74 { |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
75 if (!currWinName[0]) { |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
76 skin_error(MSGTR_SKIN_ERROR_WINDOW, cmd); |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
77 return 0; |
32873 | 78 } |
23077 | 79 |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
80 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
81 } |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
82 |
33058 | 83 static int in_window(char *name) |
84 { | |
85 if (strcmp(currWinName, name) == 0) { | |
33062 | 86 skin_error(MSGTR_SKIN_ERROR_ITEM, name); |
33058 | 87 return 1; |
32873 | 88 } |
89 | |
33058 | 90 return 0; |
91 } | |
92 | |
32873 | 93 int skinBPRead(char *fname, txSample *bf) |
94 { | |
95 int i = bpRead(fname, bf); | |
96 | |
97 switch (i) { | |
98 case -1: | |
33022 | 99 skin_error(MSGTR_SKIN_BITMAP_16bit, fname); |
32873 | 100 break; |
101 | |
102 case -2: | |
33022 | 103 skin_error(MSGTR_SKIN_BITMAP_FileNotFound, fname); |
32873 | 104 break; |
105 | |
106 case -5: | |
33022 | 107 skin_error(MSGTR_SKIN_BITMAP_PNGReadError, fname); |
32873 | 108 break; |
109 | |
110 case -8: | |
33022 | 111 skin_error(MSGTR_SKIN_BITMAP_ConversionError, fname); |
32873 | 112 break; |
113 } | |
114 | |
115 return i; | |
23077 | 116 } |
117 | |
33098 | 118 static wItem *next_item(void) |
119 { | |
120 wItem *item = NULL; | |
121 | |
122 if (*currWinItemIdx < MAX_ITEMS - 1) { | |
123 (*currWinItemIdx)++; | |
124 item = &currWinItems[*currWinItemIdx]; | |
125 } else | |
126 skin_error(MSGTR_SKIN_TooManyItemsDeclared); | |
127 | |
128 return item; | |
129 } | |
130 | |
32873 | 131 // section=movieplayer |
132 static int cmd_section(char *in) | |
23077 | 133 { |
33064 | 134 if (skin) { |
135 skin_error(MSGTR_SKIN_ERROR_ITEM, "section"); | |
136 return 1; | |
137 } | |
138 | |
33055 | 139 if (!strcmp(strlower(in), "movieplayer")) |
32937 | 140 skin = &appMPlayer; |
33067 | 141 else { |
142 skin_error(MSGTR_SKIN_UNKNOWN_NAME, in); | |
143 return 1; | |
144 } | |
32873 | 145 |
32951 | 146 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] section: %s\n", in); |
32873 | 147 |
148 return 0; | |
23077 | 149 } |
150 | |
32873 | 151 // end |
152 static int cmd_end(char *in) | |
23077 | 153 { |
32958 | 154 #ifdef MP_DEBUG |
32951 | 155 char *space, *name; |
156 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
157 if (currWinName[0]) { |
32951 | 158 space = " "; |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
159 name = currWinName; |
32951 | 160 } else { |
161 space = ""; | |
162 name = "section"; | |
163 } | |
32958 | 164 #endif |
165 | |
166 (void)in; | |
32951 | 167 |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
168 if (!section_cmd("end")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
169 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
170 |
32951 | 171 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] %send (%s)\n", space, name); |
172 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
173 if (currWinName[0]) { |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
174 currWinName[0] = 0; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
175 currWin = NULL; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
176 currWinItemIdx = NULL; |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
177 currWinItems = NULL; |
32873 | 178 } else |
32937 | 179 skin = NULL; |
32873 | 180 |
181 return 0; | |
23077 | 182 } |
183 | |
32873 | 184 // window=main|sub|playbar|menu |
185 static int cmd_window(char *in) | |
23077 | 186 { |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
187 if (!section_cmd("window")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
188 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
189 |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
190 if (currWinName[0]) { |
33062 | 191 skin_error(MSGTR_SKIN_ERROR_ITEM, "window"); |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
192 return 1; |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
193 } |
32873 | 194 |
33083 | 195 strlower(in); |
23077 | 196 |
33083 | 197 if (strcmp(in, "main") == 0) { |
33095 | 198 currWin = &skin->main; |
199 currWinItemIdx = &skin->IndexOfMainItems; | |
200 currWinItems = skin->mainItems; | |
33083 | 201 } else if (strcmp(in, "sub") == 0) { |
33095 | 202 currWin = &skin->sub; |
33083 | 203 currWinItemIdx = NULL; |
204 currWinItems = NULL; | |
205 } else if (strcmp(in, "playbar") == 0) { | |
33095 | 206 currWin = &skin->bar; |
207 currWinItemIdx = &skin->IndexOfBarItems; | |
208 currWinItems = skin->barItems; | |
33083 | 209 } else if (strcmp(in, "menu") == 0) { |
33095 | 210 currWin = &skin->menu; |
211 currWinItemIdx = &skin->IndexOfMenuItems; | |
212 currWinItems = skin->menuItems; | |
33066 | 213 } else { |
33065 | 214 skin_error(MSGTR_SKIN_UNKNOWN_NAME, in); |
33066 | 215 return 1; |
216 } | |
32873 | 217 |
33083 | 218 av_strlcpy(currWinName, in, sizeof(currWinName)); |
219 | |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
220 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] window: %s\n", currWinName); |
32873 | 221 |
222 return 0; | |
23077 | 223 } |
224 | |
32873 | 225 // base=image,x,y[,width,height] |
226 static int cmd_base(char *in) | |
23077 | 227 { |
33090 | 228 unsigned char fname[256]; |
33089 | 229 unsigned char file[512]; |
32873 | 230 int x, y; |
33089 | 231 int w = 0, h = 0; |
33104 | 232 int is_sub, is_bar, is_menu; |
32873 | 233 |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
234 if (!window_cmd("base")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
235 return 1; |
23077 | 236 |
33104 | 237 is_sub = (strcmp(currWinName, "sub") == 0); |
238 is_bar = (strcmp(currWinName, "playbar") == 0); | |
239 is_menu = (strcmp(currWinName, "menu") == 0); | |
240 | |
32873 | 241 cutItem(in, fname, ',', 0); |
33089 | 242 x = cutItemToInt(in, ',', 1); |
243 y = cutItemToInt(in, ',', 2); | |
244 w = cutItemToInt(in, ',', 3); | |
245 h = cutItemToInt(in, ',', 4); | |
32873 | 246 |
33104 | 247 { |
248 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image: %s", fname); | |
23077 | 249 |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
250 currWin->type = itBase; |
33104 | 251 |
252 if (!is_menu) { | |
33096 | 253 currWin->x = x; |
254 currWin->y = y; | |
32873 | 255 |
33104 | 256 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, " %d,%d", x, y); |
257 } | |
32951 | 258 |
33104 | 259 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "\n"); |
32873 | 260 |
33089 | 261 av_strlcpy(file, path, sizeof(file)); |
262 av_strlcat(file, fname, sizeof(file)); | |
32873 | 263 |
33096 | 264 if (skinBPRead(file, &currWin->Bitmap) != 0) |
32873 | 265 return 1; |
266 | |
33096 | 267 currWin->width = currWin->Bitmap.Width; |
268 currWin->height = currWin->Bitmap.Height; | |
32873 | 269 |
33104 | 270 if (is_sub) { |
33089 | 271 if (w && h) { |
33096 | 272 currWin->width = w; |
273 currWin->height = h; | |
32873 | 274 } |
33104 | 275 } |
32873 | 276 |
33096 | 277 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", currWin->width, currWin->height); |
32951 | 278 |
33104 | 279 if (!is_sub) { |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
280 #ifdef CONFIG_XSHAPE |
33096 | 281 Convert32to1(&currWin->Bitmap, &currWin->Mask, 0x00ff00ff); |
282 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] mask: %lux%lu\n", currWin->Mask.Width, currWin->Mask.Height); | |
23077 | 283 #else |
33096 | 284 currWin->Mask.Image = NULL; |
23077 | 285 #endif |
33104 | 286 } |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
287 |
33104 | 288 if (is_bar) |
289 skin->barIsPresent = 1; | |
290 if (is_menu) | |
291 skin->menuIsPresent = 1; | |
32873 | 292 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
293 |
32873 | 294 return 0; |
23077 | 295 } |
296 | |
32873 | 297 // background=R,G,B |
298 static int cmd_background(char *in) | |
23077 | 299 { |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
300 if (!window_cmd("background")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
301 return 1; |
23077 | 302 |
33058 | 303 if (in_window("main")) |
304 return 1; | |
33088 | 305 if (in_window("playbar")) |
306 return 1; | |
33058 | 307 if (in_window("menu")) |
308 return 1; | |
23077 | 309 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
310 currWin->R = cutItemToInt(in, ',', 0); |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
311 currWin->G = cutItemToInt(in, ',', 1); |
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
312 currWin->B = cutItemToInt(in, ',', 2); |
23077 | 313 |
32980
2bfd000bb789
Cosmetic: Rename pointers handling current window and items.
ib
parents:
32979
diff
changeset
|
314 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] background color: #%02x%02x%02x\n", currWin->R, currWin->G, currWin->B); |
23077 | 315 |
32873 | 316 return 0; |
23077 | 317 } |
318 | |
32873 | 319 // button=image,x,y,width,height,message |
320 static int cmd_button(char *in) | |
23077 | 321 { |
33090 | 322 unsigned char fname[256]; |
33089 | 323 unsigned char file[512]; |
324 int x, y, w, h, message; | |
32873 | 325 char msg[32]; |
33098 | 326 wItem *item; |
32873 | 327 |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
328 if (!window_cmd("button")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
329 return 1; |
32873 | 330 |
33058 | 331 if (in_window("sub")) |
332 return 1; | |
333 if (in_window("menu")) | |
334 return 1; | |
23077 | 335 |
32873 | 336 cutItem(in, fname, ',', 0); |
33089 | 337 x = cutItemToInt(in, ',', 1); |
338 y = cutItemToInt(in, ',', 2); | |
339 w = cutItemToInt(in, ',', 3); | |
340 h = cutItemToInt(in, ',', 4); | |
32873 | 341 cutItem(in, msg, ',', 5); |
342 | |
33071 | 343 message = appFindMessage(msg); |
344 | |
345 if (message == -1) { | |
346 skin_error(MSGTR_SKIN_UnknownMessage, msg); | |
347 return 1; | |
348 } | |
349 | |
33102
de688a61e439
Move debug messages so that they will be processed earlier.
ib
parents:
33101
diff
changeset
|
350 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] button image: %s %d,%d\n", fname, x, y); |
de688a61e439
Move debug messages so that they will be processed earlier.
ib
parents:
33101
diff
changeset
|
351 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", msg, message); |
de688a61e439
Move debug messages so that they will be processed earlier.
ib
parents:
33101
diff
changeset
|
352 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] size: %dx%d\n", w, h); |
de688a61e439
Move debug messages so that they will be processed earlier.
ib
parents:
33101
diff
changeset
|
353 |
33098 | 354 item = next_item(); |
355 | |
356 if (!item) | |
357 return 1; | |
358 | |
359 item->type = itButton; | |
360 item->x = x; | |
361 item->y = y; | |
362 item->width = w; | |
363 item->height = h; | |
364 item->message = message; | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
365 item->pressed = btnReleased; |
23077 | 366 |
33098 | 367 if (item->message == evPauseSwitchToPlay) |
368 item->pressed = btnDisabled; | |
23077 | 369 |
33098 | 370 item->Bitmap.Image = NULL; |
32873 | 371 |
372 if (strcmp(fname, "NULL") != 0) { | |
33089 | 373 av_strlcpy(file, path, sizeof(file)); |
374 av_strlcat(file, fname, sizeof(file)); | |
32873 | 375 |
33098 | 376 if (skinBPRead(file, &item->Bitmap) != 0) |
32873 | 377 return 1; |
32951 | 378 |
33098 | 379 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); |
32873 | 380 } |
381 | |
382 return 0; | |
23077 | 383 } |
384 | |
32873 | 385 // selected=image |
386 static int cmd_selected(char *in) | |
387 { | |
33089 | 388 unsigned char file[512]; |
33096 | 389 wItem *currItem; |
32873 | 390 |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
391 if (!window_cmd("selected")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
392 return 1; |
32873 | 393 |
33058 | 394 if (in_window("main")) |
395 return 1; | |
396 if (in_window("sub")) | |
397 return 1; | |
398 if (in_window("playbar")) | |
399 return 1; | |
32873 | 400 |
33102
de688a61e439
Move debug messages so that they will be processed earlier.
ib
parents:
33101
diff
changeset
|
401 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] image selected: %s\n", in); |
de688a61e439
Move debug messages so that they will be processed earlier.
ib
parents:
33101
diff
changeset
|
402 |
33096 | 403 currItem = &skin->menuSelected; |
404 currItem->type = itBase; | |
32873 | 405 |
33089 | 406 av_strlcpy(file, path, sizeof(file)); |
33091 | 407 av_strlcat(file, in, sizeof(file)); |
32873 | 408 |
33096 | 409 if (skinBPRead(file, &currItem->Bitmap) != 0) |
32873 | 410 return 1; |
411 | |
33096 | 412 currItem->width = currItem->Bitmap.Width; |
413 currItem->height = currItem->Bitmap.Height; | |
32873 | 414 |
33096 | 415 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] bitmap: %dx%d\n", currItem->width, currItem->height); |
32873 | 416 |
417 return 0; | |
418 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
419 |
32873 | 420 // menu=x,y,width,height,message |
421 static int cmd_menu(char *in) | |
422 { | |
33089 | 423 int x, y, w, h, message; |
33071 | 424 char msg[32]; |
33096 | 425 wItem *item; |
32873 | 426 |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
427 if (!window_cmd("menu")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
428 return 1; |
32873 | 429 |
33058 | 430 if (in_window("main")) |
431 return 1; | |
432 if (in_window("sub")) | |
433 return 1; | |
434 if (in_window("playbar")) | |
435 return 1; | |
32873 | 436 |
33089 | 437 x = cutItemToInt(in, ',', 0); |
438 y = cutItemToInt(in, ',', 1); | |
439 w = cutItemToInt(in, ',', 2); | |
440 h = cutItemToInt(in, ',', 3); | |
33071 | 441 cutItem(in, msg, ',', 4); |
442 | |
443 message = appFindMessage(msg); | |
23077 | 444 |
33071 | 445 if (message == -1) { |
446 skin_error(MSGTR_SKIN_UnknownMessage, msg); | |
447 return 1; | |
448 } | |
32873 | 449 |
33098 | 450 item = next_item(); |
451 | |
452 if (!item) | |
453 return 1; | |
454 | |
33100 | 455 item->type = itMenu; |
33096 | 456 item->x = x; |
457 item->y = y; | |
458 item->width = w; | |
459 item->height = h; | |
460 item->message = message; | |
23077 | 461 |
33096 | 462 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] item #%d: %d,%d %dx%d\n", *currWinItemIdx, x, y, w, h); |
33071 | 463 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", msg, message); |
23077 | 464 |
33096 | 465 item->Bitmap.Image = NULL; |
33053 | 466 |
32873 | 467 return 0; |
23077 | 468 } |
469 | |
32873 | 470 // hpotmeter=button,bwidth,bheight,phases,numphases,default,x,y,width,height,message |
471 static int cmd_hpotmeter(char *in) | |
472 { | |
33090 | 473 unsigned char pfname[256]; |
474 unsigned char phfname[256]; | |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
475 unsigned char buf[512]; |
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
476 int pwidth, pheight, ph, d, x, y, w, h, message; |
32873 | 477 wItem *item; |
23077 | 478 |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
479 if (!window_cmd("h/v potmeter")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
480 return 1; |
23077 | 481 |
33058 | 482 if (in_window("sub")) |
483 return 1; | |
484 if (in_window("menu")) | |
485 return 1; | |
23077 | 486 |
32873 | 487 cutItem(in, pfname, ',', 0); |
32911 | 488 pwidth = cutItemToInt(in, ',', 1); |
489 pheight = cutItemToInt(in, ',', 2); | |
32873 | 490 cutItem(in, phfname, ',', 3); |
491 ph = cutItemToInt(in, ',', 4); | |
492 d = cutItemToInt(in, ',', 5); | |
493 x = cutItemToInt(in, ',', 6); | |
494 y = cutItemToInt(in, ',', 7); | |
33089 | 495 w = cutItemToInt(in, ',', 8); |
496 h = cutItemToInt(in, ',', 9); | |
497 cutItem(in, buf, ',', 10); | |
32873 | 498 |
33089 | 499 message = appFindMessage(buf); |
23077 | 500 |
33069 | 501 if (message == -1) { |
33089 | 502 skin_error(MSGTR_SKIN_UnknownMessage, buf); |
33069 | 503 return 1; |
504 } | |
505 | |
33089 | 506 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] h/v potmeter image: %s %d,%d %dx%d\n", phfname, x, y, w, h); |
32951 | 507 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] button image: %s %dx%d\n", pfname, pwidth, pheight); |
508 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] numphases: %d, default: %d%%\n", ph, d); | |
33089 | 509 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", buf, message); |
23077 | 510 |
33098 | 511 item = next_item(); |
512 | |
513 if (!item) | |
514 return 1; | |
515 | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
516 item->type = itHPotmeter; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
517 item->x = x; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
518 item->y = y; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
519 item->width = w; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
520 item->height = h; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
521 item->pwidth = pwidth; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
522 item->pheight = pheight; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
523 item->numphases = ph; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
524 item->value = (float)d; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
525 item->message = message; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
526 item->pressed = btnReleased; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
527 |
32873 | 528 item->Bitmap.Image = NULL; |
23077 | 529 |
32873 | 530 if (strcmp(phfname, "NULL") != 0) { |
33089 | 531 av_strlcpy(buf, path, sizeof(buf)); |
532 av_strlcat(buf, phfname, sizeof(buf)); | |
32873 | 533 |
33089 | 534 if (skinBPRead(buf, &item->Bitmap) != 0) |
32873 | 535 return 1; |
32951 | 536 |
537 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (potmeter bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); | |
32873 | 538 } |
539 | |
540 item->Mask.Image = NULL; | |
23077 | 541 |
32873 | 542 if (strcmp(pfname, "NULL") != 0) { |
33089 | 543 av_strlcpy(buf, path, sizeof(buf)); |
544 av_strlcat(buf, pfname, sizeof(buf)); | |
32873 | 545 |
33089 | 546 if (skinBPRead(buf, &item->Mask) != 0) |
32873 | 547 return 1; |
32951 | 548 |
549 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (button bitmap: %lux%lu)\n", item->Mask.Width, item->Mask.Height); | |
32873 | 550 } |
551 | |
552 return 0; | |
23077 | 553 } |
554 | |
32873 | 555 // vpotmeter=button,bwidth,bheight,phases,numphases,default,x,y,width,height,message |
556 static int cmd_vpotmeter(char *in) | |
23077 | 557 { |
33056 | 558 int r; |
32873 | 559 wItem *item; |
23077 | 560 |
33056 | 561 r = cmd_hpotmeter(in); |
562 | |
563 if (r == 0) { | |
33057 | 564 item = &currWinItems[*currWinItemIdx]; |
565 item->type = itVPotmeter; | |
33056 | 566 } |
33053 | 567 |
32873 | 568 return r; |
23077 | 569 } |
570 | |
32873 | 571 // potmeter=phases,numphases,default,x,y,width,height,message |
572 static int cmd_potmeter(char *in) | |
573 { | |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
574 unsigned char phfname[256]; |
33089 | 575 unsigned char buf[512]; |
33093
3de646fca03b
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33092
diff
changeset
|
576 int ph, d, x, y, w, h, message; |
32873 | 577 wItem *item; |
23077 | 578 |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
579 if (!window_cmd("potmeter")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
580 return 1; |
23077 | 581 |
33058 | 582 if (in_window("sub")) |
583 return 1; | |
584 if (in_window("menu")) | |
585 return 1; | |
23077 | 586 |
32873 | 587 cutItem(in, phfname, ',', 0); |
588 ph = cutItemToInt(in, ',', 1); | |
589 d = cutItemToInt(in, ',', 2); | |
590 x = cutItemToInt(in, ',', 3); | |
591 y = cutItemToInt(in, ',', 4); | |
33089 | 592 w = cutItemToInt(in, ',', 5); |
593 h = cutItemToInt(in, ',', 6); | |
594 cutItem(in, buf, ',', 7); | |
32873 | 595 |
33089 | 596 message = appFindMessage(buf); |
23077 | 597 |
33069 | 598 if (message == -1) { |
33089 | 599 skin_error(MSGTR_SKIN_UnknownMessage, buf); |
33069 | 600 return 1; |
601 } | |
602 | |
33089 | 603 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] potmeter image: %s %d,%d %dx%d\n", phfname, x, y, w, h); |
32951 | 604 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] numphases: %d, default: %d%%\n", ph, d); |
33089 | 605 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] message: %s (#%d)\n", buf, message); |
23077 | 606 |
33098 | 607 item = next_item(); |
608 | |
609 if (!item) | |
610 return 1; | |
611 | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
612 item->type = itPotmeter; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
613 item->x = x; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
614 item->y = y; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
615 item->width = w; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
616 item->height = h; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
617 item->numphases = ph; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
618 item->value = (float)d; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
619 item->message = message; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
620 |
32873 | 621 item->Bitmap.Image = NULL; |
23077 | 622 |
32873 | 623 if (strcmp(phfname, "NULL") != 0) { |
33089 | 624 av_strlcpy(buf, path, sizeof(buf)); |
625 av_strlcat(buf, phfname, sizeof(buf)); | |
32873 | 626 |
33089 | 627 if (skinBPRead(buf, &item->Bitmap) != 0) |
32873 | 628 return 1; |
32951 | 629 |
630 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] (bitmap: %lux%lu)\n", item->Bitmap.Width, item->Bitmap.Height); | |
32873 | 631 } |
632 | |
633 return 0; | |
23077 | 634 } |
635 | |
32873 | 636 // font=fontfile |
637 static int cmd_font(char *in) | |
638 { | |
33092
83052a4ac698
Use more appropriate name for variable and reduce it to reasonable size.
ib
parents:
33091
diff
changeset
|
639 char fnt[256]; |
23077 | 640 |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
641 if (!window_cmd("font")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
642 return 1; |
23077 | 643 |
33058 | 644 if (in_window("sub")) |
645 return 1; | |
646 if (in_window("menu")) | |
647 return 1; | |
23077 | 648 |
33092
83052a4ac698
Use more appropriate name for variable and reduce it to reasonable size.
ib
parents:
33091
diff
changeset
|
649 cutItem(in, fnt, ',', 0); // Note: This seems needless but isn't for compatibility |
83052a4ac698
Use more appropriate name for variable and reduce it to reasonable size.
ib
parents:
33091
diff
changeset
|
650 // reasons with a meanwhile depreciated second parameter. |
33099
0b17f6bed6fc
Don't needlessly store font information in the wItems array
ib
parents:
33098
diff
changeset
|
651 switch (fntRead(path, fnt)) { |
32873 | 652 case -1: |
33097 | 653 skin_error(MSGTR_SKIN_NotEnoughMemory); |
32873 | 654 return 1; |
23077 | 655 |
32873 | 656 case -2: |
33022 | 657 skin_error(MSGTR_SKIN_FONT_TooManyFontsDeclared); |
32873 | 658 return 1; |
659 | |
660 case -3: | |
33022 | 661 skin_error(MSGTR_SKIN_FONT_FontFileNotFound); |
32873 | 662 return 1; |
663 | |
664 case -4: | |
33022 | 665 skin_error(MSGTR_SKIN_FONT_FontImageNotFound); |
32873 | 666 return 1; |
667 } | |
668 | |
33092
83052a4ac698
Use more appropriate name for variable and reduce it to reasonable size.
ib
parents:
33091
diff
changeset
|
669 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, fntFindID(fnt)); |
32951 | 670 |
32873 | 671 return 0; |
23077 | 672 } |
673 | |
32873 | 674 // slabel=x,y,fontfile,"text" |
675 static int cmd_slabel(char *in) | |
23077 | 676 { |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
677 int x, y, id; |
33090 | 678 char fnt[256]; |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
679 char txt[256]; |
32873 | 680 wItem *item; |
681 | |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
682 if (!window_cmd("slabel")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
683 return 1; |
23077 | 684 |
33058 | 685 if (in_window("sub")) |
686 return 1; | |
687 if (in_window("menu")) | |
688 return 1; | |
32873 | 689 |
690 x = cutItemToInt(in, ',', 0); | |
691 y = cutItemToInt(in, ',', 1); | |
33089 | 692 cutItem(in, fnt, ',', 2); |
693 cutItem(in, txt, ',', 3); | |
694 cutItem(txt, txt, '"', 1); | |
32951 | 695 |
33089 | 696 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] slabel: \"%s\"\n", txt); |
32951 | 697 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] pos: %d,%d\n", x, y); |
23077 | 698 |
33089 | 699 id = fntFindID(fnt); |
23077 | 700 |
32873 | 701 if (id < 0) { |
33097 | 702 skin_error(MSGTR_SKIN_FONT_NonExistentFont, fnt); |
32873 | 703 return 1; |
704 } | |
23077 | 705 |
33089 | 706 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, id); |
23077 | 707 |
33098 | 708 item = next_item(); |
709 | |
710 if (!item) | |
711 return 1; | |
712 | |
32873 | 713 item->type = itSLabel; |
714 item->x = x; | |
715 item->y = y; | |
716 item->width = -1; | |
717 item->height = -1; | |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
718 item->fontid = id; |
33089 | 719 item->label = strdup(txt); |
23077 | 720 |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
721 if (!item->label) { |
33097 | 722 skin_error(MSGTR_SKIN_NotEnoughMemory); |
32873 | 723 return 1; |
724 } | |
23077 | 725 |
32873 | 726 return 0; |
23077 | 727 } |
728 | |
32910 | 729 // dlabel=x,y,width,align,fontfile,"text" |
32873 | 730 static int cmd_dlabel(char *in) |
731 { | |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
732 int x, y, w, a, id; |
33090 | 733 char fnt[256]; |
33094
2faf1c3ded5d
Cosmetic: Rearrange variable declarations to match parameters.
ib
parents:
33093
diff
changeset
|
734 char txt[256]; |
32873 | 735 wItem *item; |
23077 | 736 |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
737 if (!window_cmd("dlabel")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
738 return 1; |
23077 | 739 |
33058 | 740 if (in_window("sub")) |
741 return 1; | |
742 if (in_window("menu")) | |
743 return 1; | |
32873 | 744 |
33089 | 745 x = cutItemToInt(in, ',', 0); |
746 y = cutItemToInt(in, ',', 1); | |
747 w = cutItemToInt(in, ',', 2); | |
748 a = cutItemToInt(in, ',', 3); | |
749 cutItem(in, fnt, ',', 4); | |
750 cutItem(in, txt, ',', 5); | |
751 cutItem(txt, txt, '"', 1); | |
32951 | 752 |
33089 | 753 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] dlabel: \"%s\"\n", txt); |
32951 | 754 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] pos: %d,%d\n", x, y); |
33089 | 755 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] width: %d, align: %d\n", w, a); |
23077 | 756 |
33089 | 757 id = fntFindID(fnt); |
23077 | 758 |
32873 | 759 if (id < 0) { |
33097 | 760 skin_error(MSGTR_SKIN_FONT_NonExistentFont, fnt); |
32873 | 761 return 1; |
762 } | |
23077 | 763 |
33089 | 764 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] font: %s (#%d)\n", fnt, id); |
23077 | 765 |
33098 | 766 item = next_item(); |
767 | |
768 if (!item) | |
769 return 1; | |
770 | |
32873 | 771 item->type = itDLabel; |
772 item->x = x; | |
773 item->y = y; | |
33089 | 774 item->width = w; |
32873 | 775 item->height = -1; |
33101
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
776 item->fontid = id; |
930338bde973
Order member assignments according to their definition in the structure.
ib
parents:
33100
diff
changeset
|
777 item->align = a; |
33089 | 778 item->label = strdup(txt); |
23077 | 779 |
32979
4905f5a87357
Replace some awkward and unnecessary usages of strlen().
ib
parents:
32958
diff
changeset
|
780 if (!item->label) { |
33097 | 781 skin_error(MSGTR_SKIN_NotEnoughMemory); |
32873 | 782 return 1; |
783 } | |
23077 | 784 |
32873 | 785 return 0; |
23077 | 786 } |
787 | |
32873 | 788 // decoration=enable|disable |
789 static int cmd_decoration(char *in) | |
23077 | 790 { |
33054
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
791 if (!window_cmd("decoration")) |
ed66afc0b06c
Replace macros to check whether a command is allowed by functions.
ib
parents:
33053
diff
changeset
|
792 return 1; |
32873 | 793 |
33058 | 794 if (in_window("sub")) |
795 return 1; | |
796 if (in_window("playbar")) | |
797 return 1; | |
798 if (in_window("menu")) | |
799 return 1; | |
32873 | 800 |
33086 | 801 strlower(in); |
32873 | 802 |
33086 | 803 if (strcmp(in, "enable") != 0 && strcmp(in, "disable") != 0) { |
804 skin_error(MSGTR_SKIN_UnknownParameter, in); | |
32873 | 805 return 1; |
806 } | |
23077 | 807 |
33087 | 808 skin->mainDecoration = (strcmp(in, "enable") == 0); |
23077 | 809 |
33086 | 810 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] decoration: %s\n", in); |
32873 | 811 |
812 return 0; | |
23077 | 813 } |
814 | |
32878 | 815 static _item skinItem[] = { |
32873 | 816 { "section", cmd_section }, |
817 { "end", cmd_end }, | |
818 { "window", cmd_window }, | |
819 { "base", cmd_base }, | |
820 { "button", cmd_button }, | |
821 { "selected", cmd_selected }, | |
822 { "background", cmd_background }, | |
823 { "vpotmeter", cmd_vpotmeter }, | |
824 { "hpotmeter", cmd_hpotmeter }, | |
825 { "potmeter", cmd_potmeter }, | |
826 { "font", cmd_font }, | |
827 { "slabel", cmd_slabel }, | |
828 { "dlabel", cmd_dlabel }, | |
829 { "decoration", cmd_decoration }, | |
830 { "menu", cmd_menu } | |
831 }; | |
832 | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
833 static char *setname(char *dir, char *sname) |
32873 | 834 { |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
835 static char skinfname[512]; |
32873 | 836 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
837 av_strlcpy(skinfname, dir, sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
838 av_strlcat(skinfname, "/", sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
839 av_strlcat(skinfname, sname, sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
840 av_strlcat(skinfname, "/", sizeof(skinfname)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
841 av_strlcpy(path, skinfname, sizeof(path)); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
842 av_strlcat(skinfname, "skin", sizeof(skinfname)); |
32873 | 843 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
844 return skinfname; |
23077 | 845 } |
846 | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
847 int skinRead(char *sname) |
23077 | 848 { |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
849 char *skinfname; |
32873 | 850 FILE *skinFile; |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
851 unsigned char line[256]; |
33075 | 852 unsigned char item[32]; |
32873 | 853 unsigned char param[256]; |
32944 | 854 unsigned int i; |
32873 | 855 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
856 skinfname = setname(skinDirInHome, sname); |
23077 | 857 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
858 if ((skinFile = fopen(skinfname, "rt")) == NULL) { |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
859 skinfname = setname(skinMPlayerDir, sname); |
32873 | 860 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
861 if ((skinFile = fopen(skinfname, "rt")) == NULL) { |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
862 mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_SkinFileNotFound, skinfname); |
32873 | 863 return -1; |
864 } | |
23077 | 865 } |
32873 | 866 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
867 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin] configuration file: %s\n", skinfname); |
23077 | 868 |
32932 | 869 appFreeStruct(); |
23077 | 870 |
33078 | 871 skin = NULL; |
872 currWinName[0] = 0; | |
33079 | 873 linenumber = 0; |
23077 | 874 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
875 while (fgets(line, sizeof(line), skinFile)) { |
32873 | 876 linenumber++; |
877 | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
878 line[strcspn(line, "\n\r")] = 0; // remove any kind of newline, if any |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
879 strswap(line, '\t', ' '); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
880 trim(line); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
881 decomment(line); |
32873 | 882 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
883 if (!*line) |
32873 | 884 continue; |
23077 | 885 |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
886 cutItem(line, item, '=', 0); |
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
887 cutItem(line, param, '=', 1); |
33075 | 888 strlower(item); |
32873 | 889 |
33076
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
890 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
|
891 if (!strcmp(item, skinItem[i].name)) { |
32873 | 892 if (skinItem[i].func(param) != 0) |
893 return -2; | |
33076
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
894 else |
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
895 break; |
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
896 } |
27999e9c1b3f
Leave loop after item function has been found and called.
ib
parents:
33075
diff
changeset
|
897 } |
33077 | 898 |
899 if (i == FF_ARRAY_ELEMS(skinItem)) { | |
900 skin_error(MSGTR_SKIN_UNKNOWN_ITEM, item); | |
901 return -2; | |
902 } | |
32873 | 903 } |
904 | |
905 if (linenumber == 0) { | |
33081
d217fdc83e63
(Almost entirely) cosmetic: Use more appropriate variable names.
ib
parents:
33079
diff
changeset
|
906 mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_SkinFileNotReadable, skinfname); |
32873 | 907 return -1; |
908 } | |
909 | |
910 return 0; | |
23077 | 911 } |