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