Reindent
[mplayer/glamo.git] / gui / skin / skin.c
blob064bde68cbbfc4b3f116f5f59886571d9818427a
1 /*
2 * This file is part of MPlayer.
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.
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.
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.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
23 #include "cut.h"
24 #include "font.h"
25 #include "gui/app.h"
27 #include "config.h"
28 #include "mp_msg.h"
29 #include "help_mp.h"
30 #include "gui/mplayer/widgets.h"
31 #include "libavutil/avstring.h"
33 //#define MSGL_DBG2 MSGL_STATUS
35 listItems * skinAppMPlayer = &appMPlayer;
37 // ---
39 static int linenumber;
41 static unsigned char path[512],fn[512];
43 static listItems * defList = NULL;
44 static unsigned char window_name[32] = "";
46 static wItem * currSection = NULL;
47 static int * currSubItem = NULL;
48 static wItem * currSubItems = NULL;
50 #include <stdarg.h>
52 void ERRORMESSAGE( const char * format, ... )
54 char p[512];
55 char tmp[512];
56 va_list ap;
57 va_start( ap,format );
58 vsnprintf( p,512,format,ap );
59 va_end( ap );
60 mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_SKIN_ERRORMESSAGE,linenumber,p );
61 snprintf( tmp,512,MSGTR_SKIN_ERRORMESSAGE,linenumber,p );
62 gtkMessageBox( GTK_MB_FATAL,tmp );
65 #define CHECKDEFLIST( str ) \
66 { \
67 if ( defList == NULL ) \
68 { \
69 mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_SKIN_WARNING1,linenumber,str ); \
70 return 1; \
71 } \
74 #define CHECKWINLIST( str ) \
75 { \
76 if ( !window_name[0] ) \
77 { \
78 mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_SKIN_WARNING2,linenumber,str ); \
79 return 1; \
80 } \
83 #define CHECK( name ) \
84 { \
85 if ( !strcmp( window_name,name ) ) \
86 { \
87 mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_SKIN_WARNING3,linenumber,name ); \
88 return 1; \
89 } \
92 static char * strlower( char * in )
94 int i;
95 for( i=0;i<(int)strlen( in );i++ ) in[i]=( in[i] >= 'A' ? ( in[i] <= 'Z' ? in[i]+='A' : in[i] ) : in[i] );
96 return in;
99 int skinBPRead( char * fname, txSample * bf )
101 int i=bpRead( fname,bf );
102 switch ( i )
104 case -1: ERRORMESSAGE( MSGTR_SKIN_BITMAP_16bit,fname ); break;
105 case -2: ERRORMESSAGE( MSGTR_SKIN_BITMAP_FileNotFound,fname ); break;
106 case -3: ERRORMESSAGE( MSGTR_SKIN_BITMAP_BMPReadError,fname ); break;
107 case -4: ERRORMESSAGE( MSGTR_SKIN_BITMAP_TGAReadError,fname ); break;
108 case -5: ERRORMESSAGE( MSGTR_SKIN_BITMAP_PNGReadError,fname ); break;
109 case -6: ERRORMESSAGE( MSGTR_SKIN_BITMAP_RLENotSupported,fname ); break;
110 case -7: ERRORMESSAGE( MSGTR_SKIN_BITMAP_UnknownFileType,fname ); break;
111 case -8: ERRORMESSAGE( MSGTR_SKIN_BITMAP_ConversionError,fname ); break;
113 return i;
116 int cmd_section( char * in )
118 strlower( in );
119 defList=NULL;
120 if ( !strcmp( in,"movieplayer" ) ) defList=skinAppMPlayer;
121 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] sectionname: %s\n",in );
122 return 0;
125 int cmd_end( char * in )
127 if ( strlen( window_name ) ) { window_name[0]=0; currSection=NULL; currSubItem=NULL; currSubItems=NULL; }
128 else defList=NULL;
129 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] end section\n" );
130 return 0;
133 int cmd_window( char * in )
135 CHECKDEFLIST( "window" );
137 av_strlcpy( window_name,strlower( in ),sizeof( window_name ) );
138 if ( !strncmp( in,"main",4 ) ) { currSection=&skinAppMPlayer->main; currSubItem=&skinAppMPlayer->NumberOfItems; currSubItems=skinAppMPlayer->Items; }
139 else if ( !strncmp( in,"sub",3 ) ) currSection=&skinAppMPlayer->sub;
140 else if ( !strncmp( in,"playbar",7 ) ) { currSection=&skinAppMPlayer->bar; currSubItem=&skinAppMPlayer->NumberOfBarItems; currSubItems=skinAppMPlayer->barItems; }
141 else if ( !strncmp( in,"menu",4 ) ) { currSection=&skinAppMPlayer->menuBase; currSubItem=&skinAppMPlayer->NumberOfMenuItems; currSubItems=skinAppMPlayer->MenuItems; }
142 else ERRORMESSAGE( MSGTR_UNKNOWNWINDOWTYPE );
143 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] window: %s\n",window_name );
144 return 0;
147 int cmd_base( char * in )
149 unsigned char fname[512];
150 unsigned char tmp[512];
151 int x,y;
152 int sx=0,sy=0;
154 CHECKDEFLIST( "base" );
155 CHECKWINLIST( "base" );
157 cutItem( in,fname,',',0 );
158 x=cutItemToInt( in,',',1 );
159 y=cutItemToInt( in,',',2 );
160 sx=cutItemToInt( in,',',3 );
161 sy=cutItemToInt( in,',',4 );
162 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] base: %s x: %d y: %d ( %dx%d )\n",fname,x,y,sx,sy );
163 if ( !strcmp( window_name,"main" ) )
165 defList->main.x=x;
166 defList->main.y=y;
167 defList->main.type=itBase;
168 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, fname, sizeof( tmp ));
169 if ( skinBPRead( tmp,&defList->main.Bitmap ) ) return 1;
170 defList->main.width=defList->main.Bitmap.Width;
171 defList->main.height=defList->main.Bitmap.Height;
172 #ifdef CONFIG_XSHAPE
173 Convert32to1( &defList->main.Bitmap,&defList->main.Mask,0x00ff00ff );
174 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] mask: %dx%d\n",defList->main.Mask.Width,defList->main.Mask.Height );
175 #else
176 defList->main.Mask.Image=NULL;
177 #endif
178 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] width: %d height: %d\n",defList->main.width,defList->main.height );
180 if ( !strcmp( window_name,"sub" ) )
182 defList->sub.type=itBase;
183 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, fname, sizeof( tmp ));
184 if ( skinBPRead( tmp,&defList->sub.Bitmap ) ) return 1;
185 defList->sub.x=x;
186 defList->sub.y=y;
187 defList->sub.width=defList->sub.Bitmap.Width;
188 defList->sub.height=defList->sub.Bitmap.Height;
189 if ( sx && sy )
191 defList->sub.width=sx;
192 defList->sub.height=sy;
194 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] %d,%d %dx%d\n",defList->sub.x,defList->sub.y,defList->sub.width,defList->sub.height );
196 if ( !strcmp( window_name,"menu" ) )
198 defList->menuIsPresent=1;
199 defList->menuBase.type=itBase;
200 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, fname, sizeof( tmp ));
201 if ( skinBPRead( tmp,&defList->menuBase.Bitmap ) ) return 1;
202 defList->menuBase.width=defList->menuBase.Bitmap.Width;
203 defList->menuBase.height=defList->menuBase.Bitmap.Height;
204 #ifdef CONFIG_XSHAPE
205 Convert32to1( &defList->menuBase.Bitmap,&defList->menuBase.Mask,0x00ff00ff );
206 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] mask: %dx%d\n",defList->menuBase.Mask.Width,defList->menuBase.Mask.Height );
207 #else
208 defList->menuBase.Mask.Image=NULL;
209 #endif
210 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] width: %d height: %d\n",defList->menuBase.width,defList->menuBase.height );
212 if ( !strcmp( window_name,"playbar" ) )
214 defList->barIsPresent=1;
215 defList->bar.x=x;
216 defList->bar.y=y;
217 defList->bar.type=itBase;
218 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, fname, sizeof( tmp ));
219 if ( skinBPRead( tmp,&defList->bar.Bitmap ) ) return 1;
220 defList->bar.width=defList->bar.Bitmap.Width;
221 defList->bar.height=defList->bar.Bitmap.Height;
222 #ifdef CONFIG_XSHAPE
223 Convert32to1( &defList->bar.Bitmap,&defList->bar.Mask,0x00ff00ff );
224 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] mask: %dx%d\n",defList->bar.Mask.Width,defList->bar.Mask.Height );
225 #else
226 defList->bar.Mask.Image=NULL;
227 #endif
228 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] width: %d height: %d\n",defList->bar.width,defList->bar.height );
230 return 0;
233 int cmd_background( char * in )
235 CHECKDEFLIST( "background" );
236 CHECKWINLIST( "background" );
238 CHECK( "menu" );
239 CHECK( "main" );
241 currSection->R=cutItemToInt( in,',',0 );
242 currSection->G=cutItemToInt( in,',',1 );
243 currSection->B=cutItemToInt( in,',',2 );
244 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] background color is #%x%x%x.\n",currSection->R,currSection->G,currSection->B );
246 return 0;
249 int cmd_button( char * in )
251 unsigned char fname[512];
252 unsigned char tmp[512];
253 int x,y,sx,sy;
254 char msg[32];
256 CHECKDEFLIST( "button" );
257 CHECKWINLIST( "button" );
259 CHECK( "sub" );
260 CHECK( "menu" );
262 cutItem( in,fname,',',0 );
263 x=cutItemToInt( in,',',1 );
264 y=cutItemToInt( in,',',2 );
265 sx=cutItemToInt( in,',',3 );
266 sy=cutItemToInt( in,',',4 );
267 cutItem( in,msg,',',5 );
269 (*currSubItem)++;
270 currSubItems[ *currSubItem ].type=itButton;
271 currSubItems[ *currSubItem ].x=x;
272 currSubItems[ *currSubItem ].y=y;
273 currSubItems[ *currSubItem ].width=sx;
274 currSubItems[ *currSubItem ].height=sy;
275 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] button: fname: %s\n",fname );
276 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] x: %d y: %d sx: %d sy: %d\n",x,y,sx,sy );
278 if ( ( currSubItems[ *currSubItem ].msg=appFindMessage( msg ) ) == -1 )
279 { ERRORMESSAGE( MSGTR_SKIN_BITMAP_UnknownMessage,msg ); return 0; }
280 currSubItems[ *currSubItem ].pressed=btnReleased;
281 if ( currSubItems[ *currSubItem ].msg == evPauseSwitchToPlay ) currSubItems[ *currSubItem ].pressed=btnDisabled;
282 currSubItems[ *currSubItem ].tmp=1;
284 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] message: %d\n",currSubItems[ *currSubItem ].msg );
286 currSubItems[ *currSubItem ].Bitmap.Image=NULL;
287 if ( strcmp( fname,"NULL" ) )
289 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, fname, sizeof( tmp ));
290 if ( skinBPRead( tmp,&currSubItems[ *currSubItem ].Bitmap ) ) return 1;
293 return 0;
296 int cmd_selected( char * in )
298 unsigned char fname[512];
299 unsigned char tmp[512];
301 CHECKDEFLIST( "selected" );
302 CHECKWINLIST( "selected" );
304 CHECK( "main" );
305 CHECK( "sub" );
306 CHECK( "playbar" );
308 cutItem( in,fname,',',0 );
309 defList->menuSelected.type=itBase;
310 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, fname, sizeof( tmp ));
311 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] selected: %s\n",fname );
312 if ( skinBPRead( tmp,&defList->menuSelected.Bitmap ) ) return 1;
313 defList->menuSelected.width=defList->menuSelected.Bitmap.Width;
314 defList->menuSelected.height=defList->menuSelected.Bitmap.Height;
315 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] width: %d height: %d\n",defList->menuSelected.width,defList->menuSelected.height );
316 return 0;
319 int cmd_menu( char * in )
320 { // menu = number,x,y,sx,sy,msg
321 int x,y,sx,sy,msg;
322 unsigned char tmp[64];
324 CHECKDEFLIST( "menu" );
325 CHECKWINLIST( "menu" );
327 CHECK( "main" );
328 CHECK( "sub" );
329 CHECK( "playbar" );
331 x=cutItemToInt( in,',',0 );
332 y=cutItemToInt( in,',',1 );
333 sx=cutItemToInt( in,',',2 );
334 sy=cutItemToInt( in,',',3 );
335 cutItem( in,tmp,',',4 ); msg=appFindMessage( tmp );
337 defList->NumberOfMenuItems++;
338 defList->MenuItems[ defList->NumberOfMenuItems ].x=x;
339 defList->MenuItems[ defList->NumberOfMenuItems ].y=y;
340 defList->MenuItems[ defList->NumberOfMenuItems ].width=sx;
341 defList->MenuItems[ defList->NumberOfMenuItems ].height=sy;
343 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] menuitem: %d\n",defList->NumberOfMenuItems );
344 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] x: %d y: %d sx: %d sy: %d\n",x,y,sx,sy );
346 if ( ( defList->MenuItems[ defList->NumberOfMenuItems ].msg=msg ) == -1 )
347 ERRORMESSAGE( MSGTR_SKIN_BITMAP_UnknownMessage,tmp );
349 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] message: %d\n",defList->Items[ defList->NumberOfItems ].msg );
351 defList->MenuItems[ defList->NumberOfMenuItems ].Bitmap.Image=NULL;
352 return 0;
355 int cmd_hpotmeter( char * in )
356 { // hpotmeter=buttonbitmaps,sx,sy,phasebitmaps,phases,default value,x,y,sx,sy,msg
357 int x,y,psx,psy,ph,sx,sy,msg,d;
358 unsigned char tmp[512];
359 unsigned char pfname[512];
360 unsigned char phfname[512];
361 wItem * item;
363 CHECKDEFLIST( "hpotmeter" );
364 CHECKWINLIST( "hpotmeter" );
366 CHECK( "sub" );
367 CHECK( "menu" );
369 cutItem( in,pfname,',',0 );
370 psx=cutItemToInt( in,',',1 );
371 psy=cutItemToInt( in,',',2 );
372 cutItem( in,phfname,',',3 );
373 ph=cutItemToInt( in,',',4 );
374 d=cutItemToInt( in,',',5 );
375 x=cutItemToInt( in,',',6 );
376 y=cutItemToInt( in,',',7 );
377 sx=cutItemToInt( in,',',8 );
378 sy=cutItemToInt( in,',',9 );
379 cutItem( in,tmp,',',10 ); msg=appFindMessage( tmp );
381 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] h/v potmeter: pointer filename: '%s'\n",pfname );
382 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] pointer size is %dx%d\n",psx,psy );
383 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] phasebitmaps filename: '%s'\n",phfname );
384 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] position: %d,%d %dx%d\n",x,y,sx,sy );
385 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] default value: %d\n",d );
386 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] message: %d\n",msg );
388 (*currSubItem)++;
389 item=&currSubItems[ *currSubItem ];
391 item->type=itHPotmeter;
392 item->x=x; item->y=y; item->width=sx; item->height=sy;
393 item->phases=ph;
394 item->psx=psx; item->psy=psy;
395 item->msg=msg;
396 item->value=(float)d;
397 item->pressed=btnReleased;
399 item->Bitmap.Image=NULL;
400 if ( strcmp( phfname,"NULL" ) )
402 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, phfname, sizeof( tmp ));
403 if ( skinBPRead( tmp,&item->Bitmap ) ) return 1;
406 item->Mask.Image=NULL;
407 if ( strcmp( pfname,"NULL" ) )
409 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, pfname, sizeof( tmp ));
410 if ( skinBPRead( tmp,&item->Mask ) ) return 1;
412 return 0;
415 int cmd_vpotmeter( char * in )
417 int r = cmd_hpotmeter( in );
418 wItem * item;
420 item=&currSubItems[ *currSubItem ];
421 item->type=itVPotmeter;
422 return r;
425 int cmd_potmeter( char * in )
426 { // potmeter=phasebitmaps,phases,default value,x,y,sx,sy,msg
427 int x,y,ph,sx,sy,msg,d;
428 unsigned char tmp[512];
429 unsigned char phfname[512];
430 wItem * item;
432 CHECKDEFLIST( "potmeter" );
433 CHECKWINLIST( "potmeter" );
435 CHECK( "sub" );
436 CHECK( "menu" );
438 cutItem( in,phfname,',',0 );
439 ph=cutItemToInt( in,',',1 );
440 d=cutItemToInt( in,',',2 );
441 x=cutItemToInt( in,',',3 );
442 y=cutItemToInt( in,',',4 );
443 sx=cutItemToInt( in,',',5 );
444 sy=cutItemToInt( in,',',6 );
445 cutItem( in,tmp,',',7 ); msg=appFindMessage( tmp );
447 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] potmeter: phases filename: '%s'\n",phfname );
448 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] position: %d,%d %dx%d\n",x,y,sx,sy );
449 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] phases: %d\n",ph );
450 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] default value: %d\n",d );
451 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] message: %d\n",msg );
453 (*currSubItem)++;
454 item=&currSubItems[ *currSubItem ];
456 item->type=itPotmeter;
457 item->x=x; item->y=y;
458 item->width=sx; item->height=sy;
459 item->phases=ph;
460 item->msg=msg;
461 item->value=(float)d;
463 item->Bitmap.Image=NULL;
464 if ( strcmp( phfname,"NULL" ) )
466 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, phfname, sizeof( tmp ));
467 if ( skinBPRead( tmp,&item->Bitmap ) ) return 1;
469 return 0;
472 int cmd_font( char * in )
473 { // font=fontname,fontid
474 char name[512];
475 char id[512];
476 wItem * item;
478 CHECKDEFLIST( "font" );
479 CHECKWINLIST( "font" );
481 CHECK( "sub" );
482 CHECK( "menu" );
484 cutItem( in,name,',',0 );
485 cutItem( in,id,',',1 );
487 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] font\n" );
488 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] name: %s\n",name );
490 (*currSubItem)++;
491 item=&currSubItems[ *currSubItem ];
493 item->type=itFont;
494 item->fontid=fntRead( path,name );
495 switch ( item->fontid )
497 case -1: ERRORMESSAGE( MSGTR_SKIN_FONT_NotEnoughtMemory ); return 1;
498 case -2: ERRORMESSAGE( MSGTR_SKIN_FONT_TooManyFontsDeclared ); return 1;
499 case -3: ERRORMESSAGE( MSGTR_SKIN_FONT_FontFileNotFound ); return 1;
500 case -4: ERRORMESSAGE( MSGTR_SKIN_FONT_FontImageNotFound ); return 1;
502 return 0;
505 int cmd_slabel( char * in )
507 char tmp[512];
508 char sid[63];
509 int x,y,id;
510 wItem * item;
512 CHECKDEFLIST( "slabel" );
513 CHECKWINLIST( "slabel" );
515 CHECK( "sub" );
516 CHECK( "menu" );
518 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] slabel\n" );
520 x=cutItemToInt( in,',',0 );
521 y=cutItemToInt( in,',',1 );
522 cutItem( in,sid,',',2 ); id=fntFindID( sid );
523 if ( id < 0 ) { ERRORMESSAGE( MSGTR_SKIN_FONT_NonExistentFontID,sid ); return 1; }
524 cutItem( in,tmp,',',3 ); cutItem( tmp,tmp,'"',1 );
526 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] pos: %d,%d\n",x,y );
527 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] id: %s ( %d )\n",sid,id );
528 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] str: '%s'\n",tmp );
530 (*currSubItem)++;
531 item=&currSubItems[ *currSubItem ];
533 item->type=itSLabel;
534 item->fontid=id;
535 item->x=x; item->y=y;
536 item->width=-1; item->height=-1;
537 if ( ( item->label=malloc( strlen( tmp ) + 1 ) ) == NULL ) { ERRORMESSAGE( MSGTR_SKIN_FONT_NotEnoughtMemory ); return 1; }
538 strcpy( item->label,tmp );
540 return 0;
543 int cmd_dlabel( char * in )
544 { // dlabel=x,y,sx,align,fontid,string ...
545 char tmp[512];
546 char sid[63];
547 int x,y,sx,id,a;
548 wItem * item;
550 CHECKDEFLIST( "dlabel" );
551 CHECKWINLIST( "dlabel" );
553 CHECK( "sub" );
554 CHECK( "menu" );
556 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] dlabel\n" );
558 x=cutItemToInt( in,',',0 );
559 y=cutItemToInt( in,',',1 );
560 sx=cutItemToInt( in,',',2 );
561 a=cutItemToInt( in,',',3 );
562 cutItem( in,sid,',',4 ); id=fntFindID( sid );
563 if ( id < 0 ) { ERRORMESSAGE( MSGTR_SKIN_FONT_NonExistentFontID,sid ); return 1; }
564 cutItem( in,tmp,',',5 ); cutItem( tmp,tmp,'"',1 );
566 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] pos: %d,%d width: %d align: %d\n",x,y,sx,a );
567 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] id: %s ( %d )\n",sid,id );
568 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] str: '%s'\n",tmp );
570 (*currSubItem)++;
571 item=&currSubItems[ *currSubItem ];
573 item->type=itDLabel;
574 item->fontid=id; item->align=a;
575 item->x=x; item->y=y;
576 item->width=sx; item->height=-1;
577 if ( ( item->label=malloc( strlen( tmp ) + 1 ) ) == NULL ) { ERRORMESSAGE( MSGTR_SKIN_FONT_NotEnoughtMemory ); return 1; }
578 strcpy( item->label,tmp );
580 return 0;
583 int cmd_decoration( char * in )
585 char tmp[512];
587 CHECKDEFLIST( "decoration" );
588 CHECKWINLIST( "decoration" );
590 CHECK( "sub" );
591 CHECK( "menu" );
592 CHECK( "playbar" );
594 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] window decoration is %s\n",in );
595 strlower( in );
596 cutItem( in,tmp,',',0 );
597 if ( strcmp( tmp,"enable" )&&strcmp( tmp,"disable" ) ) { ERRORMESSAGE( MSGTR_SKIN_UnknownParameter,tmp ); return 1; }
598 if ( strcmp( tmp,"enable" ) ) defList->mainDecoration=0;
599 else defList->mainDecoration=1;
601 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] window decoration is %s\n",(defList->mainDecoration?"enabled":"disabled") );
602 return 0;
605 typedef struct
607 const char * name;
608 int (*func)( char * in );
609 } _item;
611 _item skinItem[] =
613 { "section", cmd_section },
614 { "end", cmd_end },
615 { "window", cmd_window },
616 { "base", cmd_base },
617 { "button", cmd_button },
618 { "selected", cmd_selected },
619 { "background", cmd_background },
620 { "vpotmeter", cmd_vpotmeter },
621 { "hpotmeter", cmd_hpotmeter },
622 { "potmeter", cmd_potmeter },
623 { "font", cmd_font },
624 { "slabel", cmd_slabel },
625 { "dlabel", cmd_dlabel },
626 { "decoration", cmd_decoration },
627 { "menu", cmd_menu }
630 #define ITEMS (int)( sizeof( skinItem )/sizeof( _item ) )
632 char * trimleft( char * in )
634 int c = 0;
635 char * out;
636 if ( strlen( in ) == 0 ) return NULL;
637 while ( in[c] == ' ' ) c++;
638 if ( c != 0 )
640 out=malloc( strlen( in ) - c + 1 );
641 memcpy( out,&in[c],strlen( in ) - c + 1 );
643 else out=in;
644 return out;
647 char * strswap( char * in,char what,char whereof )
649 int i;
650 if ( strlen( in ) == 0 ) return NULL;
651 for ( i=0;i<(int)strlen( in );i++ )
652 if ( in[i] == what ) in[i]=whereof;
653 return in;
656 char * trim( char * in )
658 int c = 0,i = 0,id = 0;
659 if ( strlen( in ) == 0 ) return NULL;
660 while ( c != (int)strlen( in ) )
662 if ( in[c] == '"' ) id=!id;
663 if ( ( in[c] == ' ' )&&( !id ) )
665 for ( i=0;i<(int)strlen( in ) - c; i++ ) in[c+i]=in[c+i+1];
666 continue;
668 c++;
670 return in;
673 FILE * skinFile;
675 void setname( char * item1, char * item2 )
677 av_strlcpy(fn, item1, sizeof( fn ));
678 av_strlcat(fn, "/", sizeof( fn )); av_strlcat(fn, item2, sizeof( fn ));
679 av_strlcpy(path, fn, sizeof( path )); av_strlcat(path, "/", sizeof( path ));
680 av_strlcat(fn, "/skin", sizeof( fn ));
683 int skinRead( char * dname )
685 unsigned char tmp[255];
686 unsigned char * ptmp;
687 unsigned char command[32];
688 unsigned char param[256];
689 int c,i;
691 setname( skinDirInHome,dname );
692 if ( ( skinFile = fopen( fn,"rt" ) ) == NULL )
694 setname( skinMPlayerDir,dname );
695 if ( ( skinFile = fopen( fn,"rt" ) ) == NULL )
697 setname( skinDirInHome_obsolete,dname );
698 if ( ( skinFile = fopen( fn,"rt" ) ) == NULL )
700 setname( skinMPlayerDir_obsolete,dname );
701 if ( ( skinFile = fopen( fn,"rt" ) ) == NULL )
703 setname( skinMPlayerDir,dname );
704 mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_SKIN_SkinFileNotFound,fn );
705 return -1;
711 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] file: %s\n",fn );
713 appInitStruct( skinAppMPlayer );
715 linenumber=0;
716 while (fgets(tmp, 255, skinFile))
718 linenumber++;
720 c=tmp[ strlen( tmp ) - 1 ]; if ( c == '\n' || c == '\r' ) tmp[ strlen( tmp ) - 1 ]=0;
721 c=tmp[ strlen( tmp ) - 1 ]; if ( c == '\n' || c == '\r' ) tmp[ strlen( tmp ) - 1 ]=0;
722 for ( c=0;c<(int)strlen( tmp );c++ )
723 if ( tmp[c] == ';' )
725 tmp[c]=0;
726 break;
728 if ( strlen( tmp ) == 0 ) continue;
729 ptmp=trimleft( tmp );
730 if ( strlen( ptmp ) == 0 ) continue;
731 ptmp=strswap( ptmp,'\t',' ' );
732 ptmp=trim( ptmp );
734 cutItem( ptmp,command,'=',0 ); cutItem( ptmp,param,'=',1 );
735 strlower( command );
736 for( i=0;i<ITEMS;i++ )
737 if ( !strcmp( command,skinItem[i].name ) )
738 if ( skinItem[i].func( param ) ) return -2;
740 if (linenumber == 0) {
741 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_SKIN_SkinFileNotReadable, fn);
742 return -1;
744 return 0;