Mercurial > mplayer.hg
annotate gui/skin/skin.c @ 29321:e98825540790
Overhaul translation handling completely and add options to install specific
documentation and man page translations.
author | diego |
---|---|
date | Sun, 14 Jun 2009 14:55:01 +0000 |
parents | 0f1b5b68af32 |
children | 5fbb30fa62cc |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
23077 | 18 |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 | |
23 #include "cut.h" | |
24 #include "font.h" | |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
23703
diff
changeset
|
25 #include "gui/app.h" |
23077 | 26 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
27 #include "config.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
28 #include "mp_msg.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
29 #include "help_mp.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
23703
diff
changeset
|
30 #include "gui/mplayer/widgets.h" |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23077
diff
changeset
|
31 #include "libavutil/avstring.h" |
23077 | 32 |
33 //#define MSGL_DBG2 MSGL_STATUS | |
34 | |
35 listItems * skinAppMPlayer = &appMPlayer; | |
36 | |
37 // --- | |
38 | |
39 static int linenumber; | |
40 | |
41 static unsigned char path[512],fn[512]; | |
42 | |
43 static listItems * defList = NULL; | |
44 static unsigned char window_name[32] = ""; | |
45 | |
46 static wItem * currSection = NULL; | |
47 static int * currSubItem = NULL; | |
48 static wItem * currSubItems = NULL; | |
49 | |
50 #include <stdarg.h> | |
51 | |
52 void ERRORMESSAGE( const char * format, ... ) | |
53 { | |
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 ); | |
63 } | |
64 | |
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 } \ | |
72 } | |
73 | |
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 } \ | |
81 } | |
82 | |
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 } \ | |
90 } | |
91 | |
92 static char * strlower( char * in ) | |
93 { | |
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; | |
97 } | |
98 | |
99 int skinBPRead( char * fname, txSample * bf ) | |
100 { | |
101 int i=bpRead( fname,bf ); | |
102 switch ( i ) | |
103 { | |
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; | |
112 } | |
113 return i; | |
114 } | |
115 | |
116 int cmd_section( char * in ) | |
117 { | |
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; | |
123 } | |
124 | |
125 int cmd_end( char * in ) | |
126 { | |
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; | |
131 } | |
132 | |
133 int cmd_window( char * in ) | |
134 { | |
135 CHECKDEFLIST( "window" ); | |
136 | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23077
diff
changeset
|
137 av_strlcpy( window_name,strlower( in ),sizeof( window_name ) ); |
23077 | 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; | |
145 } | |
146 | |
147 int cmd_base( char * in ) | |
148 { | |
149 unsigned char fname[512]; | |
150 unsigned char tmp[512]; | |
151 int x,y; | |
152 int sx=0,sy=0; | |
153 | |
154 CHECKDEFLIST( "base" ); | |
155 CHECKWINLIST( "base" ); | |
156 | |
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" ) ) | |
164 { | |
165 defList->main.x=x; | |
166 defList->main.y=y; | |
167 defList->main.type=itBase; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
168 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, fname, sizeof( tmp )); |
23077 | 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; | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
172 #ifdef CONFIG_XSHAPE |
23077 | 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 ); | |
179 } | |
180 if ( !strcmp( window_name,"sub" ) ) | |
181 { | |
182 defList->sub.type=itBase; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
183 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, fname, sizeof( tmp )); |
23077 | 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 ) | |
190 { | |
191 defList->sub.width=sx; | |
192 defList->sub.height=sy; | |
193 } | |
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 ); | |
195 } | |
196 if ( !strcmp( window_name,"menu" ) ) | |
197 { | |
198 defList->menuIsPresent=1; | |
199 defList->menuBase.type=itBase; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
200 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, fname, sizeof( tmp )); |
23077 | 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; | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
204 #ifdef CONFIG_XSHAPE |
23077 | 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 ); | |
211 } | |
212 if ( !strcmp( window_name,"playbar" ) ) | |
213 { | |
214 defList->barIsPresent=1; | |
215 defList->bar.x=x; | |
216 defList->bar.y=y; | |
217 defList->bar.type=itBase; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
218 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, fname, sizeof( tmp )); |
23077 | 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; | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
222 #ifdef CONFIG_XSHAPE |
23077 | 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 ); | |
229 } | |
230 return 0; | |
231 } | |
232 | |
233 int cmd_background( char * in ) | |
234 { | |
235 CHECKDEFLIST( "background" ); | |
236 CHECKWINLIST( "background" ); | |
237 | |
238 CHECK( "menu" ); | |
239 CHECK( "main" ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
240 |
23077 | 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 ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
245 |
23077 | 246 return 0; |
247 } | |
248 | |
249 int cmd_button( char * in ) | |
250 { | |
251 unsigned char fname[512]; | |
252 unsigned char tmp[512]; | |
253 int x,y,sx,sy; | |
254 char msg[32]; | |
255 | |
256 CHECKDEFLIST( "button" ); | |
257 CHECKWINLIST( "button" ); | |
258 | |
259 CHECK( "sub" ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
260 CHECK( "menu" ); |
23077 | 261 |
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 ); | |
268 | |
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 ); | |
277 | |
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; | |
283 | |
284 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] message: %d\n",currSubItems[ *currSubItem ].msg ); | |
285 | |
286 currSubItems[ *currSubItem ].Bitmap.Image=NULL; | |
287 if ( strcmp( fname,"NULL" ) ) | |
288 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
289 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, fname, sizeof( tmp )); |
23077 | 290 if ( skinBPRead( tmp,&currSubItems[ *currSubItem ].Bitmap ) ) return 1; |
291 } | |
292 | |
293 return 0; | |
294 } | |
295 | |
296 int cmd_selected( char * in ) | |
297 { | |
298 unsigned char fname[512]; | |
299 unsigned char tmp[512]; | |
300 | |
301 CHECKDEFLIST( "selected" ); | |
302 CHECKWINLIST( "selected" ); | |
303 | |
304 CHECK( "main" ); | |
305 CHECK( "sub" ); | |
306 CHECK( "playbar" ); | |
307 | |
308 cutItem( in,fname,',',0 ); | |
309 defList->menuSelected.type=itBase; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
310 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, fname, sizeof( tmp )); |
23077 | 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; | |
317 } | |
318 | |
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]; | |
323 | |
324 CHECKDEFLIST( "menu" ); | |
325 CHECKWINLIST( "menu" ); | |
326 | |
327 CHECK( "main" ); | |
328 CHECK( "sub" ); | |
329 CHECK( "playbar" ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
330 |
23077 | 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 ); | |
336 | |
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; | |
342 | |
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 ); | |
345 | |
346 if ( ( defList->MenuItems[ defList->NumberOfMenuItems ].msg=msg ) == -1 ) | |
347 ERRORMESSAGE( MSGTR_SKIN_BITMAP_UnknownMessage,tmp ); | |
348 | |
349 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] message: %d\n",defList->Items[ defList->NumberOfItems ].msg ); | |
350 | |
351 defList->MenuItems[ defList->NumberOfMenuItems ].Bitmap.Image=NULL; | |
352 return 0; | |
353 } | |
354 | |
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; | |
362 | |
363 CHECKDEFLIST( "hpotmeter" ); | |
364 CHECKWINLIST( "hpotmeter" ); | |
365 | |
366 CHECK( "sub" ); | |
367 CHECK( "menu" ); | |
368 | |
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 ); | |
380 | |
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 ); | |
387 | |
388 (*currSubItem)++; | |
389 item=&currSubItems[ *currSubItem ]; | |
390 | |
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; | |
398 | |
399 item->Bitmap.Image=NULL; | |
400 if ( strcmp( phfname,"NULL" ) ) | |
401 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
402 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, phfname, sizeof( tmp )); |
23077 | 403 if ( skinBPRead( tmp,&item->Bitmap ) ) return 1; |
404 } | |
405 | |
406 item->Mask.Image=NULL; | |
407 if ( strcmp( pfname,"NULL" ) ) | |
408 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
409 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, pfname, sizeof( tmp )); |
23077 | 410 if ( skinBPRead( tmp,&item->Mask ) ) return 1; |
411 } | |
412 return 0; | |
413 } | |
414 | |
415 int cmd_vpotmeter( char * in ) | |
416 { | |
417 int r = cmd_hpotmeter( in ); | |
418 wItem * item; | |
419 | |
420 item=&currSubItems[ *currSubItem ]; | |
421 item->type=itVPotmeter; | |
422 return r; | |
423 } | |
424 | |
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; | |
431 | |
432 CHECKDEFLIST( "potmeter" ); | |
433 CHECKWINLIST( "potmeter" ); | |
434 | |
435 CHECK( "sub" ); | |
436 CHECK( "menu" ); | |
437 | |
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 ); | |
446 | |
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 ); | |
452 | |
453 (*currSubItem)++; | |
454 item=&currSubItems[ *currSubItem ]; | |
455 | |
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; | |
462 | |
463 item->Bitmap.Image=NULL; | |
464 if ( strcmp( phfname,"NULL" ) ) | |
465 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
466 av_strlcpy(tmp, path, sizeof( tmp )); av_strlcat(tmp, phfname, sizeof( tmp )); |
23077 | 467 if ( skinBPRead( tmp,&item->Bitmap ) ) return 1; |
468 } | |
469 return 0; | |
470 } | |
471 | |
472 int cmd_font( char * in ) | |
473 { // font=fontname,fontid | |
474 char name[512]; | |
475 char id[512]; | |
476 wItem * item; | |
477 | |
478 CHECKDEFLIST( "font" ); | |
479 CHECKWINLIST( "font" ); | |
480 | |
481 CHECK( "sub" ); | |
482 CHECK( "menu" ); | |
483 | |
484 cutItem( in,name,',',0 ); | |
485 cutItem( in,id,',',1 ); | |
486 | |
487 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] font\n" ); | |
488 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] name: %s\n",name ); | |
489 | |
490 (*currSubItem)++; | |
491 item=&currSubItems[ *currSubItem ]; | |
492 | |
493 item->type=itFont; | |
494 item->fontid=fntRead( path,name ); | |
495 switch ( item->fontid ) | |
496 { | |
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; | |
501 } | |
502 return 0; | |
503 } | |
504 | |
505 int cmd_slabel( char * in ) | |
506 { | |
507 char tmp[512]; | |
508 char sid[63]; | |
509 int x,y,id; | |
510 wItem * item; | |
511 | |
512 CHECKDEFLIST( "slabel" ); | |
513 CHECKWINLIST( "slabel" ); | |
514 | |
515 CHECK( "sub" ); | |
516 CHECK( "menu" ); | |
517 | |
518 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] slabel\n" ); | |
519 | |
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 ); | |
525 | |
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 ); | |
529 | |
530 (*currSubItem)++; | |
531 item=&currSubItems[ *currSubItem ]; | |
532 | |
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 ); | |
539 | |
540 return 0; | |
541 } | |
542 | |
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; | |
549 | |
550 CHECKDEFLIST( "dlabel" ); | |
551 CHECKWINLIST( "dlabel" ); | |
552 | |
553 CHECK( "sub" ); | |
554 CHECK( "menu" ); | |
555 | |
556 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] dlabel\n" ); | |
557 | |
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 ); | |
565 | |
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 ); | |
569 | |
570 (*currSubItem)++; | |
571 item=&currSubItems[ *currSubItem ]; | |
572 | |
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 ); | |
579 | |
580 return 0; | |
581 } | |
582 | |
583 int cmd_decoration( char * in ) | |
584 { | |
585 char tmp[512]; | |
586 | |
587 CHECKDEFLIST( "decoration" ); | |
588 CHECKWINLIST( "decoration" ); | |
589 | |
590 CHECK( "sub" ); | |
591 CHECK( "menu" ); | |
592 CHECK( "playbar" ); | |
593 | |
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; | |
600 | |
601 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"\n[skin] window decoration is %s\n",(defList->mainDecoration?"enabled":"disabled") ); | |
602 return 0; | |
603 } | |
604 | |
605 typedef struct | |
606 { | |
607 const char * name; | |
608 int (*func)( char * in ); | |
609 } _item; | |
610 | |
611 _item skinItem[] = | |
612 { | |
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 } | |
628 }; | |
629 | |
630 #define ITEMS (int)( sizeof( skinItem )/sizeof( _item ) ) | |
631 | |
632 char * trimleft( char * in ) | |
633 { | |
634 int c = 0; | |
635 char * out; | |
636 if ( strlen( in ) == 0 ) return NULL; | |
637 while ( in[c] == ' ' ) c++; | |
638 if ( c != 0 ) | |
639 { | |
640 out=malloc( strlen( in ) - c + 1 ); | |
641 memcpy( out,&in[c],strlen( in ) - c + 1 ); | |
642 } | |
643 else out=in; | |
644 return out; | |
645 } | |
646 | |
647 char * strswap( char * in,char what,char whereof ) | |
648 { | |
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; | |
654 } | |
655 | |
656 char * trim( char * in ) | |
657 { | |
658 int c = 0,i = 0,id = 0; | |
659 if ( strlen( in ) == 0 ) return NULL; | |
660 while ( c != (int)strlen( in ) ) | |
661 { | |
662 if ( in[c] == '"' ) id=!id; | |
663 if ( ( in[c] == ' ' )&&( !id ) ) | |
664 { | |
665 for ( i=0;i<(int)strlen( in ) - c; i++ ) in[c+i]=in[c+i+1]; | |
666 continue; | |
667 } | |
668 c++; | |
669 } | |
670 return in; | |
671 } | |
672 | |
673 FILE * skinFile; | |
674 | |
675 void setname( char * item1, char * item2 ) | |
676 { | |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23077
diff
changeset
|
677 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
|
678 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
|
679 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
|
680 av_strlcat(fn, "/skin", sizeof( fn )); |
23077 | 681 } |
682 | |
683 int skinRead( char * dname ) | |
684 { | |
685 unsigned char tmp[255]; | |
686 unsigned char * ptmp; | |
687 unsigned char command[32]; | |
688 unsigned char param[256]; | |
689 int c,i; | |
690 | |
691 setname( skinDirInHome,dname ); | |
692 if ( ( skinFile = fopen( fn,"rt" ) ) == NULL ) | |
693 { | |
694 setname( skinMPlayerDir,dname ); | |
695 if ( ( skinFile = fopen( fn,"rt" ) ) == NULL ) | |
696 { | |
697 setname( skinDirInHome_obsolete,dname ); | |
698 if ( ( skinFile = fopen( fn,"rt" ) ) == NULL ) | |
699 { | |
700 setname( skinMPlayerDir_obsolete,dname ); | |
701 if ( ( skinFile = fopen( fn,"rt" ) ) == NULL ) | |
702 { | |
703 setname( skinMPlayerDir,dname ); | |
704 mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_SKIN_SkinFileNotFound,fn ); | |
705 return -1; | |
706 } | |
707 } | |
708 } | |
709 } | |
710 | |
711 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] file: %s\n",fn ); | |
712 | |
713 appInitStruct( skinAppMPlayer ); | |
714 | |
715 linenumber=0; | |
716 while (fgets(tmp, 255, skinFile)) | |
717 { | |
718 linenumber++; | |
719 | |
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] == ';' ) | |
724 { | |
725 tmp[c]=0; | |
726 break; | |
727 } | |
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 ); | |
733 | |
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; | |
739 } | |
740 if (linenumber == 0) { | |
741 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_SKIN_SkinFileNotReadable, fn); | |
742 return -1; | |
743 } | |
744 return 0; | |
745 } |