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