[Mplayer-cvslog] CVS: main/Gui/skin cut.c,NONE,1.1 cut.h,NONE,1.1 font.c,NONE,1.1 font.h,NONE,1.1 skin.c,NONE,1.1 skin.h,NONE,1.1

Arpi of Ize arpi at mplayer.dev.hu
Sat Aug 25 23:04:32 CEST 2001


Update of /cvsroot/mplayer/main/Gui/skin
In directory mplayer:/var/tmp.root/cvs-serv13203/skin

Added Files:
	cut.c cut.h font.c font.h skin.c skin.h 
Log Message:
GUI version n-1

--- NEW FILE ---

#include <string.h>
#include <stdlib.h>

void cutItem( char * in,char * out,char sep,int num )
{
 int i,n,c;
 for ( c=0,n=0,i=0;i<strlen( in );i++ )
  {
   if ( in[i] == sep ) n++;
   if ( n >= num && in[i] != sep ) out[c++]=in[i];
   if ( n >= num && in[i+1] == sep ) { out[c]=0; return; }
  }
 out[c]=0;
}

void cutChunk( char * in,char * s1 )
{
 cutItem( in,s1,'=',0 );
 memmove( in,strchr( in,'=' )+1,strlen( in ) - strlen( s1 ) );
}

--- NEW FILE ---

#ifndef _MYCUTS
#define _MYCUTS

extern void cutItem( char * in,char * out,char sep,int num );

extern void cutChunk( char * in,char * s1 );

#endif
--- NEW FILE ---

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>

#include "skin.h"
#include "font.h"
#include "cut.h"
#include "../error.h"

int items;

bmpFont * Fonts[25] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };

int fntAddNewFont( char * name )
{
 int id;
 for( id=0;id<25;id++ ) if ( !Fonts[id] ) break;
 if ( ( Fonts[id]=malloc( sizeof( bmpFont ) ) ) == NULL ) return -1;
 strcpy( Fonts[id]->name,name );
 memset( Fonts[id]->Fnt,-1,256 * sizeof( fntChar ) );
 return id;
}

void fntFreeFont( int id )
{
}

int fntRead( char * path,char * fname,int id )
{
 FILE * f;
 unsigned char   tmp[512];
 unsigned char * ptmp;
 unsigned char   command[32];
 unsigned char   param[256];
 int             c,i;
 int             linenumber = 0;

 strcpy( tmp,path ); strcat( tmp,fname ); strcat( tmp,".fnt" );
 if ( ( f=fopen( tmp,"rt" ) ) == NULL ) return -1;
 while ( !feof( f ) )
  {
   fgets( tmp,255,f ); linenumber++;

   c=tmp[ strlen( tmp ) - 1 ]; if ( ( c == '\n' )||( c == '\r' ) ) tmp[ strlen( tmp ) - 1 ]=0;
   c=tmp[ strlen( tmp ) - 1 ]; if ( ( c == '\n' )||( c == '\r' ) ) tmp[ strlen( tmp ) - 1 ]=0;
   for ( c=0;c < strlen( tmp );c++ )
    if ( tmp[c] == ';' )
     {
      tmp[c]=0;
      break;
     }
   if ( strlen( tmp ) == 0 ) continue;
   ptmp=strdelspacesbeforecommand( tmp );
   if ( strlen( ptmp ) == 0 ) continue;
   ptmp=strswap( ptmp,'\t',' ' );
   ptmp=strdelspaces( ptmp );
   cutItem( ptmp,command,'=',0 ); cutItem( ptmp,param,'=',1 );
   if ( command[0] == '"' )
    {
     int i;
     cutItem( command,command,'"',1 );
     i=(int)command[0];
     cutItem( param,tmp,',',0 ); Fonts[id]->Fnt[i].x=atoi( tmp );
     cutItem( param,tmp,',',1 ); Fonts[id]->Fnt[i].y=atoi( tmp );
     cutItem( param,tmp,',',2 ); Fonts[id]->Fnt[i].sx=atoi( tmp );
     cutItem( param,tmp,',',3 ); Fonts[id]->Fnt[i].sy=atoi( tmp );
     #ifdef DEBUG
      dbprintf( 0,"[font]  char: '%s' params: %d,%d %dx%d\n",command,Fonts[id]->Fnt[i].x,Fonts[id]->Fnt[i].y,Fonts[id]->Fnt[i].sx,Fonts[id]->Fnt[i].sy );
     #endif
    }
    else
     {
      if ( !strcmp( command,"image" ) )
       {
        strcpy( tmp,path ); strcat( tmp,param );
        #ifdef DEBUG
         dbprintf( 0,"[font] font imagefile: %s\n",tmp );
        #endif
        if ( skinBPRead( tmp,&Fonts[id]->Bitmap ) ) return -2;
       }
     }
  }
 return 0;
}

int fntFindID( char * name )
{
 int i;
 for ( i=0;i < 25;i++ )
  if ( Fonts[i] )
   if ( !strcmp( name,Fonts[i]->name ) ) return i;
 return -1;
}

int fntTextWidth( int id,char * str )
{
 int size = 0;
 int i;
 if ( !Fonts[id] ) return 0;
 for ( i=0;i < strlen( str );i++ )
   if ( Fonts[id]->Fnt[ (int)str[i] ].sx != -1 ) size+=Fonts[id]->Fnt[ (int)str[i] ].sx;
 return size;
}

int fntTextHeight( int id,char * str )
{
 int max = 0,i;
 if ( !Fonts[id] ) return 0;
 for ( i=0;i < strlen( str );i++ )
   if ( Fonts[id]->Fnt[ (int)str[i] ].sy > max ) max=Fonts[id]->Fnt[ (int)str[i] ].sy;
 return max;
}

txSample * fntRender( int id,int px,int sx,char * fmt,... )
{
 txSample      * tmp = NULL;
 char            p[512];
 va_list         ap;
 unsigned long * ibuf;
 unsigned long * obuf;
 int             i,x,y;
 int             oy = 0, ox = 0, dx = 0;

 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=(unsigned long *)tmp->Image;
 ibuf=(unsigned long *)Fonts[id]->Bitmap.Image;
 for ( i=0;i < strlen( p );i++ )
  {
   int c = (int)p[i];
   if ( Fonts[id]->Fnt[c].x == -1 ) c=32;
   for ( oy=0,y=Fonts[id]->Fnt[c].y;y < Fonts[id]->Fnt[c].y + Fonts[id]->Fnt[c].sy; y++,oy++ )
    for ( ox=0,x=Fonts[id]->Fnt[c].x;x < Fonts[id]->Fnt[c].x + 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 ) )
  {
   txSample tmp2;
   tmp2.ImageSize=sx * tmp->Height * 4;
   if ( ( tmp2.Image=malloc( tmp2.ImageSize ) ) ==  NULL ) { free( tmp->Image ); return NULL; }

   obuf=(unsigned long *)tmp->Image;
   ibuf=(unsigned long *)tmp2.Image;

   for ( y=0;y < tmp->Height;y++ )
    {
     ox=px;
     oy=y * sx; 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;
  }

 return tmp;
}

--- NEW FILE ---

#ifndef _MYFONT
#define _MYFONT

#include "../bitmap/bitmap.h"

typedef struct
{
 int x,y;   // location
 int sx,sy; // size
} fntChar;

typedef struct
{
 fntChar    Fnt[256];
 txSample   Bitmap;
 char       name[128];
} bmpFont;

extern fntChar    Fnt[256];
extern txSample   Bitmap;
extern bmpFont  * Fonts[25];

extern int  fntAddNewFont( char * name );
extern void fntFreeFont( int id );
extern int  fntFindID( char * name );

extern int        fntRead( char * path,char * fname,int id );
extern txSample * fntRender( int id,int px,int sx,char * fmt,... );

#endif
--- NEW FILE ---

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cut.h"
#include "error.h"
#include "font.h"
#include "../app.h"
#include "../language.h"
#include "../../config.h"

char            SkinDir[] = "/.mplayer/Skin/";
char          * Skin;

listItems     * skinAppMPlayer = &appMPlayer;
listItems     * skinAppTV      = &appTV;
listItems     * skinAppRadio   = &appRadio;

int             linenumber;

unsigned char   path[512],fn[512];

listItems     * defList = NULL;
unsigned char   winList[32] = "";

#include <stdarg.h>

void ERRORMESSAGE( const char * format, ... )
{
 char      p[512];
 va_list   ap;
 va_start( ap,format );
 vsnprintf( p,512,format,ap );
 va_end( ap );
 message( False,"[skin] error in skin config file on line %d: %s",linenumber,p );
}

#define CHECKDEFLIST( str ) { \
                              if ( defList == NULL ) \
                               { \
                                message( False,"[skin] warning in skin config file on line %d: widget found but before \"section\" not found ("str")",linenumber ); \
                                return 1; \
                               } \
                            }
#define CHECKWINLIST( str ) { \
                              if ( !strlen( winList ) ) \
                               { \
                                message( False,"[skin] warning in skin config file on line %d: widget found but before \"subsection\" not found ("str")",linenumber ); \
                                return 1; \
                               } \
                            }

char * strlower( char * in )
{
 int i;
 for( i=0;i<strlen( in );i++ ) in[i]=( in[i] >= 'A' ? ( in[i] <= 'Z' ?  in[i]+='A' : in[i] ) : in[i] );
 return in;
}

int skinBPRead( char * fname, txSample * bf )
{
 int i=bpRead( fname,bf );
 switch ( i )
  {
   case -1: ERRORMESSAGE( "16 bits or less depth bitmap not supported ( %s ).\n",fname ); break;
   case -2: ERRORMESSAGE( "file not found ( %s )\n",fname ); break;
   case -3: ERRORMESSAGE( "bmp read error ( %s )\n",fname ); break;
   case -4: ERRORMESSAGE( "tga read error ( %s )\n",fname ); break;
   case -5: ERRORMESSAGE( "png read error ( %s )\n",fname ); break;
   case -6: ERRORMESSAGE( "RLE packed tga not supported ( %s )\n",fname ); break;
   case -7: ERRORMESSAGE( "unknown file type ( %s )\n",fname ); break;
   case -8: ERRORMESSAGE( "24 bit to 32 bit convert error ( %s )\n",fname ); break;
  }
 return i;
}

int __section( char * in )
{
 strlower( in );
 defList=NULL;
 if ( !strcmp( in,"movieplayer" ) ) defList=skinAppMPlayer;
 #ifdef DEBUG
  dbprintf( 3,"\n[skin] sectionname: %s\n",in );
 #endif
 return 0;
}

int __end( char * in )
{
 if ( strlen( winList ) ) winList[0]=0;
  else defList=NULL;
 #ifdef DEBUG
  dbprintf( 3,"\n[skin] end section\n" );
 #endif
 return 0;
}

int __window( char * in )
{
 CHECKDEFLIST( "window" );

 strlower( in );
 strcpy( winList,in );
 #ifdef DEBUG
  dbprintf( 3,"\n[skin] window: %s\n",winList );
 #endif
 return 0;
}

int __base( char * in )
{
 unsigned char fname[512];
 unsigned char tmp[512];
 int           x,y;

 CHECKDEFLIST( "base" );
 CHECKWINLIST( "base" );

 cutItem( in,fname,',',0 );
 cutItem( in,tmp,',',1 ); x=atoi( tmp );
 cutItem( in,tmp,',',2 ); y=atoi( tmp );
 #ifdef DEBUG
  dbprintf( 3,"\n[skin] base: %s x: %d y: %d\n",fname,x,y );
 #endif
 if ( !strcmp( winList,"main" ) )
  {
   defList->main.x=x;
   defList->main.y=y;
   defList->main.type=itBase;
   strcpy( tmp,path ); strcat( tmp,fname );
   if ( skinBPRead( tmp,&defList->main.Bitmap ) ) return 1;
   defList->main.width=defList->main.Bitmap.Width;
   defList->main.height=defList->main.Bitmap.Height;
   #ifdef HAVE_XSHAPE
    defList->main.Mask.Width=defList->main.Bitmap.Width;
    defList->main.Mask.Height=defList->main.Bitmap.Height;
    defList->main.Mask.BPP=1;
    defList->main.Mask.ImageSize=defList->main.Mask.Width * defList->main.Mask.Height / 8;
    defList->main.Mask.Image=(char *)calloc( 1,defList->main.Mask.ImageSize );
    if ( defList->main.Mask.Image == NULL ) message( True,langNEMFMM );
    {
     int i,b,c=0; unsigned long * buf = NULL; unsigned char tmp = 0;
     buf=(unsigned long *)defList->main.Bitmap.Image;
     for ( b=0,i=0;i < defList->main.Mask.Width * defList->main.Mask.Height;i++ )
      {
       if ( buf[i] != 0x00ff00ff ) tmp=( tmp >> 1 )|128;
        else { tmp=tmp >> 1; buf[i]=0; }
       if ( b++ == 7 ) { defList->main.Mask.Image[c++]=tmp; tmp=0; b=0; }
      }
     defList->main.Mask.Image[c++]=tmp;
    }
    #ifdef DEBUG
     dbprintf( 3,"[skin]  mask: %dX%d\n",defList->main.Mask.Width,defList->main.Mask.Height );
    #endif
   #else
    defList->main.Mask.Image=NULL;
   #endif
   #ifdef DEBUG
    dbprintf( 3,"[skin]  width: %d height: %d\n",defList->main.width,defList->main.height );
   #endif
  }
 if ( !strcmp( winList,"sub" ) )
  {
   defList->sub.x=x;
   defList->sub.y=y;
   defList->sub.type=itBase;
   strcpy( tmp,path ); strcat( tmp,fname );
   if ( skinBPRead( tmp,&defList->sub.Bitmap ) ) return 1;
   defList->sub.width=defList->sub.Bitmap.Width;
   defList->sub.height=defList->sub.Bitmap.Height;
   #ifdef DEBUG
    dbprintf( 3,"[skin]  width: %d height: %d\n",defList->sub.width,defList->sub.height );
   #endif
  }
/*
 if ( !strcmp( winList,"eq" ) )
  {
   defList->eq.x=x;
   defList->eq.y=y;
   defList->eq.type=itBase;
   strcpy( tmp,path ); strcat( tmp,fname );
   if ( skinBPRead( tmp,&defList->eq.Bitmap ) ) return 1;
   defList->eq.width=defList->eq.Bitmap.Width;
   defList->eq.height=defList->eq.Bitmap.Height;
   #ifdef DEBUG
    dbprintf( 3,"[skin]  width: %d height: %d\n",defList->eq.width,defList->eq.height );
   #endif
  }
*/
 if ( !strcmp( winList,"menu" ) )
  {
   defList->menuBase.type=itBase;
   strcpy( tmp,path ); strcat( tmp,fname );
   if ( skinBPRead( tmp,&defList->menuBase.Bitmap ) ) return 1;
   defList->menuBase.width=defList->menuBase.Bitmap.Width;
   defList->menuBase.height=defList->menuBase.Bitmap.Height;
   #ifdef DEBUG
    dbprintf( 3,"[skin]  width: %d height: %d\n",defList->menuBase.width,defList->menuBase.height );
   #endif
  }
 return 0;
}

int __background( char * in )
{
 unsigned char tmp[512];

 CHECKDEFLIST( "background" );
 CHECKWINLIST( "background" );

 if ( !strcmp( winList,"sub" ) )
  {
   cutItem( in,tmp,',',0 ); defList->subR=atoi( tmp );
   cutItem( in,tmp,',',1 ); defList->subG=atoi( tmp );
   cutItem( in,tmp,',',2 ); defList->subB=atoi( tmp );
   #ifdef DEBUG
    dbprintf( 3,"\n[skin] subwindow background color is #%x%x%x.\n",defList->subR,defList->subG,defList->subB );
   #endif
  }
 return 0;
}

int __button( char * in )
{
 unsigned char   fname[512];
 unsigned char   tmp[512];
 int             x,y,sx,sy;
 unsigned char   msg[32];

 CHECKDEFLIST( "button" );
 CHECKWINLIST( "button" );

// button=prev,17,89,23,18,Up,evPrev

 cutItem( in,fname,',',0 );
 cutItem( in,tmp,',',1 ); x=atoi( tmp );
 cutItem( in,tmp,',',2 ); y=atoi( tmp );
 cutItem( in,tmp,',',3 ); sx=atoi( tmp );
 cutItem( in,tmp,',',4 ); sy=atoi( tmp );
 cutItem( in,msg,',',5 );

 defList->NumberOfItems++;
 defList->Items[ defList->NumberOfItems ].type=itButton;
 defList->Items[ defList->NumberOfItems ].x=x;
 defList->Items[ defList->NumberOfItems ].y=y;
 defList->Items[ defList->NumberOfItems ].width=sx;
 defList->Items[ defList->NumberOfItems ].height=sy;
 #ifdef DEBUG
  dbprintf( 3,"\n[skin] button: fname: %s\n",fname );
  dbprintf( 3,"[skin]  x: %d y: %d sx: %d sy: %d\n",x,y,sx,sy );
 #endif

 if ( ( defList->Items[ defList->NumberOfItems ].msg=appFindMessage( msg ) ) == -1 )
   { ERRORMESSAGE( "unknown message: %s\n",msg ); return 1; }
 defList->Items[ defList->NumberOfItems ].pressed=btnReleased;
 if ( defList->Items[ defList->NumberOfItems ].msg == evPauseSwitchToPlay ) defList->Items[ defList->NumberOfItems ].pressed=btnDisabled;
 defList->Items[ defList->NumberOfItems ].tmp=1;

 #ifdef DEBUG
  dbprintf( 3,"[skin]  message: %d\n",
   defList->Items[ defList->NumberOfItems ].msg );
 #endif

 defList->Items[ defList->NumberOfItems ].Bitmap.Image=NULL;
 if ( strcmp( fname,"NULL" ) )
  {
   strcpy( tmp,path ); strcat( tmp,fname );
   if ( skinBPRead( tmp,&defList->Items[ defList->NumberOfItems ].Bitmap ) ) return 1;
  }
 return 0;
}

int __selected( char * in )
{
 unsigned char   fname[512];
 unsigned char   tmp[512];

 CHECKDEFLIST( "selected" );
 CHECKWINLIST( "selected" );

 cutItem( in,fname,',',0 );
 defList->menuSelected.type=itBase;
 strcpy( tmp,path ); strcat( tmp,fname );
 #ifdef DEBUG
  dbprintf( 3,"\n[skin] selected: %s\n",fname );
 #endif
 if ( skinBPRead( tmp,&defList->menuSelected.Bitmap ) ) return 1;
 defList->menuSelected.width=defList->menuSelected.Bitmap.Width;
 defList->menuSelected.height=defList->menuSelected.Bitmap.Height;
 #ifdef DEBUG
  dbprintf( 3,"[skin]  width: %d height: %d\n",defList->menuSelected.width,defList->menuSelected.height );
 #endif
 return 0;
}

int __menu( char * in )
{ // menu = number,x,y,sx,sy,msg
 int             x,y,sx,sy,msg;
 unsigned char   tmp[64];

 CHECKDEFLIST( "menu" );
 CHECKWINLIST( "menu" );

 cutItem( in,tmp,',',0 ); x=atoi( tmp );
 cutItem( in,tmp,',',1 ); y=atoi( tmp );
 cutItem( in,tmp,',',2 ); sx=atoi( tmp );
 cutItem( in,tmp,',',3 ); sy=atoi( tmp );
 cutItem( in,tmp,',',4 ); msg=appFindMessage( tmp );

 defList->NumberOfMenuItems++;
 defList->MenuItems[ defList->NumberOfMenuItems ].x=x;
 defList->MenuItems[ defList->NumberOfMenuItems ].y=y;
 defList->MenuItems[ defList->NumberOfMenuItems ].width=sx;
 defList->MenuItems[ defList->NumberOfMenuItems ].height=sy;

 #ifdef DEBUG
  dbprintf( 3,"\n[skin] menuitem: %d\n",defList->NumberOfMenuItems );
  dbprintf( 3,"[skin]  x: %d y: %d sx: %d sy: %d\n",x,y,sx,sy );
 #endif

 if ( ( defList->MenuItems[ defList->NumberOfMenuItems ].msg=msg ) == -1 )
  ERRORMESSAGE( "unknown message: %s\n",tmp );

 #ifdef DEBUG
  dbprintf( 3,"[skin]  message: %d\n",defList->Items[ defList->NumberOfItems ].msg );
 #endif

 defList->MenuItems[ defList->NumberOfMenuItems ].Bitmap.Image=NULL;
 return 0;
}

int __hpotmeter( char * in )
{ // hpotmeter=buttonbitmaps,sx,sy,phasebitmaps,phases,default value,x,y,sx,sy,msg
 int             x,y,psx,psy,ph,sx,sy,msg,d;
 unsigned char   tmp[512];
 unsigned char   pfname[512];
 unsigned char   phfname[512];
 wItem         * item;

 CHECKDEFLIST( "hpotmeter" );
 CHECKWINLIST( "hpotmeter" );

 cutItem( in,pfname,',',0 );
 cutItem( in,tmp,',',1 ); psx=atoi( tmp );
 cutItem( in,tmp,',',2 ); psy=atoi( tmp );
 cutItem( in,phfname,',',3 );
 cutItem( in,tmp,',',4 ); ph=atoi( tmp );
 cutItem( in,tmp,',',5 ); d=atoi( tmp );
 cutItem( in,tmp,',',6 ); x=atoi( tmp );
 cutItem( in,tmp,',',7 ); y=atoi( tmp );
 cutItem( in,tmp,',',8 ); sx=atoi( tmp );
 cutItem( in,tmp,',',9 ); sy=atoi( tmp );
 cutItem( in,tmp,',',10 ); msg=appFindMessage( tmp );

 #ifdef DEBUG
  dbprintf( 3,"\n[skin] hpotmeter: pointer filename: '%s'\n",pfname );
  dbprintf( 3,  "[skin]  pointer size is %dx%d\n",psx,psy );
  dbprintf( 3,  "[skin]  phasebitmaps filename: '%s'\n",phfname );
  dbprintf( 3,  "[skin]   position: %d,%d %dx%d\n",x,y,sx,sy );
  dbprintf( 3,  "[skin]   default value: %d\n",d );
  dbprintf( 3,  "[skin]  message: %d\n",msg );
 #endif

 defList->NumberOfItems++;
 item=&defList->Items[ defList->NumberOfItems ];
 item->type=itHPotmeter;
 item->x=x; item->y=y; item->width=sx; item->height=sy;
 item->phases=ph;
 item->psx=psx; item->psy=psy;
 item->msg=msg;
 item->value=(float)d;
 item->pressed=btnReleased;

 item->Bitmap.Image=NULL;
 if ( strcmp( phfname,"NULL" ) )
  {
   strcpy( tmp,path ); strcat( tmp,phfname );
   if ( skinBPRead( tmp,&item->Bitmap ) ) return 1;
  }

 item->Mask.Image=NULL;
 if ( strcmp( pfname,"NULL" ) )
  {
   strcpy( tmp,path ); strcat( tmp,pfname );
   if ( skinBPRead( tmp,&item->Mask ) ) return 1;
  }

 return 0;
}

int __potmeter( char * in )
{ // potmeter=phasebitmaps,phases,default value,x,y,sx,sy,msg
 int             x,y,ph,sx,sy,msg,d;
 unsigned char   tmp[512];
 unsigned char   phfname[512];
 wItem         * item;

 CHECKDEFLIST( "potmeter" );
 CHECKWINLIST( "potmeter" );

 cutItem( in,phfname,',',0 );
 cutItem( in,tmp,',',1 ); ph=atoi( tmp );
 cutItem( in,tmp,',',2 ); d=atoi( tmp );
 cutItem( in,tmp,',',3 ); x=atoi( tmp );
 cutItem( in,tmp,',',4 ); y=atoi( tmp );
 cutItem( in,tmp,',',5 ); sx=atoi( tmp );
 cutItem( in,tmp,',',6 ); sy=atoi( tmp );
 cutItem( in,tmp,',',7 ); msg=appFindMessage( tmp );

 #ifdef DEBUG
  dbprintf( 3,"\n[skin] potmeter: phases filename: '%s'\n",phfname );
  dbprintf( 3,  "[skin]  position: %d,%d %dx%d\n",x,y,sx,sy );
  dbprintf( 3,  "[skin]  phases: %d\n",ph );
  dbprintf( 3,  "[skin]  default value: %d\n",d );
  dbprintf( 3,  "[skin]  message: %d\n",msg );
 #endif

 defList->NumberOfItems++;
 item=&defList->Items[ defList->NumberOfItems ];
 item->type=itPotmeter;
 item->x=x; item->y=y;
 item->width=sx; item->height=sy;
 item->phases=ph;
 item->msg=msg;
 item->value=(float)d;

 item->Bitmap.Image=NULL;
 if ( strcmp( phfname,"NULL" ) )
  {
   strcpy( tmp,path ); strcat( tmp,phfname );
   if ( skinBPRead( tmp,&item->Bitmap ) ) return 1;
  }
 return 0;
}

int __font( char * in )
{ // font=fontname,fontid
 char    name[512];
 char    id[512];
 wItem * item;

 CHECKDEFLIST( "font" );
 CHECKWINLIST( "font" );

 cutItem( in,name,',',0 );
 cutItem( in,id,',',1 );

 #ifdef DEBUG
  dbprintf( 3,"\n[skin] font\n" );
  dbprintf( 3,  "[skin]  name: %s\n",name );
 #endif

 defList->NumberOfItems++;
 item=&defList->Items[ defList->NumberOfItems ];
 item->type=itFont;
 item->fontid=fntAddNewFont( name );
 switch ( item->fontid )
  {
   case -1: ERRORMESSAGE( "not enought memory\n" ); return 1;
   case -2: ERRORMESSAGE( "too many fonts\n" ); return 1;
  }

 #ifdef DEBUG
  dbprintf( 3,  "[skin]  id: %s ( %d )\n",id,item->fontid );
 #endif

 switch ( fntRead( path,name,item->fontid ) )
  {
   case -1: ERRORMESSAGE( "font file not found\n" ); return 1;
   case -2: ERRORMESSAGE( "font image not found\n" ); return 1;
  }

 return 0;
}

int __slabel( char * in )
{
 char    tmp[512];
 char    sid[63];
 int     x,y,id;
 wItem * item;

 CHECKDEFLIST( "slabel" );
 CHECKWINLIST( "slabel" );

 #ifdef DEBUG
  dbprintf( 3,"\n[skin] slabel\n" );
 #endif

 cutItem( in,tmp,',',0 ); x=atoi( tmp );
 cutItem( in,tmp,',',1 ); y=atoi( tmp );
 cutItem( in,sid,',',2 ); id=fntFindID( sid );
 if ( id < 0 ) { ERRORMESSAGE( "nonexistent font id. ( %s )\n",sid ); return 1; }
 cutItem( in,tmp,',',3 ); cutItem( tmp,tmp,'"',1 );

 #ifdef DEBUG
  dbprintf( 3,  "[skin]  pos: %d,%d\n",x,y );
  dbprintf( 3,  "[skin]  id: %s ( %d )\n",sid,id );
  dbprintf( 3,  "[skin]  str: '%s'\n",tmp );
 #endif

 defList->NumberOfItems++;
 item=&defList->Items[ defList->NumberOfItems ];
 item->type=itSLabel;
 item->fontid=id;
 item->x=x; item->y=y;
 item->width=-1; item->height=-1;
 if ( ( item->label=malloc( strlen( tmp ) + 1 ) ) == NULL ) { ERRORMESSAGE( "not enought memory.\n" ); return 1; }
 strcpy( item->label,tmp );

 return 0;
}

int __dlabel( char * in )
{ // dlabel=x,y,sx,align,fontid,string ...
 char    tmp[512];
 char    sid[63];
 int     x,y,sx,id,a;
 wItem * item;

 CHECKDEFLIST( "dlabel" );
 CHECKWINLIST( "dlabel" );

 #ifdef DEBUG
  dbprintf( 3,"\n[skin] dlabel\n" );
 #endif

 cutItem( in,tmp,',',0 ); x=atoi( tmp );
 cutItem( in,tmp,',',1 ); y=atoi( tmp );
 cutItem( in,tmp,',',2 ); sx=atoi( tmp );
 cutItem( in,tmp,',',3 ); a=atoi( tmp );
 cutItem( in,sid,',',4 ); id=fntFindID( sid );
 if ( id < 0 ) { ERRORMESSAGE( "nonexistent font id. ( %s )\n",sid ); return 1; }
 cutItem( in,tmp,',',5 ); cutItem( tmp,tmp,'"',1 );

 #ifdef DEBUG
  dbprintf( 3,"[skin]  pos: %d,%d width: %d align: %d\n",x,y,sx,a );
  dbprintf( 3,"[skin]  id: %s ( %d )\n",sid,id );
  dbprintf( 3,"[skin]  str: '%s'\n",tmp );
 #endif

 defList->NumberOfItems++;
 item=&defList->Items[ defList->NumberOfItems ];
 item->type=itDLabel;
 item->fontid=id; item->align=a;
 item->x=x; item->y=y;
 item->width=sx; item->height=-1;
 if ( ( item->label=malloc( strlen( tmp ) + 1 ) ) == NULL ) { ERRORMESSAGE( "not enought memory.\n" ); return 1; }
 strcpy( item->label,tmp );

 return 0;
}

typedef struct
{
 char * name;
 int  (*func)( char * in );
} _item;

_item skinItem[] =
 {
  { "section",     __section     },
  { "end",         __end         },
  { "window",      __window      },
  { "base",        __base        },
  { "button",      __button      },
  { "selected",    __selected    },
  { "background",  __background  },
  { "hpotmeter",   __hpotmeter   },
  { "potmeter",    __potmeter    },
  { "font",        __font        },
  { "slabel",      __slabel      },
  { "dlabel",      __dlabel      },
  { "menu",        __menu        }
 };

#define ITEMS ( sizeof( skinItem )/sizeof( _item ) )

char * strdelspacesbeforecommand( char * in )
{
 int    c = 0;
 char * out;
 if ( strlen( in ) == 0 ) return NULL;
 while ( in[c] == ' ' ) c++;
 if ( c != 0 )
  {
   out=malloc( strlen( in ) - c  + 1 );
   memcpy( out,&in[c],strlen( in ) - c + 1 );
  }
  else out=in;
 return out;
}

char * strswap( char * in,char what,char whereof )
{
 int    i;
 if ( strlen( in ) == 0 ) return NULL;
 for ( i=0;i<strlen( in );i++ )
   if ( in[i] == what ) in[i]=whereof;
 return in;
}

char * strdelspaces( char * in )
{
 int    c = 0,i = 0,id = 0;
 if ( strlen( in ) == 0 ) return NULL;
 while ( c != strlen( in ) )
  {
   if ( in[c] == '"' ) id=!id;
   if ( ( in[c] == ' ' )&&( !id ) )
    {
     for ( i=0;i<strlen( in ) - c; i++ ) in[c+i]=in[c+i+1];
     continue;
    }
   c++;
  }
 return in;
}

FILE * skinFile;

void setname( char * item1, char * item2 )
{ strcpy( fn,item1 ); strcat( fn,"/" ); strcat( fn,item2 ); strcpy( path,fn ); strcat( path,"/" ); strcat( fn,"/skin" ); }

int skinRead( char * dname )
{
 unsigned char   tmp[255];
 unsigned char * ptmp;
 unsigned char   command[32];
 unsigned char   param[256];
 int             c,i;

 setname( skinMPlayerDir,dname );
 if ( ( skinFile = fopen( fn,"rt" ) ) == NULL )
  {
   setname( skinDirInHome,dname );
   if ( ( skinFile = fopen( fn,"rt" ) ) == NULL )
    {
     dbprintf( 3,"[skin] file ( %s ) not found.\n",fn );
     return -1;
    }
  }

 #ifdef DEBUG
  dbprintf( 3,"[skin] file: %s\n",fn );
 #endif

 appInitStruct( &appMPlayer );

 linenumber=0;
 while ( !feof( skinFile ) )
  {
   fgets( tmp,255,skinFile ); linenumber++;

   c=tmp[ strlen( tmp ) - 1 ]; if ( c == '\n' || c == '\r' ) tmp[ strlen( tmp ) - 1 ]=0;
   c=tmp[ strlen( tmp ) - 1 ]; if ( c == '\n' || c == '\r' ) tmp[ strlen( tmp ) - 1 ]=0;
   for ( c=0;c<strlen( tmp );c++ )
    if ( tmp[c] == ';' )
     {
      tmp[c]=0;
      break;
     }
   if ( strlen( tmp ) == 0 ) continue;
   ptmp=strdelspacesbeforecommand( tmp );
   if ( strlen( ptmp ) == 0 ) continue;
   ptmp=strswap( ptmp,'\t',' ' );
   ptmp=strdelspaces( ptmp );

   cutItem( ptmp,command,'=',0 ); cutItem( ptmp,param,'=',1 );
   strlower( command );
   for( i=0;i<ITEMS;i++ )
    if ( !strcmp( command,skinItem[i].name ) )
     if ( skinItem[i].func( param ) ) return -2;
  }
 return 0;
}

void btnModify( int event,float state )
{
 int j;
 for ( j=0;j<appMPlayer.NumberOfItems + 1;j++ )
  if ( appMPlayer.Items[j].msg == event )
   {
    switch ( appMPlayer.Items[j].type )
     {
      case itButton:
           appMPlayer.Items[j].pressed=(int)state;
           break;
      case itPotmeter:
      case itHPotmeter:
           if ( state < 0.0f ) state=0.0f;
           if ( state > 100.f ) state=100.0f;
           appMPlayer.Items[j].value=state;
           break;
     }
   }
}

int btnGetValue( int event )
{
 int j;
 for ( j=0;j<appMPlayer.NumberOfItems + 1;j++ )
  if ( appMPlayer.Items[j].msg == event ) return appMPlayer.Items[j].value;
 return 0;
}

--- NEW FILE ---

#ifndef __MY_SKIN
#define __MY_SKIN

#include "../app.h"

extern listItems     * skinAppMPlayer;
//extern listItems     * skinAppTV;
//extern listItems     * skinAppRadio;

extern int skinRead( char * dname  );
extern int skinBPRead( char * fname, txSample * bf );

extern void btnModify( int event,float state );
extern int btnGetValue( int event );

// ---

extern char * strdelspacesbeforecommand( char * in );
extern char * strswap( char * in,char what,char whereof );
extern char * strdelspaces( char * in );

#endif




More information about the MPlayer-cvslog mailing list