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.
29 #include "gui/skin/font.h"
30 #include "gui/skin/skin.h"
31 #include "gui/wm/ws.h"
35 #include "libvo/x11_common.h"
37 #include "stream/stream.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"
51 unsigned int GetTimerMS( void );
53 static inline void TranslateFilename( int c
,char * tmp
,size_t tmplen
)
58 switch ( guiIntfStruct
.StreamType
)
60 case STREAMTYPE_STREAM
:
61 av_strlcpy(tmp
, guiIntfStruct
.Filename
, tmplen
);
64 if ( ( guiIntfStruct
.Filename
)&&( guiIntfStruct
.Filename
[0] ) )
66 if ( (p
= strrchr(guiIntfStruct
.Filename
, '/')) )
67 av_strlcpy(tmp
, p
+ 1, tmplen
);
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
);
76 if ( guiIntfStruct
.DVD
.current_chapter
) snprintf(tmp
,tmplen
,MSGTR_Chapter
,guiIntfStruct
.DVD
.current_chapter
);
77 else av_strlcat( tmp
,MSGTR_NoChapter
,tmplen
);
82 snprintf( tmp
,tmplen
,MSGTR_VCDTrack
,guiIntfStruct
.Track
);
85 default: av_strlcpy( tmp
,MSGTR_NoMediaOpened
,tmplen
);
89 for ( i
=0;i
< (int)strlen( tmp
);i
++ )
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];
108 memset( trbuf
,0,512 );
110 strsize
= strlen(str
);
111 for ( c
=0,i
=0;i
< strsize
;i
++ )
113 if ( str
[i
] != '$' ) { trbuf
[c
++]=str
[i
]; trbuf
[c
]=0; }
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
;
129 snprintf( tmp
,sizeof( tmp
),"%02d:%02d:%02d",t
/3600,t
/60%60,t
%60 );
130 av_strlcat( trbuf
,tmp
,sizeof( trbuf
) );
132 case '7': t
=guiIntfStruct
.LengthInSec
; goto calclengthmmmmss
;
133 case '2': t
=guiIntfStruct
.TimeSec
;
135 snprintf( tmp
,sizeof( tmp
),"%04d:%02d",t
/60,t
%60 );
136 av_strlcat( trbuf
,tmp
,sizeof( trbuf
) );
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;
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;
174 switch ( guiIntfStruct
.StreamType
)
176 case STREAMTYPE_FILE
: av_strlcat( trbuf
,"f",sizeof( trbuf
) ); break;
178 case STREAMTYPE_VCD
: av_strlcat( trbuf
,"v",sizeof( trbuf
) ); break;
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;
184 default: av_strlcat( trbuf
," ",sizeof( trbuf
) ); break;
187 case '$': av_strlcat( trbuf
,"$",sizeof( trbuf
) ); break;
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
)
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
;
214 for ( iy
=y
;iy
< (int)(y
+bf
->Height
/ max
);iy
++ )
215 for ( ix
=x
;ix
< (int)(x
+bf
->Width
);ix
++ )
218 if ( tmp
!= 0x00ff00ff ) buf
[iy
* image_width
+ ix
]=tmp
;
222 for ( iy
=y
;iy
< (int)(y
+bf
->Height
/ max
);iy
++ )
224 for ( ix
=x
;ix
< (int)(x
+bf
->Width
);ix
++ )
227 if ( tmp
!= 0x00ff00ff ) buf
[yc
+ ix
]=tmp
;
234 void SimplePotmeterPutImage( txSample
* bf
,int x
,int y
,float frac
)
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
;
247 for ( iy
=y
;iy
< (int)(y
+bf
->Height
);iy
++ )
249 for ( ix
=x
;ix
< (int)(x
+w
);ix
++ )
252 if ( tmp
!= 0x00ff00ff ) buf
[iy
* image_width
+ ix
]=tmp
;
258 void Render( wsTWindow
* window
,wItem
* Items
,int nrItems
,char * db
,int size
)
261 txSample
* image
= NULL
;
265 image_width
=window
->Width
;
267 for( i
=0;i
< nrItems
+ 1;i
++ )
273 PutImage( &item
->Bitmap
,item
->x
,item
->y
,3,item
->pressed
);
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
) );
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
);
285 PutImage( &item
->Bitmap
,
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
) ),
294 image
=fntRender( item
,0,"%s",item
->label
);
295 if ( image
) PutImage( image
,item
->x
,item
->y
,1,0 );
298 char * t
= Translate( item
->label
);
299 int l
= fntTextWidth( item
->fontid
,t
);
301 image
=fntRender( item
,l
-(GetTimerMS() / 20)%l
,"%s",t
);
303 if ( image
) PutImage( image
,item
->x
,item
->y
,1,0 );
307 wsConvert( window
,db
,size
);