Mercurial > mplayer.hg
annotate Gui/mplayer/common.c @ 20719:da64f5e20483
Synced to 3.11.2006
author | jheryan |
---|---|
date | Mon, 06 Nov 2006 13:41:37 +0000 |
parents | 64d82a45a05d |
children | a7e5b99ac083 |
rev | line source |
---|---|
8973 | 1 |
2 // main window | |
3 | |
4 #include <stdlib.h> | |
5 #include <stdio.h> | |
6 #include <inttypes.h> | |
7 #include <sys/stat.h> | |
8 #include <unistd.h> | |
9 | |
17144 | 10 #include "app.h" |
11 #include "skin/font.h" | |
12 #include "skin/skin.h" | |
13 #include "wm/ws.h" | |
8973 | 14 |
17144 | 15 #include "../config.h" |
16 #include "../help_mp.h" | |
17 #include "../libvo/x11_common.h" | |
18 #include "../libvo/fastmemcpy.h" | |
8973 | 19 |
19271
64d82a45a05d
introduce new 'stream' directory for all stream layer related components and split them from libmpdemux
ben
parents:
18976
diff
changeset
|
20 #include "../stream/stream.h" |
17144 | 21 #include "../mixer.h" |
22 #include "../libvo/sub.h" | |
23 #include "../mplayer.h" | |
8973 | 24 |
17144 | 25 #include "../libmpdemux/demuxer.h" |
26 #include "../libmpdemux/stheader.h" | |
27 #include "../codec-cfg.h" | |
8973 | 28 |
29 | |
30 #include "play.h" | |
31 #include "widgets.h" | |
32 | |
12691
0230544f52a1
Fix GUI compilation, patch by Reimar Dffinger and Alexander Strasser.
diego
parents:
12685
diff
changeset
|
33 extern mixer_t mixer; // mixer from mplayer.c |
0230544f52a1
Fix GUI compilation, patch by Reimar Dffinger and Alexander Strasser.
diego
parents:
12685
diff
changeset
|
34 |
8973 | 35 extern unsigned int GetTimerMS( void ); |
36 | |
12646 | 37 inline void TranslateFilename( int c,char * tmp,size_t tmplen ) |
8973 | 38 { |
39 int i; | |
12646 | 40 char * p; |
41 | |
8973 | 42 switch ( guiIntfStruct.StreamType ) |
43 { | |
44 case STREAMTYPE_STREAM: | |
12646 | 45 strlcpy(tmp, guiIntfStruct.Filename, tmplen); |
8973 | 46 break; |
47 case STREAMTYPE_FILE: | |
48 if ( ( guiIntfStruct.Filename )&&( guiIntfStruct.Filename[0] ) ) | |
49 { | |
13181 | 50 if ( (p = strrchr(guiIntfStruct.Filename, '/')) ) |
12646 | 51 strlcpy(tmp, p + 1, tmplen); |
52 else | |
53 strlcpy(tmp, guiIntfStruct.Filename, tmplen); | |
8973 | 54 if ( tmp[strlen( tmp ) - 4] == '.' ) tmp[strlen( tmp ) - 4]=0; |
55 if ( tmp[strlen( tmp ) - 5] == '.' ) tmp[strlen( tmp ) - 5]=0; | |
12646 | 56 } else strlcpy( tmp,MSGTR_NoFileLoaded,tmplen ); |
8973 | 57 break; |
58 #ifdef USE_DVDREAD | |
59 case STREAMTYPE_DVD: | |
12646 | 60 if ( guiIntfStruct.DVD.current_chapter ) snprintf(tmp,tmplen,MSGTR_Chapter,guiIntfStruct.DVD.current_chapter ); |
61 else strlcat( tmp,MSGTR_NoChapter,tmplen ); | |
8973 | 62 break; |
63 #endif | |
64 #ifdef HAVE_VCD | |
65 case STREAMTYPE_VCD: | |
12646 | 66 snprintf( tmp,tmplen,MSGTR_VCDTrack,guiIntfStruct.Track ); |
8973 | 67 break; |
68 #endif | |
12646 | 69 default: strlcpy( tmp,MSGTR_NoMediaOpened,tmplen ); |
8973 | 70 } |
71 if ( c ) | |
72 { | |
73 for ( i=0;i < (int)strlen( tmp );i++ ) | |
74 { | |
75 int t=0; | |
76 if ( c == 1 ) { if ( ( tmp[i] >= 'A' )&&( tmp[i] <= 'Z' ) ) t=32; } | |
77 if ( c == 2 ) { if ( ( tmp[i] >= 'a' )&&( tmp[i] <= 'z' ) ) t=-32; } | |
78 tmp[i]=(char)( tmp[i] + t ); | |
79 } | |
80 } | |
81 } | |
82 | |
12646 | 83 /* Unsafe! Pass only null-terminated strings as (char *)str. */ |
8973 | 84 char * Translate( char * str ) |
85 { | |
86 static char trbuf[512]; | |
87 char tmp[512]; | |
88 int i,c; | |
89 int t; | |
12646 | 90 int strsize = 0; |
8973 | 91 memset( trbuf,0,512 ); |
92 memset( tmp,0,128 ); | |
12646 | 93 strsize = strlen(str); |
94 for ( c=0,i=0;i < strsize;i++ ) | |
8973 | 95 { |
96 if ( str[i] != '$' ) { trbuf[c++]=str[i]; trbuf[c]=0; } | |
97 else | |
98 { | |
99 switch ( str[++i] ) | |
100 { | |
12646 | 101 case 't': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.Track ); |
102 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
103 case 'o': TranslateFilename( 0,tmp,sizeof( tmp ) ); | |
104 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
105 case 'f': TranslateFilename( 1,tmp,sizeof( tmp ) ); | |
106 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
107 case 'F': TranslateFilename( 2,tmp,sizeof( tmp ) ); | |
108 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
8973 | 109 case '6': t=guiIntfStruct.LengthInSec; goto calclengthhhmmss; |
110 case '1': t=guiIntfStruct.TimeSec; | |
111 calclengthhhmmss: | |
12646 | 112 snprintf( tmp,sizeof( tmp ),"%02d:%02d:%02d",t/3600,t/60%60,t%60 ); |
113 strlcat( trbuf,tmp,sizeof( trbuf ) ); | |
8973 | 114 break; |
115 case '7': t=guiIntfStruct.LengthInSec; goto calclengthmmmmss; | |
116 case '2': t=guiIntfStruct.TimeSec; | |
117 calclengthmmmmss: | |
12646 | 118 snprintf( tmp,sizeof( tmp ),"%04d:%02d",t/60,t%60 ); |
119 strlcat( trbuf,tmp,sizeof( trbuf ) ); | |
8973 | 120 break; |
12646 | 121 case '3': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.TimeSec / 3600 ); |
122 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
123 case '4': snprintf( tmp,sizeof( tmp ),"%02d",( ( guiIntfStruct.TimeSec / 60 ) % 60 ) ); | |
124 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
125 case '5': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.TimeSec % 60 ); | |
126 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
127 case '8': snprintf( tmp,sizeof( tmp ),"%01d:%02d:%02d",guiIntfStruct.TimeSec / 3600,( guiIntfStruct.TimeSec / 60 ) % 60,guiIntfStruct.TimeSec % 60 ); strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
128 case 'v': snprintf( tmp,sizeof( tmp ),"%3.2f%%",guiIntfStruct.Volume ); | |
129 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
130 case 'V': snprintf( tmp,sizeof( tmp ),"%3.1f",guiIntfStruct.Volume ); | |
131 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
132 case 'b': snprintf( tmp,sizeof( tmp ),"%3.2f%%",guiIntfStruct.Balance ); | |
133 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
134 case 'B': snprintf( tmp,sizeof( tmp ),"%3.1f",guiIntfStruct.Balance ); | |
135 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
136 case 'd': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.FrameDrop ); | |
137 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
138 case 'x': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.MovieWidth ); | |
139 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
140 case 'y': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.MovieHeight ); | |
141 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
142 case 'C': snprintf( tmp,sizeof( tmp ),"%s", guiIntfStruct.sh_video? ((sh_video_t *)guiIntfStruct.sh_video)->codec->name : ""); | |
143 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
144 case 's': if ( guiIntfStruct.Playing == 0 ) strlcat( trbuf,"s",sizeof( trbuf ) ); break; | |
145 case 'l': if ( guiIntfStruct.Playing == 1 ) strlcat( trbuf,"p",sizeof( trbuf ) ); break; | |
146 case 'e': if ( guiIntfStruct.Playing == 2 ) strlcat( trbuf,"e",sizeof( trbuf ) ); break; | |
8973 | 147 case 'a': |
12691
0230544f52a1
Fix GUI compilation, patch by Reimar Dffinger and Alexander Strasser.
diego
parents:
12685
diff
changeset
|
148 if ( mixer.muted ) { strlcat( trbuf,"n",sizeof( trbuf ) ); break; } |
8973 | 149 switch ( guiIntfStruct.AudioType ) |
150 { | |
12646 | 151 case 0: strlcat( trbuf,"n",sizeof( trbuf ) ); break; |
152 case 1: strlcat( trbuf,"m",sizeof( trbuf ) ); break; | |
153 case 2: strlcat( trbuf,"t",sizeof( trbuf ) ); break; | |
8973 | 154 } |
155 break; | |
156 case 'T': | |
157 switch ( guiIntfStruct.StreamType ) | |
158 { | |
12646 | 159 case STREAMTYPE_FILE: strlcat( trbuf,"f",sizeof( trbuf ) ); break; |
8973 | 160 #ifdef HAVE_VCD |
12646 | 161 case STREAMTYPE_VCD: strlcat( trbuf,"v",sizeof( trbuf ) ); break; |
8973 | 162 #endif |
12646 | 163 case STREAMTYPE_STREAM: strlcat( trbuf,"u",sizeof( trbuf ) ); break; |
8973 | 164 #ifdef USE_DVDREAD |
12646 | 165 case STREAMTYPE_DVD: strlcat( trbuf,"d",sizeof( trbuf ) ); break; |
8973 | 166 #endif |
12646 | 167 default: strlcat( trbuf," ",sizeof( trbuf ) ); break; |
8973 | 168 } |
169 break; | |
12646 | 170 case '$': strlcat( trbuf,"$",sizeof( trbuf ) ); break; |
8973 | 171 default: continue; |
172 } | |
173 c=strlen( trbuf ); | |
174 } | |
175 } | |
176 return trbuf; | |
177 } | |
178 | |
179 static char * image_buffer = NULL; | |
180 static int image_width = 0; | |
181 | |
182 void PutImage( txSample * bf,int x,int y,int max,int ofs ) | |
183 { | |
184 int i=0,ix,iy; | |
185 uint32_t * buf = NULL; | |
186 uint32_t * drw = NULL; | |
187 register uint32_t tmp; | |
188 register uint32_t yc; | |
189 | |
190 if ( ( !bf )||( bf->Image == NULL ) ) return; | |
191 | |
192 i=( bf->Width * ( bf->Height / max ) ) * ofs; | |
193 buf=(uint32_t *)image_buffer; | |
194 drw=(uint32_t *)bf->Image; | |
195 | |
9191 | 196 #if 1 |
8973 | 197 for ( iy=y;iy < (int)(y+bf->Height / max);iy++ ) |
198 for ( ix=x;ix < (int)(x+bf->Width);ix++ ) | |
199 { | |
200 tmp=drw[i++]; | |
201 if ( tmp != 0x00ff00ff ) buf[iy * image_width + ix]=tmp; | |
202 } | |
203 #else | |
204 yc=y * image_width; | |
205 for ( iy=y;iy < (int)(y+bf->Height / max);iy++ ) | |
206 { | |
207 for ( ix=x;ix < (int)(x+bf->Width);ix++ ) | |
208 { | |
209 tmp=drw[i++]; | |
210 if ( tmp != 0x00ff00ff ) buf[yc + ix]=tmp; | |
211 } | |
212 yc+=image_width; | |
213 } | |
214 #endif | |
215 } | |
216 | |
12693
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
217 void SimplePotmeterPutImage( txSample * bf,int x,int y,float frac ) |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
218 { |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
219 int i=0,w,r,ix,iy; |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
220 uint32_t * buf = NULL; |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
221 uint32_t * drw = NULL; |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
222 register uint32_t tmp; |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
223 |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
224 if ( ( !bf )||( bf->Image == NULL ) ) return; |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
225 |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
226 buf=(uint32_t *)image_buffer; |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
227 drw=(uint32_t *)bf->Image; |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
228 w=bf->Width*frac; |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
229 r=bf->Width-w; |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
230 for ( iy=y;iy < (int)(y+bf->Height);iy++ ) |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
231 { |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
232 for ( ix=x;ix < (int)(x+w);ix++ ) |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
233 { |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
234 tmp=drw[i++]; |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
235 if ( tmp != 0x00ff00ff ) buf[iy * image_width + ix]=tmp; |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
236 } |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
237 i+=r; |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
238 } |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
239 } |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
240 |
8973 | 241 void Render( wsTWindow * window,wItem * Items,int nrItems,char * db,int size ) |
242 { | |
243 wItem * item; | |
244 txSample * image = NULL; | |
18976
6a08d0dabca8
Remove unused variables, patch by Stefan Huehner, stefan ##at## huehner org.
diego
parents:
17254
diff
changeset
|
245 int i; |
8973 | 246 |
247 image_buffer=db; | |
248 image_width=window->Width; | |
249 | |
250 for( i=0;i < nrItems + 1;i++ ) | |
251 { | |
252 item=&Items[i]; | |
253 switch( item->type ) | |
254 { | |
255 case itButton: | |
256 PutImage( &item->Bitmap,item->x,item->y,3,item->pressed ); | |
257 break; | |
258 case itPotmeter: | |
12693
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
259 if (item->phases == 1)SimplePotmeterPutImage( &item->Bitmap,item->x,item->y, item->value / 100.0f ); |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
260 else PutImage( &item->Bitmap,item->x,item->y,item->phases,( item->phases - 1 ) * ( item->value / 100.0f ) ); |
8973 | 261 break; |
262 case itHPotmeter: | |
12693
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
263 if (item->phases == 1)SimplePotmeterPutImage( &item->Bitmap,item->x,item->y, item->value / 100.0f ); |
eb996ecdfcd5
simple, smooth, ram-saving dynamic potmeter, which feature is required by the tvisor skin, patch by Andre Kuhne
alex
parents:
12691
diff
changeset
|
264 else PutImage( &item->Bitmap,item->x,item->y,item->phases,( item->phases - 1 ) * ( item->value / 100.0f ) ); |
8973 | 265 PutImage( &item->Mask,item->x + (int)( ( item->width - item->psx ) * item->value / 100.0f ),item->y,3,item->pressed ); |
266 break; | |
267 case itVPotmeter: | |
268 PutImage( &item->Bitmap, | |
269 item->x,item->y, | |
270 item->phases, | |
17254 | 271 item->phases * ( 1. - item->value / 100.0f ) ); |
8973 | 272 PutImage( &item->Mask, |
17254 | 273 item->x,item->y + (int)( ( item->height - item->psy ) * ( 1. - item->value / 100.0f ) ), |
8973 | 274 3,item->pressed ); |
275 break; | |
276 case itSLabel: | |
277 image=fntRender( item,0,"%s",item->label ); | |
278 if ( image ) PutImage( image,item->x,item->y,1,0 ); | |
279 case itDLabel: | |
280 { | |
281 char * t = Translate( item->label ); | |
282 int l = fntTextWidth( item->fontid,t ); | |
12685
b4587790a399
scroll strings from the left to right, patch by Andre Kuhne
alex
parents:
12646
diff
changeset
|
283 l=(l?l:item->width); |
b4587790a399
scroll strings from the left to right, patch by Andre Kuhne
alex
parents:
12646
diff
changeset
|
284 image=fntRender( item,l-(GetTimerMS() / 20)%l,"%s",t ); |
8973 | 285 } |
286 if ( image ) PutImage( image,item->x,item->y,1,0 ); | |
287 break; | |
288 } | |
289 } | |
290 wsConvert( window,db,size ); | |
291 } |