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