Remove trailing whitespace from most files
[mplayer/glamo.git] / gui / mplayer / gui_common.c
blob646b76929b11f5477824a6d8f51679fc3cd354e0
1 /*
2 * main window
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <inttypes.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include <string.h>
28 #include "gui/app.h"
29 #include "gui/skin/font.h"
30 #include "gui/skin/skin.h"
31 #include "gui/wm/ws.h"
33 #include "config.h"
34 #include "help_mp.h"
35 #include "libvo/x11_common.h"
37 #include "stream/stream.h"
38 #include "mixer.h"
39 #include "libvo/sub.h"
41 #include "libmpdemux/demuxer.h"
42 #include "libmpdemux/stheader.h"
43 #include "codec-cfg.h"
44 #include "access_mpcontext.h"
45 #include "libavutil/avstring.h"
48 #include "play.h"
49 #include "widgets.h"
51 unsigned int GetTimerMS( void );
53 static inline void TranslateFilename( int c,char * tmp,size_t tmplen )
55 int i;
56 char * p;
58 switch ( guiIntfStruct.StreamType )
60 case STREAMTYPE_STREAM:
61 av_strlcpy(tmp, guiIntfStruct.Filename, tmplen);
62 break;
63 case STREAMTYPE_FILE:
64 if ( ( guiIntfStruct.Filename )&&( guiIntfStruct.Filename[0] ) )
66 if ( (p = strrchr(guiIntfStruct.Filename, '/')) )
67 av_strlcpy(tmp, p + 1, tmplen);
68 else
69 av_strlcpy(tmp, guiIntfStruct.Filename, tmplen);
70 if ( tmp[strlen( tmp ) - 4] == '.' ) tmp[strlen( tmp ) - 4]=0;
71 if ( tmp[strlen( tmp ) - 5] == '.' ) tmp[strlen( tmp ) - 5]=0;
72 } else av_strlcpy( tmp,MSGTR_NoFileLoaded,tmplen );
73 break;
74 #ifdef CONFIG_DVDREAD
75 case STREAMTYPE_DVD:
76 if ( guiIntfStruct.DVD.current_chapter ) snprintf(tmp,tmplen,MSGTR_Chapter,guiIntfStruct.DVD.current_chapter );
77 else av_strlcat( tmp,MSGTR_NoChapter,tmplen );
78 break;
79 #endif
80 #ifdef CONFIG_VCD
81 case STREAMTYPE_VCD:
82 snprintf( tmp,tmplen,MSGTR_VCDTrack,guiIntfStruct.Track );
83 break;
84 #endif
85 default: av_strlcpy( tmp,MSGTR_NoMediaOpened,tmplen );
87 if ( c )
89 for ( i=0;i < (int)strlen( tmp );i++ )
91 int t=0;
92 if ( c == 1 ) { if ( ( tmp[i] >= 'A' )&&( tmp[i] <= 'Z' ) ) t=32; }
93 if ( c == 2 ) { if ( ( tmp[i] >= 'a' )&&( tmp[i] <= 'z' ) ) t=-32; }
94 tmp[i]=(char)( tmp[i] + t );
99 /* Unsafe! Pass only null-terminated strings as (char *)str. */
100 char * Translate( char * str )
102 mixer_t *mixer = mpctx_get_mixer(guiIntfStruct.mpcontext);
103 static char trbuf[512];
104 char tmp[512];
105 int i,c;
106 int t;
107 int strsize = 0;
108 memset( trbuf,0,512 );
109 memset( tmp,0,128 );
110 strsize = strlen(str);
111 for ( c=0,i=0;i < strsize;i++ )
113 if ( str[i] != '$' ) { trbuf[c++]=str[i]; trbuf[c]=0; }
114 else
116 switch ( str[++i] )
118 case 't': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.Track );
119 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
120 case 'o': TranslateFilename( 0,tmp,sizeof( tmp ) );
121 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
122 case 'f': TranslateFilename( 1,tmp,sizeof( tmp ) );
123 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
124 case 'F': TranslateFilename( 2,tmp,sizeof( tmp ) );
125 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
126 case '6': t=guiIntfStruct.LengthInSec; goto calclengthhhmmss;
127 case '1': t=guiIntfStruct.TimeSec;
128 calclengthhhmmss:
129 snprintf( tmp,sizeof( tmp ),"%02d:%02d:%02d",t/3600,t/60%60,t%60 );
130 av_strlcat( trbuf,tmp,sizeof( trbuf ) );
131 break;
132 case '7': t=guiIntfStruct.LengthInSec; goto calclengthmmmmss;
133 case '2': t=guiIntfStruct.TimeSec;
134 calclengthmmmmss:
135 snprintf( tmp,sizeof( tmp ),"%04d:%02d",t/60,t%60 );
136 av_strlcat( trbuf,tmp,sizeof( trbuf ) );
137 break;
138 case '3': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.TimeSec / 3600 );
139 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
140 case '4': snprintf( tmp,sizeof( tmp ),"%02d",( ( guiIntfStruct.TimeSec / 60 ) % 60 ) );
141 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
142 case '5': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.TimeSec % 60 );
143 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
144 case '8': snprintf( tmp,sizeof( tmp ),"%01d:%02d:%02d",guiIntfStruct.TimeSec / 3600,( guiIntfStruct.TimeSec / 60 ) % 60,guiIntfStruct.TimeSec % 60 ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
145 case 'v': snprintf( tmp,sizeof( tmp ),"%3.2f%%",guiIntfStruct.Volume );
146 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
147 case 'V': snprintf( tmp,sizeof( tmp ),"%3.1f",guiIntfStruct.Volume );
148 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
149 case 'b': snprintf( tmp,sizeof( tmp ),"%3.2f%%",guiIntfStruct.Balance );
150 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
151 case 'B': snprintf( tmp,sizeof( tmp ),"%3.1f",guiIntfStruct.Balance );
152 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
153 case 'd': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.FrameDrop );
154 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
155 case 'x': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.MovieWidth );
156 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
157 case 'y': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.MovieHeight );
158 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
159 case 'C': snprintf( tmp,sizeof( tmp ),"%s", guiIntfStruct.sh_video? ((sh_video_t *)guiIntfStruct.sh_video)->codec->name : "");
160 av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break;
161 case 's': if ( guiIntfStruct.Playing == 0 ) av_strlcat( trbuf,"s",sizeof( trbuf ) ); break;
162 case 'l': if ( guiIntfStruct.Playing == 1 ) av_strlcat( trbuf,"p",sizeof( trbuf ) ); break;
163 case 'e': if ( guiIntfStruct.Playing == 2 ) av_strlcat( trbuf,"e",sizeof( trbuf ) ); break;
164 case 'a':
165 if ( mixer->muted ) { av_strlcat( trbuf,"n",sizeof( trbuf ) ); break; }
166 switch ( guiIntfStruct.AudioType )
168 case 0: av_strlcat( trbuf,"n",sizeof( trbuf ) ); break;
169 case 1: av_strlcat( trbuf,"m",sizeof( trbuf ) ); break;
170 case 2: av_strlcat( trbuf,"t",sizeof( trbuf ) ); break;
172 break;
173 case 'T':
174 switch ( guiIntfStruct.StreamType )
176 case STREAMTYPE_FILE: av_strlcat( trbuf,"f",sizeof( trbuf ) ); break;
177 #ifdef CONFIG_VCD
178 case STREAMTYPE_VCD: av_strlcat( trbuf,"v",sizeof( trbuf ) ); break;
179 #endif
180 case STREAMTYPE_STREAM: av_strlcat( trbuf,"u",sizeof( trbuf ) ); break;
181 #ifdef CONFIG_DVDREAD
182 case STREAMTYPE_DVD: av_strlcat( trbuf,"d",sizeof( trbuf ) ); break;
183 #endif
184 default: av_strlcat( trbuf," ",sizeof( trbuf ) ); break;
186 break;
187 case '$': av_strlcat( trbuf,"$",sizeof( trbuf ) ); break;
188 default: continue;
190 c=strlen( trbuf );
193 return trbuf;
196 static char * image_buffer = NULL;
197 static int image_width = 0;
199 void PutImage( txSample * bf,int x,int y,int max,int ofs )
201 int i=0,ix,iy;
202 uint32_t * buf = NULL;
203 uint32_t * drw = NULL;
204 register uint32_t tmp;
205 /* register uint32_t yc; */
207 if ( ( !bf )||( bf->Image == NULL ) ) return;
209 i=( bf->Width * ( bf->Height / max ) ) * ofs;
210 buf=(uint32_t *)image_buffer;
211 drw=(uint32_t *)bf->Image;
213 #if 1
214 for ( iy=y;iy < (int)(y+bf->Height / max);iy++ )
215 for ( ix=x;ix < (int)(x+bf->Width);ix++ )
217 tmp=drw[i++];
218 if ( tmp != 0x00ff00ff ) buf[iy * image_width + ix]=tmp;
220 #else
221 yc=y * image_width;
222 for ( iy=y;iy < (int)(y+bf->Height / max);iy++ )
224 for ( ix=x;ix < (int)(x+bf->Width);ix++ )
226 tmp=drw[i++];
227 if ( tmp != 0x00ff00ff ) buf[yc + ix]=tmp;
229 yc+=image_width;
231 #endif
234 void SimplePotmeterPutImage( txSample * bf,int x,int y,float frac )
236 int i=0,w,r,ix,iy;
237 uint32_t * buf = NULL;
238 uint32_t * drw = NULL;
239 register uint32_t tmp;
241 if ( ( !bf )||( bf->Image == NULL ) ) return;
243 buf=(uint32_t *)image_buffer;
244 drw=(uint32_t *)bf->Image;
245 w=bf->Width*frac;
246 r=bf->Width-w;
247 for ( iy=y;iy < (int)(y+bf->Height);iy++ )
249 for ( ix=x;ix < (int)(x+w);ix++ )
251 tmp=drw[i++];
252 if ( tmp != 0x00ff00ff ) buf[iy * image_width + ix]=tmp;
254 i+=r;
258 void Render( wsTWindow * window,wItem * Items,int nrItems,char * db,int size )
260 wItem * item;
261 txSample * image = NULL;
262 int i;
264 image_buffer=db;
265 image_width=window->Width;
267 for( i=0;i < nrItems + 1;i++ )
269 item=&Items[i];
270 switch( item->type )
272 case itButton:
273 PutImage( &item->Bitmap,item->x,item->y,3,item->pressed );
274 break;
275 case itPotmeter:
276 if (item->phases == 1)SimplePotmeterPutImage( &item->Bitmap,item->x,item->y, item->value / 100.0f );
277 else PutImage( &item->Bitmap,item->x,item->y,item->phases,( item->phases - 1 ) * ( item->value / 100.0f ) );
278 break;
279 case itHPotmeter:
280 if (item->phases == 1)SimplePotmeterPutImage( &item->Bitmap,item->x,item->y, item->value / 100.0f );
281 else PutImage( &item->Bitmap,item->x,item->y,item->phases,( item->phases - 1 ) * ( item->value / 100.0f ) );
282 PutImage( &item->Mask,item->x + (int)( ( item->width - item->psx ) * item->value / 100.0f ),item->y,3,item->pressed );
283 break;
284 case itVPotmeter:
285 PutImage( &item->Bitmap,
286 item->x,item->y,
287 item->phases,
288 item->phases * ( 1. - item->value / 100.0f ) );
289 PutImage( &item->Mask,
290 item->x,item->y + (int)( ( item->height - item->psy ) * ( 1. - item->value / 100.0f ) ),
291 3,item->pressed );
292 break;
293 case itSLabel:
294 image=fntRender( item,0,"%s",item->label );
295 if ( image ) PutImage( image,item->x,item->y,1,0 );
296 case itDLabel:
298 char * t = Translate( item->label );
299 int l = fntTextWidth( item->fontid,t );
300 l=(l?l:item->width);
301 image=fntRender( item,l-(GetTimerMS() / 20)%l,"%s",t );
303 if ( image ) PutImage( image,item->x,item->y,1,0 );
304 break;
307 wsConvert( window,db,size );