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