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