From 23d1cd9a0f0250c79920717e1cf6cc294c13e1ab Mon Sep 17 00:00:00 2001 From: pontscho Date: Sat, 11 Jan 2003 01:30:07 +0000 Subject: [PATCH] - new font render finished - fix 'l' button (evLoad changed to evLoadPlay) git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8884 b3059339-0415-0410-9bf9-f77b7e298cf2 --- Gui/interface.c | 3 +- Gui/mplayer/mw.c | 10 +-- Gui/skin/font.c | 225 +++++++++++++++-------------------------------- 3 files changed, 73 insertions(+), 165 deletions(-) diff --git a/Gui/interface.c b/Gui/interface.c index e8cb0f939c..bd4e6356f8 100644 --- a/Gui/interface.c +++ b/Gui/interface.c @@ -277,6 +277,7 @@ void guiInit( void ) void guiDone( void ) { + mplMainRender=0; mp_msg( MSGT_GPLAYER,MSGL_V,"[gui] done.\n" ); cfg_write(); wsXDone(); @@ -284,7 +285,7 @@ void guiDone( void ) int guiCMDArray[] = { - evLoad, + evLoadPlay, evLoadSubtitle, evAbout, evPlay, diff --git a/Gui/mplayer/mw.c b/Gui/mplayer/mw.c index e0b6b09588..56627a80fe 100644 --- a/Gui/mplayer/mw.c +++ b/Gui/mplayer/mw.c @@ -219,20 +219,14 @@ void mplMainDraw( void ) break; case itSLabel: image=fntRender( item,0,"%s",item->label ); - goto drawrenderedtext; + if ( image ) PutImage( image,item->x,item->y,1,0 ); case itDLabel: { char * t = Translate( item->label ); int l = fntTextWidth( item->fontid,t ); image=fntRender( item,(GetTimerMS() / 20)%(l?l:item->width),"%s",t ); } -drawrenderedtext: - if ( image ) - { - PutImage( image,item->x,item->y,1,0 ); - if ( image->Image ) free( image->Image ); - free( image ); - } + if ( image ) PutImage( image,item->x,item->y,1,0 ); break; } } diff --git a/Gui/skin/font.c b/Gui/skin/font.c index 7ce0feba96..ca369a10d1 100644 --- a/Gui/skin/font.c +++ b/Gui/skin/font.c @@ -145,193 +145,106 @@ int fntTextHeight( int id,char * str ) return max; } -typedef struct -{ - int pos; - char c; -} iChar; - txSample * fntRender( wItem * item,int px,char * fmt,... ) { -#if 0 - txSample * tmp = NULL; - va_list ap; - char p[512]; - iChar pos[512]; - int i, dx = 0, s, tw; - uint32_t * ibuf; - uint32_t * obuf; + txSample * tmp = NULL; + va_list ap; + unsigned char p[512]; + unsigned int c; + int i, dx = 0, s, tw, fbw, iw, id, ofs; + int x,y,fh,fw,fyc,yc; + uint32_t * ibuf; + uint32_t * obuf; va_start( ap,fmt ); vsnprintf( p,512,fmt,ap ); va_end( ap ); - if ( ( !item )|| - ( !Fonts[item->fontid] )|| - ( !p[0] )|| - ( !fntTextWidth( item->fontid,p ) ) ) return NULL; + iw=item->width; + id=item->fontid; - tw=fntTextWidth( item->fontid,p ); + if ( ( !item )|| + ( !Fonts[id] )|| + ( !p[0] )|| + ( !fntTextWidth( id,p ) ) ) return NULL; + + tw=fntTextWidth( id,p ); + fbw=Fonts[id]->Bitmap.Width; if ( item->Bitmap.Image == NULL ) { - item->Bitmap.Height=item->height=fntTextHeight( item->fontid,p ); - item->Bitmap.Width=item->width; - item->Bitmap.ImageSize=item->height * item->width * 4; + item->Bitmap.Height=item->height=fntTextHeight( id,p ); + item->Bitmap.Width=iw; + item->Bitmap.ImageSize=item->height * iw * 4; item->Bitmap.BPP=32; item->Bitmap.Image=malloc( item->Bitmap.ImageSize ); } obuf=(uint32_t *)item->Bitmap.Image; - ibuf=(uint32_t *)Fonts[item->fontid]->Bitmap.Image; + ibuf=(uint32_t *)Fonts[id]->Bitmap.Image; for ( i=0;i < item->Bitmap.ImageSize / 4;i++ ) obuf[i]=0xff00ff; - if ( tw < item->width ) + if ( tw <= iw ) { switch ( item->align ) { default: case fntAlignLeft: dx=0; break; - case fntAlignCenter: dx=( item->width - fntTextWidth( item->fontid,p ) ) / 2; break; - case fntAlignRight: dx=item->width - fntTextWidth( item->fontid,p ); break; + case fntAlignCenter: dx=( iw - fntTextWidth( id,p ) ) / 2; break; + case fntAlignRight: dx=iw - fntTextWidth( id,p ); break; } } else dx+=px; -/* + + ofs=dx; + for ( i=0;i < (int)strlen( p );i++ ) { - int c = (int)p[i]; - int fw = Fonts[item->fontid]->Fnt[c].sx; - int fh = Fonts[item->fontid]->Fnt[c].sy; - int fx = Fonts[item->fontid]->Fnt[c].x; - int fy = Fonts[item->fontid]->Fnt[c].y; - - if ( fw != -1 ) - { - // font rendernig - int x,y; - for ( y=0;y < fh;y++ ) - { - if ( dx >= 0 ) - for ( x=0; x < fw;x++ ) - { - if ( dx + x >= item->width ) goto fnt_exit; - obuf[y * item->width + x + dx]=ibuf[ ( fy + y ) * Fonts[item->fontid]->Bitmap.Width + fx + x ]; - } - } - dx+=fw; - } else dx+=4; - } - -fnt_exit: -*/ - -if ( !strncmp( p,"lofasz",6 ) ) -{ - int i,j, c = 0; - char t[512]; - memset( t,0,512 ); -// printf( "!!!! " ); - for ( i=0; i < (int)strlen( p );i++ ) - { - int c = (int)p[i]; - int fw = Fonts[item->fontid]->Fnt[c].sx; - pos[i].pos=dx; - pos[i].c=p[i]; - if ( pos[i].pos > item->width ) pos[i].pos-=item->width; -// printf( "%d; ",pos[i] ); + c=(unsigned int)p[i]; + fw=Fonts[id]->Fnt[c].sx; + + if ( fw == -1 ) { c=32; fw=Fonts[id]->Fnt[c].sx; } + + fh=Fonts[id]->Fnt[c].sy; + fyc=Fonts[id]->Fnt[c].y * fbw + Fonts[id]->Fnt[c].x; + yc=dx; + + if ( dx >= 0 ) + for ( y=0;y < fh;y++ ) + { + for ( x=0; x < fw;x++ ) + if ( dx + x >= 0 && dx + x < iw ) obuf[yc + x]=ibuf[ fyc + x ]; + fyc+=fbw; + yc+=iw; + } dx+=fw; } - for ( i=0;i < (int)strlen( p );i++ ) - for ( j=strlen( p );j > i;j-- ) - if ( pos[j].pos < pos[i].pos ) - { - iChar tmp; - memcpy( &tmp,&pos[i],sizeof( iChar ) ); - memcpy( &pos[i],&pos[j],sizeof( iChar ) ); - memcpy( &pos[j],&tmp,sizeof( iChar ) ); - } -// - for ( i=0;i < (int)strlen( p );i++ ) - t[c++]=pos[i].c; -// if ( pos[i].pos > 0 && pos[i].pos < item->width ) t[c++]=pos[i].c; - printf( "!!! %s\n",t ); -} + + if ( ofs > 0 && tw > item->width ) + { + dx=ofs; + for ( i=(int)strlen( p );i > 0;i-- ) + { + c=(unsigned int)p[i]; + fw=Fonts[id]->Fnt[c].sx; + + if ( fw == -1 ) { c=32; fw=Fonts[id]->Fnt[c].sx; } + + fh=Fonts[id]->Fnt[c].sy; + fyc=Fonts[id]->Fnt[c].y * fbw + Fonts[id]->Fnt[c].x; + + dx-=fw; yc=dx; + if ( dx >= 0 ) + for ( y=0;y < fh;y++ ) + { + for ( x=fw - 1;x >= 0;x-- ) + if ( dx + x >= 0 && dx + x < iw ) obuf[yc + x]=ibuf[fyc + x]; + fyc+=fbw; + yc+=iw; + } + } + } return &item->Bitmap; - -#else - txSample tmp2; - txSample * tmp = NULL; - va_list ap; - char p[512]; - uint32_t * ibuf; - uint32_t * obuf; - int i,x,y; - int oy = 0, ox = 0, dx = 0, s = 0; - int id=item->fontid; - int sx=item->width; - int a=item->align; - - va_start( ap,fmt ); - vsnprintf( p,512,fmt,ap ); - va_end( ap ); - - if ( ( !Fonts[id] )|| - ( !strlen( p ) )|| - ( !fntTextWidth( id,p ) )|| - ( (tmp=malloc( sizeof( txSample ) )) == NULL ) ) return NULL; - - tmp->Width=fntTextWidth( id,p ); - tmp->Height=fntTextHeight( id,p ); - tmp->BPP=32; - tmp->ImageSize=tmp->Width * tmp->Height * 4; - if ( ( tmp->Image=malloc( tmp->ImageSize ) ) == NULL ) return NULL; - - obuf=(uint32_t *)tmp->Image; - ibuf=(uint32_t *)Fonts[id]->Bitmap.Image; - - for ( i=0;i < (int)strlen( p );i++ ) - { - unsigned int c = (unsigned char)p[i]; - int cx,cy; - - if ( Fonts[id]->Fnt[c].sx == -1 ) c=32; - - cx=Fonts[id]->Fnt[c].x; - cy=Fonts[id]->Fnt[c].y; - - for ( oy=0,y=cy;y < cy + Fonts[id]->Fnt[c].sy; y++,oy++ ) - for ( ox=0,x=cx;x < cx + Fonts[id]->Fnt[c].sx; x++,ox++ ) - obuf[ oy * tmp->Width + dx + ox ]=ibuf[ y * Fonts[id]->Bitmap.Width + x ]; - - dx+=Fonts[id]->Fnt[c].sx; - } - - if ( ( sx > 0 )&&( sx < tmp->Width ) ) - { - tmp2.ImageSize=sx * tmp->Height * 4; - if ( ( tmp2.Image=malloc( tmp2.ImageSize ) ) == NULL ) { free( tmp->Image ); return NULL; } - - obuf=(uint32_t *)tmp->Image; - ibuf=(uint32_t *)tmp2.Image; - oy=0; - - for ( y=0;y < tmp->Height;y++ ) - { - ox=px; - dx=y * tmp->Width; - for ( x=0;x < sx;x++ ) - { - ibuf[oy++]=obuf[dx + ox++]; - if ( ox >= tmp->Width ) ox=0; - } - } - - free( tmp->Image ); tmp->Width=sx; tmp->ImageSize=tmp2.ImageSize; tmp->Image=tmp2.Image; - } -#endif - - return tmp; }