Mercurial > mplayer.hg
annotate Gui/skin/skin.c @ 1866:32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
author | pontscho |
---|---|
date | Fri, 07 Sep 2001 21:04:14 +0000 |
parents | 58dd326fcc4a |
children | d21f8afc7680 |
rev | line source |
---|---|
1729 | 1 |
1693 | 2 #include <stdio.h> |
3 #include <stdlib.h> | |
4 #include <string.h> | |
5 | |
6 #include "cut.h" | |
7 #include "error.h" | |
8 #include "font.h" | |
9 #include "../app.h" | |
10 #include "../language.h" | |
11 #include "../../config.h" | |
12 | |
13 listItems * skinAppMPlayer = &appMPlayer; | |
14 | |
15 int linenumber; | |
16 | |
17 unsigned char path[512],fn[512]; | |
18 | |
19 listItems * defList = NULL; | |
20 unsigned char winList[32] = ""; | |
21 | |
22 #include <stdarg.h> | |
23 | |
24 void ERRORMESSAGE( const char * format, ... ) | |
25 { | |
26 char p[512]; | |
27 va_list ap; | |
28 va_start( ap,format ); | |
29 vsnprintf( p,512,format,ap ); | |
30 va_end( ap ); | |
31 message( False,"[skin] error in skin config file on line %d: %s",linenumber,p ); | |
32 } | |
33 | |
34 #define CHECKDEFLIST( str ) { \ | |
35 if ( defList == NULL ) \ | |
36 { \ | |
37 message( False,"[skin] warning in skin config file on line %d: widget found but before \"section\" not found ("str")",linenumber ); \ | |
38 return 1; \ | |
39 } \ | |
40 } | |
41 #define CHECKWINLIST( str ) { \ | |
42 if ( !strlen( winList ) ) \ | |
43 { \ | |
44 message( False,"[skin] warning in skin config file on line %d: widget found but before \"subsection\" not found ("str")",linenumber ); \ | |
45 return 1; \ | |
46 } \ | |
47 } | |
48 | |
49 char * strlower( char * in ) | |
50 { | |
51 int i; | |
52 for( i=0;i<strlen( in );i++ ) in[i]=( in[i] >= 'A' ? ( in[i] <= 'Z' ? in[i]+='A' : in[i] ) : in[i] ); | |
53 return in; | |
54 } | |
55 | |
56 int skinBPRead( char * fname, txSample * bf ) | |
57 { | |
58 int i=bpRead( fname,bf ); | |
59 switch ( i ) | |
60 { | |
61 case -1: ERRORMESSAGE( "16 bits or less depth bitmap not supported ( %s ).\n",fname ); break; | |
62 case -2: ERRORMESSAGE( "file not found ( %s )\n",fname ); break; | |
63 case -3: ERRORMESSAGE( "bmp read error ( %s )\n",fname ); break; | |
64 case -4: ERRORMESSAGE( "tga read error ( %s )\n",fname ); break; | |
65 case -5: ERRORMESSAGE( "png read error ( %s )\n",fname ); break; | |
66 case -6: ERRORMESSAGE( "RLE packed tga not supported ( %s )\n",fname ); break; | |
67 case -7: ERRORMESSAGE( "unknown file type ( %s )\n",fname ); break; | |
68 case -8: ERRORMESSAGE( "24 bit to 32 bit convert error ( %s )\n",fname ); break; | |
69 } | |
70 return i; | |
71 } | |
72 | |
73 int __section( char * in ) | |
74 { | |
75 strlower( in ); | |
76 defList=NULL; | |
77 if ( !strcmp( in,"movieplayer" ) ) defList=skinAppMPlayer; | |
78 #ifdef DEBUG | |
79 dbprintf( 3,"\n[skin] sectionname: %s\n",in ); | |
80 #endif | |
81 return 0; | |
82 } | |
83 | |
84 int __end( char * in ) | |
85 { | |
86 if ( strlen( winList ) ) winList[0]=0; | |
87 else defList=NULL; | |
88 #ifdef DEBUG | |
89 dbprintf( 3,"\n[skin] end section\n" ); | |
90 #endif | |
91 return 0; | |
92 } | |
93 | |
94 int __window( char * in ) | |
95 { | |
96 CHECKDEFLIST( "window" ); | |
97 | |
98 strlower( in ); | |
99 strcpy( winList,in ); | |
100 #ifdef DEBUG | |
101 dbprintf( 3,"\n[skin] window: %s\n",winList ); | |
102 #endif | |
103 return 0; | |
104 } | |
105 | |
106 int __base( char * in ) | |
107 { | |
108 unsigned char fname[512]; | |
109 unsigned char tmp[512]; | |
110 int x,y; | |
111 | |
112 CHECKDEFLIST( "base" ); | |
113 CHECKWINLIST( "base" ); | |
114 | |
115 cutItem( in,fname,',',0 ); | |
1852 | 116 x=cutItemToInt( in,',',1 ); |
117 y=cutItemToInt( in,',',2 ); | |
1693 | 118 #ifdef DEBUG |
119 dbprintf( 3,"\n[skin] base: %s x: %d y: %d\n",fname,x,y ); | |
120 #endif | |
121 if ( !strcmp( winList,"main" ) ) | |
122 { | |
123 defList->main.x=x; | |
124 defList->main.y=y; | |
125 defList->main.type=itBase; | |
126 strcpy( tmp,path ); strcat( tmp,fname ); | |
127 if ( skinBPRead( tmp,&defList->main.Bitmap ) ) return 1; | |
128 defList->main.width=defList->main.Bitmap.Width; | |
129 defList->main.height=defList->main.Bitmap.Height; | |
130 #ifdef HAVE_XSHAPE | |
131 defList->main.Mask.Width=defList->main.Bitmap.Width; | |
132 defList->main.Mask.Height=defList->main.Bitmap.Height; | |
133 defList->main.Mask.BPP=1; | |
134 defList->main.Mask.ImageSize=defList->main.Mask.Width * defList->main.Mask.Height / 8; | |
135 defList->main.Mask.Image=(char *)calloc( 1,defList->main.Mask.ImageSize ); | |
136 if ( defList->main.Mask.Image == NULL ) message( True,langNEMFMM ); | |
137 { | |
1852 | 138 int i,b,c=0; unsigned long * buf = NULL; unsigned char tmp = 0; int nothaveshape = 1; |
1693 | 139 buf=(unsigned long *)defList->main.Bitmap.Image; |
140 for ( b=0,i=0;i < defList->main.Mask.Width * defList->main.Mask.Height;i++ ) | |
141 { | |
142 if ( buf[i] != 0x00ff00ff ) tmp=( tmp >> 1 )|128; | |
1852 | 143 else { tmp=tmp >> 1; buf[i]=nothaveshape=0; } |
144 if ( b++ == 7 ) { defList->main.Mask.Image[c++]=tmp; tmp=b=0; } | |
1693 | 145 } |
1852 | 146 if ( b ) defList->main.Mask.Image[c]=tmp; |
147 if ( nothaveshape ) { free( defList->main.Mask.Image ); defList->main.Mask.Image=NULL; } | |
1693 | 148 } |
149 #ifdef DEBUG | |
1852 | 150 dbprintf( 3,"[skin] mask: %dx%d\n",defList->main.Mask.Width,defList->main.Mask.Height ); |
1693 | 151 #endif |
152 #else | |
153 defList->main.Mask.Image=NULL; | |
154 #endif | |
155 #ifdef DEBUG | |
156 dbprintf( 3,"[skin] width: %d height: %d\n",defList->main.width,defList->main.height ); | |
157 #endif | |
158 } | |
159 if ( !strcmp( winList,"sub" ) ) | |
160 { | |
161 defList->sub.x=x; | |
162 defList->sub.y=y; | |
163 defList->sub.type=itBase; | |
164 strcpy( tmp,path ); strcat( tmp,fname ); | |
165 if ( skinBPRead( tmp,&defList->sub.Bitmap ) ) return 1; | |
166 defList->sub.width=defList->sub.Bitmap.Width; | |
167 defList->sub.height=defList->sub.Bitmap.Height; | |
168 #ifdef DEBUG | |
169 dbprintf( 3,"[skin] width: %d height: %d\n",defList->sub.width,defList->sub.height ); | |
170 #endif | |
171 } | |
172 /* | |
173 if ( !strcmp( winList,"eq" ) ) | |
174 { | |
175 defList->eq.x=x; | |
176 defList->eq.y=y; | |
177 defList->eq.type=itBase; | |
178 strcpy( tmp,path ); strcat( tmp,fname ); | |
179 if ( skinBPRead( tmp,&defList->eq.Bitmap ) ) return 1; | |
180 defList->eq.width=defList->eq.Bitmap.Width; | |
181 defList->eq.height=defList->eq.Bitmap.Height; | |
182 #ifdef DEBUG | |
183 dbprintf( 3,"[skin] width: %d height: %d\n",defList->eq.width,defList->eq.height ); | |
184 #endif | |
185 } | |
186 */ | |
187 if ( !strcmp( winList,"menu" ) ) | |
188 { | |
189 defList->menuBase.type=itBase; | |
190 strcpy( tmp,path ); strcat( tmp,fname ); | |
191 if ( skinBPRead( tmp,&defList->menuBase.Bitmap ) ) return 1; | |
192 defList->menuBase.width=defList->menuBase.Bitmap.Width; | |
193 defList->menuBase.height=defList->menuBase.Bitmap.Height; | |
194 #ifdef DEBUG | |
195 dbprintf( 3,"[skin] width: %d height: %d\n",defList->menuBase.width,defList->menuBase.height ); | |
196 #endif | |
197 } | |
198 return 0; | |
199 } | |
200 | |
201 int __background( char * in ) | |
202 { | |
203 CHECKDEFLIST( "background" ); | |
204 CHECKWINLIST( "background" ); | |
205 | |
206 if ( !strcmp( winList,"sub" ) ) | |
207 { | |
1852 | 208 defList->subR=cutItemToInt( in,',',0 ); |
209 defList->subG=cutItemToInt( in,',',1 ); | |
210 defList->subB=cutItemToInt( in,',',2 ); | |
1693 | 211 #ifdef DEBUG |
212 dbprintf( 3,"\n[skin] subwindow background color is #%x%x%x.\n",defList->subR,defList->subG,defList->subB ); | |
213 #endif | |
214 } | |
215 return 0; | |
216 } | |
217 | |
218 int __button( char * in ) | |
219 { | |
220 unsigned char fname[512]; | |
221 unsigned char tmp[512]; | |
222 int x,y,sx,sy; | |
223 unsigned char msg[32]; | |
224 | |
225 CHECKDEFLIST( "button" ); | |
226 CHECKWINLIST( "button" ); | |
227 | |
228 cutItem( in,fname,',',0 ); | |
1852 | 229 x=cutItemToInt( in,',',1 ); |
230 y=cutItemToInt( in,',',2 ); | |
231 sx=cutItemToInt( in,',',3 ); | |
232 sy=cutItemToInt( in,',',4 ); | |
1693 | 233 cutItem( in,msg,',',5 ); |
234 | |
235 defList->NumberOfItems++; | |
236 defList->Items[ defList->NumberOfItems ].type=itButton; | |
237 defList->Items[ defList->NumberOfItems ].x=x; | |
238 defList->Items[ defList->NumberOfItems ].y=y; | |
239 defList->Items[ defList->NumberOfItems ].width=sx; | |
240 defList->Items[ defList->NumberOfItems ].height=sy; | |
241 #ifdef DEBUG | |
242 dbprintf( 3,"\n[skin] button: fname: %s\n",fname ); | |
243 dbprintf( 3,"[skin] x: %d y: %d sx: %d sy: %d\n",x,y,sx,sy ); | |
244 #endif | |
245 | |
246 if ( ( defList->Items[ defList->NumberOfItems ].msg=appFindMessage( msg ) ) == -1 ) | |
247 { ERRORMESSAGE( "unknown message: %s\n",msg ); return 1; } | |
248 defList->Items[ defList->NumberOfItems ].pressed=btnReleased; | |
249 if ( defList->Items[ defList->NumberOfItems ].msg == evPauseSwitchToPlay ) defList->Items[ defList->NumberOfItems ].pressed=btnDisabled; | |
250 defList->Items[ defList->NumberOfItems ].tmp=1; | |
251 | |
252 #ifdef DEBUG | |
253 dbprintf( 3,"[skin] message: %d\n", | |
254 defList->Items[ defList->NumberOfItems ].msg ); | |
255 #endif | |
256 | |
257 defList->Items[ defList->NumberOfItems ].Bitmap.Image=NULL; | |
258 if ( strcmp( fname,"NULL" ) ) | |
259 { | |
260 strcpy( tmp,path ); strcat( tmp,fname ); | |
261 if ( skinBPRead( tmp,&defList->Items[ defList->NumberOfItems ].Bitmap ) ) return 1; | |
262 } | |
263 return 0; | |
264 } | |
265 | |
266 int __selected( char * in ) | |
267 { | |
268 unsigned char fname[512]; | |
269 unsigned char tmp[512]; | |
270 | |
271 CHECKDEFLIST( "selected" ); | |
272 CHECKWINLIST( "selected" ); | |
273 | |
274 cutItem( in,fname,',',0 ); | |
275 defList->menuSelected.type=itBase; | |
276 strcpy( tmp,path ); strcat( tmp,fname ); | |
277 #ifdef DEBUG | |
278 dbprintf( 3,"\n[skin] selected: %s\n",fname ); | |
279 #endif | |
280 if ( skinBPRead( tmp,&defList->menuSelected.Bitmap ) ) return 1; | |
281 defList->menuSelected.width=defList->menuSelected.Bitmap.Width; | |
282 defList->menuSelected.height=defList->menuSelected.Bitmap.Height; | |
283 #ifdef DEBUG | |
284 dbprintf( 3,"[skin] width: %d height: %d\n",defList->menuSelected.width,defList->menuSelected.height ); | |
285 #endif | |
286 return 0; | |
287 } | |
288 | |
289 int __menu( char * in ) | |
290 { // menu = number,x,y,sx,sy,msg | |
291 int x,y,sx,sy,msg; | |
292 unsigned char tmp[64]; | |
293 | |
294 CHECKDEFLIST( "menu" ); | |
295 CHECKWINLIST( "menu" ); | |
296 | |
1852 | 297 x=cutItemToInt( in,',',0 ); |
298 y=cutItemToInt( in,',',1 ); | |
299 sx=cutItemToInt( in,',',2 ); | |
300 sy=cutItemToInt( in,',',3 ); | |
1693 | 301 cutItem( in,tmp,',',4 ); msg=appFindMessage( tmp ); |
302 | |
303 defList->NumberOfMenuItems++; | |
304 defList->MenuItems[ defList->NumberOfMenuItems ].x=x; | |
305 defList->MenuItems[ defList->NumberOfMenuItems ].y=y; | |
306 defList->MenuItems[ defList->NumberOfMenuItems ].width=sx; | |
307 defList->MenuItems[ defList->NumberOfMenuItems ].height=sy; | |
308 | |
309 #ifdef DEBUG | |
310 dbprintf( 3,"\n[skin] menuitem: %d\n",defList->NumberOfMenuItems ); | |
311 dbprintf( 3,"[skin] x: %d y: %d sx: %d sy: %d\n",x,y,sx,sy ); | |
312 #endif | |
313 | |
314 if ( ( defList->MenuItems[ defList->NumberOfMenuItems ].msg=msg ) == -1 ) | |
315 ERRORMESSAGE( "unknown message: %s\n",tmp ); | |
316 | |
317 #ifdef DEBUG | |
318 dbprintf( 3,"[skin] message: %d\n",defList->Items[ defList->NumberOfItems ].msg ); | |
319 #endif | |
320 | |
321 defList->MenuItems[ defList->NumberOfMenuItems ].Bitmap.Image=NULL; | |
322 return 0; | |
323 } | |
324 | |
325 int __hpotmeter( char * in ) | |
326 { // hpotmeter=buttonbitmaps,sx,sy,phasebitmaps,phases,default value,x,y,sx,sy,msg | |
327 int x,y,psx,psy,ph,sx,sy,msg,d; | |
328 unsigned char tmp[512]; | |
329 unsigned char pfname[512]; | |
330 unsigned char phfname[512]; | |
331 wItem * item; | |
332 | |
333 CHECKDEFLIST( "hpotmeter" ); | |
334 CHECKWINLIST( "hpotmeter" ); | |
335 | |
336 cutItem( in,pfname,',',0 ); | |
1852 | 337 psx=cutItemToInt( in,',',1 ); |
338 psy=cutItemToInt( in,',',2 ); | |
1693 | 339 cutItem( in,phfname,',',3 ); |
1852 | 340 ph=cutItemToInt( in,',',4 ); |
341 d=cutItemToInt( in,',',5 ); | |
342 x=cutItemToInt( in,',',6 ); | |
343 y=cutItemToInt( in,',',7 ); | |
344 sx=cutItemToInt( in,',',8 ); | |
345 sy=cutItemToInt( in,',',9 ); | |
1693 | 346 cutItem( in,tmp,',',10 ); msg=appFindMessage( tmp ); |
347 | |
348 #ifdef DEBUG | |
349 dbprintf( 3,"\n[skin] hpotmeter: pointer filename: '%s'\n",pfname ); | |
350 dbprintf( 3, "[skin] pointer size is %dx%d\n",psx,psy ); | |
351 dbprintf( 3, "[skin] phasebitmaps filename: '%s'\n",phfname ); | |
352 dbprintf( 3, "[skin] position: %d,%d %dx%d\n",x,y,sx,sy ); | |
353 dbprintf( 3, "[skin] default value: %d\n",d ); | |
354 dbprintf( 3, "[skin] message: %d\n",msg ); | |
355 #endif | |
356 | |
357 defList->NumberOfItems++; | |
358 item=&defList->Items[ defList->NumberOfItems ]; | |
359 item->type=itHPotmeter; | |
360 item->x=x; item->y=y; item->width=sx; item->height=sy; | |
361 item->phases=ph; | |
362 item->psx=psx; item->psy=psy; | |
363 item->msg=msg; | |
364 item->value=(float)d; | |
365 item->pressed=btnReleased; | |
366 | |
367 item->Bitmap.Image=NULL; | |
368 if ( strcmp( phfname,"NULL" ) ) | |
369 { | |
370 strcpy( tmp,path ); strcat( tmp,phfname ); | |
371 if ( skinBPRead( tmp,&item->Bitmap ) ) return 1; | |
372 } | |
373 | |
374 item->Mask.Image=NULL; | |
375 if ( strcmp( pfname,"NULL" ) ) | |
376 { | |
377 strcpy( tmp,path ); strcat( tmp,pfname ); | |
378 if ( skinBPRead( tmp,&item->Mask ) ) return 1; | |
379 } | |
380 | |
381 return 0; | |
382 } | |
383 | |
384 int __potmeter( char * in ) | |
385 { // potmeter=phasebitmaps,phases,default value,x,y,sx,sy,msg | |
386 int x,y,ph,sx,sy,msg,d; | |
387 unsigned char tmp[512]; | |
388 unsigned char phfname[512]; | |
389 wItem * item; | |
390 | |
391 CHECKDEFLIST( "potmeter" ); | |
392 CHECKWINLIST( "potmeter" ); | |
393 | |
394 cutItem( in,phfname,',',0 ); | |
1852 | 395 ph=cutItemToInt( in,',',1 ); |
396 d=cutItemToInt( in,',',2 ); | |
397 x=cutItemToInt( in,',',3 ); | |
398 y=cutItemToInt( in,',',4 ); | |
399 sx=cutItemToInt( in,',',5 ); | |
400 sy=cutItemToInt( in,',',6 ); | |
1693 | 401 cutItem( in,tmp,',',7 ); msg=appFindMessage( tmp ); |
402 | |
403 #ifdef DEBUG | |
404 dbprintf( 3,"\n[skin] potmeter: phases filename: '%s'\n",phfname ); | |
405 dbprintf( 3, "[skin] position: %d,%d %dx%d\n",x,y,sx,sy ); | |
406 dbprintf( 3, "[skin] phases: %d\n",ph ); | |
407 dbprintf( 3, "[skin] default value: %d\n",d ); | |
408 dbprintf( 3, "[skin] message: %d\n",msg ); | |
409 #endif | |
410 | |
411 defList->NumberOfItems++; | |
412 item=&defList->Items[ defList->NumberOfItems ]; | |
413 item->type=itPotmeter; | |
414 item->x=x; item->y=y; | |
415 item->width=sx; item->height=sy; | |
416 item->phases=ph; | |
417 item->msg=msg; | |
418 item->value=(float)d; | |
419 | |
420 item->Bitmap.Image=NULL; | |
421 if ( strcmp( phfname,"NULL" ) ) | |
422 { | |
423 strcpy( tmp,path ); strcat( tmp,phfname ); | |
424 if ( skinBPRead( tmp,&item->Bitmap ) ) return 1; | |
425 } | |
426 return 0; | |
427 } | |
428 | |
429 int __font( char * in ) | |
430 { // font=fontname,fontid | |
431 char name[512]; | |
432 char id[512]; | |
433 wItem * item; | |
434 | |
435 CHECKDEFLIST( "font" ); | |
436 CHECKWINLIST( "font" ); | |
437 | |
438 cutItem( in,name,',',0 ); | |
439 cutItem( in,id,',',1 ); | |
440 | |
441 #ifdef DEBUG | |
442 dbprintf( 3,"\n[skin] font\n" ); | |
443 dbprintf( 3, "[skin] name: %s\n",name ); | |
444 #endif | |
445 | |
446 defList->NumberOfItems++; | |
447 item=&defList->Items[ defList->NumberOfItems ]; | |
448 item->type=itFont; | |
449 item->fontid=fntAddNewFont( name ); | |
450 switch ( item->fontid ) | |
451 { | |
452 case -1: ERRORMESSAGE( "not enought memory\n" ); return 1; | |
453 case -2: ERRORMESSAGE( "too many fonts\n" ); return 1; | |
454 } | |
455 | |
456 #ifdef DEBUG | |
457 dbprintf( 3, "[skin] id: %s ( %d )\n",id,item->fontid ); | |
458 #endif | |
459 | |
460 switch ( fntRead( path,name,item->fontid ) ) | |
461 { | |
462 case -1: ERRORMESSAGE( "font file not found\n" ); return 1; | |
463 case -2: ERRORMESSAGE( "font image not found\n" ); return 1; | |
464 } | |
465 | |
466 return 0; | |
467 } | |
468 | |
469 int __slabel( char * in ) | |
470 { | |
471 char tmp[512]; | |
472 char sid[63]; | |
473 int x,y,id; | |
474 wItem * item; | |
475 | |
476 CHECKDEFLIST( "slabel" ); | |
477 CHECKWINLIST( "slabel" ); | |
478 | |
479 #ifdef DEBUG | |
480 dbprintf( 3,"\n[skin] slabel\n" ); | |
481 #endif | |
482 | |
1852 | 483 x=cutItemToInt( in,',',0 ); |
484 y=cutItemToInt( in,',',1 ); | |
1693 | 485 cutItem( in,sid,',',2 ); id=fntFindID( sid ); |
486 if ( id < 0 ) { ERRORMESSAGE( "nonexistent font id. ( %s )\n",sid ); return 1; } | |
487 cutItem( in,tmp,',',3 ); cutItem( tmp,tmp,'"',1 ); | |
488 | |
489 #ifdef DEBUG | |
490 dbprintf( 3, "[skin] pos: %d,%d\n",x,y ); | |
491 dbprintf( 3, "[skin] id: %s ( %d )\n",sid,id ); | |
492 dbprintf( 3, "[skin] str: '%s'\n",tmp ); | |
493 #endif | |
494 | |
495 defList->NumberOfItems++; | |
496 item=&defList->Items[ defList->NumberOfItems ]; | |
497 item->type=itSLabel; | |
498 item->fontid=id; | |
499 item->x=x; item->y=y; | |
500 item->width=-1; item->height=-1; | |
501 if ( ( item->label=malloc( strlen( tmp ) + 1 ) ) == NULL ) { ERRORMESSAGE( "not enought memory.\n" ); return 1; } | |
502 strcpy( item->label,tmp ); | |
503 | |
504 return 0; | |
505 } | |
506 | |
507 int __dlabel( char * in ) | |
508 { // dlabel=x,y,sx,align,fontid,string ... | |
509 char tmp[512]; | |
510 char sid[63]; | |
511 int x,y,sx,id,a; | |
512 wItem * item; | |
513 | |
514 CHECKDEFLIST( "dlabel" ); | |
515 CHECKWINLIST( "dlabel" ); | |
516 | |
517 #ifdef DEBUG | |
518 dbprintf( 3,"\n[skin] dlabel\n" ); | |
519 #endif | |
520 | |
1852 | 521 x=cutItemToInt( in,',',0 ); |
522 y=cutItemToInt( in,',',1 ); | |
523 sx=cutItemToInt( in,',',2 ); | |
524 a=cutItemToInt( in,',',3 ); | |
1693 | 525 cutItem( in,sid,',',4 ); id=fntFindID( sid ); |
526 if ( id < 0 ) { ERRORMESSAGE( "nonexistent font id. ( %s )\n",sid ); return 1; } | |
527 cutItem( in,tmp,',',5 ); cutItem( tmp,tmp,'"',1 ); | |
528 | |
529 #ifdef DEBUG | |
530 dbprintf( 3,"[skin] pos: %d,%d width: %d align: %d\n",x,y,sx,a ); | |
531 dbprintf( 3,"[skin] id: %s ( %d )\n",sid,id ); | |
532 dbprintf( 3,"[skin] str: '%s'\n",tmp ); | |
533 #endif | |
534 | |
535 defList->NumberOfItems++; | |
536 item=&defList->Items[ defList->NumberOfItems ]; | |
537 item->type=itDLabel; | |
538 item->fontid=id; item->align=a; | |
539 item->x=x; item->y=y; | |
540 item->width=sx; item->height=-1; | |
541 if ( ( item->label=malloc( strlen( tmp ) + 1 ) ) == NULL ) { ERRORMESSAGE( "not enought memory.\n" ); return 1; } | |
542 strcpy( item->label,tmp ); | |
543 | |
544 return 0; | |
545 } | |
546 | |
1866
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
547 int __decoration( char * in ) |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
548 { |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
549 char tmp[512]; |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
550 |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
551 CHECKDEFLIST( "decoration" ); |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
552 CHECKWINLIST( "decoration" ); |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
553 |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
554 #ifdef DEBUG |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
555 dbprintf( 0,"\n[skin] window decoration is %s\n",in ); |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
556 #endif |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
557 cutItem( in,tmp,',',0 ); |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
558 if ( strcmp( tmp,"enable" )&&strcmp( tmp,"disable" ) ) { ERRORMESSAGE( "unknown parameter.\n" ); return 1; } |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
559 if ( strcmp( tmp,"enable" ) ) defList->mainDecoration=0; |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
560 else defList->mainDecoration=1; |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
561 |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
562 #ifdef DEBUG |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
563 dbprintf( 3,"\n[skin] window decoration is %s\n",(defList->mainDecoration?"enabled":"disabled") ); |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
564 #endif |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
565 return 0; |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
566 } |
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
567 |
1693 | 568 typedef struct |
569 { | |
570 char * name; | |
571 int (*func)( char * in ); | |
572 } _item; | |
573 | |
574 _item skinItem[] = | |
575 { | |
576 { "section", __section }, | |
577 { "end", __end }, | |
578 { "window", __window }, | |
579 { "base", __base }, | |
580 { "button", __button }, | |
581 { "selected", __selected }, | |
582 { "background", __background }, | |
583 { "hpotmeter", __hpotmeter }, | |
584 { "potmeter", __potmeter }, | |
585 { "font", __font }, | |
586 { "slabel", __slabel }, | |
587 { "dlabel", __dlabel }, | |
1866
32b1bb50a0e8
some bug fix, and add decoration item to skin conffile. faszom(C)
pontscho
parents:
1852
diff
changeset
|
588 { "decoration", __decoration }, |
1693 | 589 { "menu", __menu } |
590 }; | |
591 | |
592 #define ITEMS ( sizeof( skinItem )/sizeof( _item ) ) | |
593 | |
594 char * strdelspacesbeforecommand( char * in ) | |
595 { | |
596 int c = 0; | |
597 char * out; | |
598 if ( strlen( in ) == 0 ) return NULL; | |
599 while ( in[c] == ' ' ) c++; | |
600 if ( c != 0 ) | |
601 { | |
602 out=malloc( strlen( in ) - c + 1 ); | |
603 memcpy( out,&in[c],strlen( in ) - c + 1 ); | |
604 } | |
605 else out=in; | |
606 return out; | |
607 } | |
608 | |
609 char * strswap( char * in,char what,char whereof ) | |
610 { | |
611 int i; | |
612 if ( strlen( in ) == 0 ) return NULL; | |
613 for ( i=0;i<strlen( in );i++ ) | |
614 if ( in[i] == what ) in[i]=whereof; | |
615 return in; | |
616 } | |
617 | |
618 char * strdelspaces( char * in ) | |
619 { | |
620 int c = 0,i = 0,id = 0; | |
621 if ( strlen( in ) == 0 ) return NULL; | |
622 while ( c != strlen( in ) ) | |
623 { | |
624 if ( in[c] == '"' ) id=!id; | |
625 if ( ( in[c] == ' ' )&&( !id ) ) | |
626 { | |
627 for ( i=0;i<strlen( in ) - c; i++ ) in[c+i]=in[c+i+1]; | |
628 continue; | |
629 } | |
630 c++; | |
631 } | |
632 return in; | |
633 } | |
634 | |
635 FILE * skinFile; | |
636 | |
637 void setname( char * item1, char * item2 ) | |
638 { strcpy( fn,item1 ); strcat( fn,"/" ); strcat( fn,item2 ); strcpy( path,fn ); strcat( path,"/" ); strcat( fn,"/skin" ); } | |
639 | |
640 int skinRead( char * dname ) | |
641 { | |
642 unsigned char tmp[255]; | |
643 unsigned char * ptmp; | |
644 unsigned char command[32]; | |
645 unsigned char param[256]; | |
646 int c,i; | |
647 | |
648 setname( skinMPlayerDir,dname ); | |
649 if ( ( skinFile = fopen( fn,"rt" ) ) == NULL ) | |
650 { | |
651 setname( skinDirInHome,dname ); | |
652 if ( ( skinFile = fopen( fn,"rt" ) ) == NULL ) | |
653 { | |
654 dbprintf( 3,"[skin] file ( %s ) not found.\n",fn ); | |
655 return -1; | |
656 } | |
657 } | |
658 | |
659 #ifdef DEBUG | |
660 dbprintf( 3,"[skin] file: %s\n",fn ); | |
661 #endif | |
662 | |
663 appInitStruct( &appMPlayer ); | |
664 | |
665 linenumber=0; | |
666 while ( !feof( skinFile ) ) | |
667 { | |
668 fgets( tmp,255,skinFile ); linenumber++; | |
669 | |
670 c=tmp[ strlen( tmp ) - 1 ]; if ( c == '\n' || c == '\r' ) tmp[ strlen( tmp ) - 1 ]=0; | |
671 c=tmp[ strlen( tmp ) - 1 ]; if ( c == '\n' || c == '\r' ) tmp[ strlen( tmp ) - 1 ]=0; | |
672 for ( c=0;c<strlen( tmp );c++ ) | |
673 if ( tmp[c] == ';' ) | |
674 { | |
675 tmp[c]=0; | |
676 break; | |
677 } | |
678 if ( strlen( tmp ) == 0 ) continue; | |
679 ptmp=strdelspacesbeforecommand( tmp ); | |
680 if ( strlen( ptmp ) == 0 ) continue; | |
681 ptmp=strswap( ptmp,'\t',' ' ); | |
682 ptmp=strdelspaces( ptmp ); | |
683 | |
684 cutItem( ptmp,command,'=',0 ); cutItem( ptmp,param,'=',1 ); | |
685 strlower( command ); | |
686 for( i=0;i<ITEMS;i++ ) | |
687 if ( !strcmp( command,skinItem[i].name ) ) | |
688 if ( skinItem[i].func( param ) ) return -2; | |
689 } | |
690 return 0; | |
691 } | |
692 | |
693 void btnModify( int event,float state ) | |
694 { | |
695 int j; | |
696 for ( j=0;j<appMPlayer.NumberOfItems + 1;j++ ) | |
697 if ( appMPlayer.Items[j].msg == event ) | |
698 { | |
1729 | 699 if ( appMPlayer.Items[j].used ) continue; |
1693 | 700 switch ( appMPlayer.Items[j].type ) |
701 { | |
702 case itButton: | |
703 appMPlayer.Items[j].pressed=(int)state; | |
704 break; | |
705 case itPotmeter: | |
706 case itHPotmeter: | |
707 if ( state < 0.0f ) state=0.0f; | |
708 if ( state > 100.f ) state=100.0f; | |
709 appMPlayer.Items[j].value=state; | |
710 break; | |
711 } | |
712 } | |
713 } | |
714 | |
1729 | 715 float btnGetValue( int event ) |
1693 | 716 { |
717 int j; | |
718 for ( j=0;j<appMPlayer.NumberOfItems + 1;j++ ) | |
719 if ( appMPlayer.Items[j].msg == event ) return appMPlayer.Items[j].value; | |
720 return 0; | |
721 } |