欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

display.c

是一个手机功能的模拟程序
C
第 1 页 / 共 5 页
字号:
            therefore text may be cut off.
            Linefeeds and carriage returns are not supported and there-
            fore must be handled by upper layers.


*/

#if R2D_SUBLCD_SUPPORT
/* Robert.Chen add, 2003-12-14 */
/* sub_main: 1 for main LCD, 0 for sub LCD */
static dspl_TextOut_Cmode_Center_i(USHORT in_Y, USHORT len_x, UBYTE in_Attrib,
                                             char * in_Text, UBYTE Newline, UBYTE sub_main)
{
    int in_X_signed;
    int in_Y_signed;
    unsigned char * p=(unsigned char *)in_Text;
    int charnum=0,row=0,i=0,j=0,n=0;
    USHORT unichar;
    UBYTE  displayType;
    int font_h, font_w, font_s;
    char mult_line_txt_asc[MAXROW][24];//maxrow X maxchar
    char mult_line_txt_uni[MAXROW][42];//char * type;you should allot 42;
	/* 2003/10/28 sunsj */
	unsigned char ascii_char;
	int total_pixel;
	int current_char_width;
	int scrX_i;


	/* 2003/10/28 sunsj */
    //charnum=(len_x-in_X)/font_w;
	charnum=(len_x)/6;

	if(sub_main == R2D_MAINLCD) /* main LCD */
	{
		font_h		= fontinfo->font_h;
	    font_w		= fontinfo->font_w;
    	font_s		= fontinfo->font_s;
    	displayType = displayData.DisplayType;
    	scrX_i		= scrX;
	}
	else	/* sub LCD */
	{
		font_h		= sub_fontinfo->font_h;
	    font_w		= sub_fontinfo->font_w;
    	font_s		= sub_fontinfo->font_s;
    	displayType = sub_displayData.DisplayType;
    	scrX_i		= sub_scrX;
	}	

    if(Newline)
    {
        if(in_Attrib&DSPL_TXTATTR_ASCIIMODE)//if ascii
        {
			/* 2003/10/28 sunsj some ascii code will convert a big number through type convert */
			ascii_char = *p;
            for(i=0;i<MAXROW&&(*p!=0);i++)
            {
				/* 2003/10/28 sunsj add for auto width char display */
				total_pixel = 0;
                while((*p!=NEWLINE)&&(j<charnum)&&(*p!=0))
                {
					/* 2003/10/28 sunsj add for auto width char */
					if(sub_main == R2D_MAINLCD)
						current_char_width = get_CharWidth((USHORT)ascii_char);
					else
						current_char_width = sub_get_CharWidth((USHORT)ascii_char);
						
					total_pixel += current_char_width;
					if( total_pixel > len_x )
					{
						break;
					}

                    mult_line_txt_asc[i][j++]=(char)*p++;
					/* 2003/10/28 sunsj get the new char */
					ascii_char = *p;
                }
                row++;
                mult_line_txt_asc[i][j]=0x00;//set the end char to 0x00;
                if(*p==NEWLINE&&*(p+1)!=0x00)//if newline and next char isn't 0x00, get next char;
                    p++;
                j=0;            
            }
        }
        else/* if(in_Attrib&DSPL_TXTATTR_UNIMODE)*/
        {
            //if unicode
            unichar=(*p<<8)+*(p+1);
            for(i=0;i<MAXROW&&(unichar!=0x0000);i++)
            {
                n=0;
				/* 2003/10/28 sunsj add for auto width char display */
				total_pixel = 0;
                while((unichar!=NEWLINE)&&((n<(charnum-1))||((n==charnum-1)&&(unichar<=0xff)))&&(unichar!=0x0000))
                {
					/* 2003/10/28 sunsj add for auto width char */
					if(sub_main == R2D_MAINLCD)
						current_char_width = get_CharWidth(unichar);
					else
						current_char_width = sub_get_CharWidth(unichar);
						
					total_pixel += current_char_width;
					if( total_pixel > (len_x) )
					{
						break;
					}

                    mult_line_txt_uni[i][j++]=(char)*p;
                    mult_line_txt_uni[i][j++]=(char)*(p+1);
                    if(unichar<=0xff)
                        n++;
					/* 2003/10/13 sunsj pinyin code display number */
					else if(unichar >= 0xf461 && unichar <= 0xf490)
						n++;
                    else
                        n+=2;
                    p+=2;
                    unichar=(USHORT)((*p<<8)+*(p+1));
                }
                row++;
                mult_line_txt_uni[i][j]=0x00;//set the end byte to 0x00,0x00;
                mult_line_txt_uni[i][j+1]=0x00;
                if(unichar==NEWLINE&&(((*(p+2)<<8)+*(p+3))!=0x0000))
                {//if newline and next byte isn't 0x0000, get next byte;
                    p+=2;
                    unichar=(USHORT)((*p<<8)+*(p+1));
                }
                j=0;        
                n=0;
            }
        }
    }
    else
    {
        row=1;
        if(in_Attrib&DSPL_TXTATTR_ASCIIMODE)
        { // if ascii
            memcpy(mult_line_txt_asc,p,24);
            mult_line_txt_asc[0][charnum]=0;
        }
        else
        { // if unicode
            charnum=wstrlen(in_Text)-1;  //xsf add for real length of str 2003.03.10 minus 0x80
            memcpy(mult_line_txt_uni[0],&in_Text[1],charnum);
            mult_line_txt_uni[0][charnum+1]=0;
            mult_line_txt_uni[0][charnum]=0;
        }
    }
    // SH - If we want signed coordinates (i.e. if x and y can have negative numbers)
    // we need to convert the unsigned values into two's complement.

    if(in_Attrib & DSPL_TXTATTR_SIGNED_COORDS)
    {
        in_X_signed = (SHORT)(scrX_i-len_x)/2;
        in_Y_signed = (SHORT)in_Y;
    }
    else
    {
        in_X_signed =50;/*jhxu720 (SHORT)(scrX_i-len_x)/2;*/
        in_Y_signed = in_Y;
    }

#if defined (WIN32_FORREST)
    if(scrEnabled)
    {
        scrText(in_X, in_Y, in_Attrib, in_Text); // zhangzg Eastcom 0703/2002
    }
    else
        LCD_WriteString (in_Y, in_X, (UBYTE *) in_Text);
#else
    if(displayType EQ DSPL_TYPE_CHARACTER)
    {
        if(in_Attrib&DSPL_TXTATTR_ASCIIMODE)
        {
            for(i=0;i<row;i++)
            {
            	if(sub_main == R2D_MAINLCD)
                	scrText(font_w * in_X_signed + 2, font_h * (in_Y_signed+i), in_Attrib,(char *)mult_line_txt_asc[i]);
                else
                	sub_scrText(font_w * in_X_signed + 2, font_h * (in_Y_signed+i), in_Attrib,(char *)mult_line_txt_asc[i]);
            }
        }
        else if(in_Attrib&DSPL_TXTATTR_UNIMODE)
        {
            char *ss;
            for(i=0;i<row;i++)
            {
                ss=*(mult_line_txt_uni+i);
                if(sub_main == R2D_MAINLCD)
	                scrText_Unicode(2*font_w * in_X_signed + 2, font_h * (in_Y_signed+i), in_Attrib, ss);
				else
					sub_scrText_Unicode(2*font_w * in_X_signed + 2, font_h * (in_Y_signed+i), in_Attrib, ss);
            }
        }
    }
    else
    {
        if(in_Attrib&DSPL_TXTATTR_ASCIIMODE)
        {
            //2004-05-10 Sunny removed
            for(i=0;i<row - 1;i++)//old:for(i=0;i<row;i++)
            {
            	if(sub_main == R2D_MAINLCD)
	                scrText(in_X_signed,in_Y_signed+i*font_h, in_Attrib, (char *)mult_line_txt_asc[i]);
	            else
	            	sub_scrText(in_X_signed,in_Y_signed+i*font_h, in_Attrib, (char *)mult_line_txt_asc[i]);
            }

            /* 2004/05/26 sunsj modify */
            if( (i==(row-1))&&(row-1)==0 )
            {
				in_X_signed=56;/*jhxu720(scrX_i-total_pixel)/2;*/
				
            	if(sub_main == R2D_MAINLCD)
	                scrText(in_X_signed,in_Y_signed+i*font_h, in_Attrib, (char *)mult_line_txt_asc[i]);
	            else
	            	sub_scrText(in_X_signed,in_Y_signed+i*font_h, in_Attrib, (char *)mult_line_txt_asc[i]);
            }
			//2004-05-10 Sunny add end
        }
        else
        {
            char *ss;
            for(i=0;i<row-1;i++)
            {
            		
                ss=*(mult_line_txt_uni+i);
                if(sub_main == R2D_MAINLCD)
	                scrText_Unicode(in_X_signed,in_Y_signed+i*font_h, in_Attrib, ss);
	            else
	            	sub_scrText_Unicode(in_X_signed,in_Y_signed+i*font_h, in_Attrib, ss);
            }
		
			if((i==(row-1))&&(row-1)!=0)
			{
				in_X_signed=56;/*(scrX_i-total_pixel)/2;jhxu720*/
				ss=*(mult_line_txt_uni+i);
				if(sub_main == R2D_MAINLCD)
					scrText_Unicode(in_X_signed,in_Y_signed+i*font_h, in_Attrib, ss);
				else
					sub_scrText_Unicode(in_X_signed,in_Y_signed+i*font_h, in_Attrib, ss);
			}

			
        }
    }
#endif
     return DRV_OK;
}

/* Compatiable with old version, 2003-12-16, Robert.Chen */
GLOBAL UBYTE dspl_TextOut_Cmode_Center(USHORT in_Y, USHORT len_x, UBYTE in_Attrib,
                                             char * in_Text, UBYTE Newline)
{
	return dspl_TextOut_Cmode_Center_i(in_Y, len_x, in_Attrib, in_Text, Newline, R2D_MAINLCD);
}

GLOBAL UBYTE dspl_sub_TextOut_Cmode_Center(USHORT in_Y, USHORT len_x, UBYTE in_Attrib,
                                             char * in_Text, UBYTE Newline)
{
	return dspl_TextOut_Cmode_Center_i(in_Y, len_x, in_Attrib, in_Text, Newline, R2D_SUBLCD);
}

#else
/*2003/11/25, wangyan add for multi-line text show in center mode*/
GLOBAL UBYTE dspl_TextOut_Cmode_Center(USHORT  in_Y, USHORT  len_x,UBYTE   in_Attrib,char * in_Text,
                                 UBYTE Newline)
{
    int in_X_signed;
    int in_Y_signed;
    unsigned char * p=(unsigned char *)in_Text;
    int charnum=0,row=0,i=0,j=0,n=0;
    USHORT unichar;
    int font_h=fontinfo->font_h;
    int font_w=fontinfo->font_w;
    int font_s=fontinfo->font_s;
    char mult_line_txt_asc[MAXROW][24];//maxrow X maxchar
    char mult_line_txt_uni[MAXROW][42];//char * type;you should allot 42;
	/* 2003/10/28 sunsj */
	unsigned char ascii_char;
	int total_pixel;
	int current_char_width;


	/* 2003/10/28 sunsj */
    //charnum=(len_x-in_X)/font_w;
	charnum=(len_x)/6;

    if(Newline)
    {
        if(in_Attrib&DSPL_TXTATTR_ASCIIMODE)//if ascii
        {
			/* 2003/10/28 sunsj some ascii code will convert a big number through type convert */
			ascii_char = *p;
            for(i=0;i<MAXROW&&(*p!=0);i++)
            {
				/* 2003/10/28 sunsj add for auto width char display */
				total_pixel = 0;
                while((*p!=NEWLINE)&&(j<charnum)&&(*p!=0))
                {
					/* 2003/10/28 sunsj add for auto width char */
					current_char_width = get_CharWidth((USHORT)ascii_char);
					total_pixel += current_char_width;
					if( total_pixel > len_x )
					{
						break;
					}

                    mult_line_txt_asc[i][j++]=(char)*p++;
					/* 2003/10/28 sunsj get the new char */
					ascii_char = *p;
                }
                row++;
                mult_line_txt_asc[i][j]=0x00;//set the end char to 0x00;
                if(*p==NEWLINE&&*(p+1)!=0x00)//if newline and next char isn't 0x00, get next char;
                    p++;
                j=0;            
            }
        }
        else/* if(in_Attrib&DSPL_TXTATTR_UNIMODE)*/
        {
            //if unicode
            unichar=(*p<<8)+*(p+1);
            for(i=0;i<MAXROW&&(unichar!=0x0000);i++)
            {
                n=0;
				/* 2003/10/28 sunsj add for auto width char display */
				total_pixel = 0;
                while((unichar!=NEWLINE)&&((n<(charnum-1))||((n==charnum-1)&&(unichar<=0xff)))&&(unichar!=0x0000))
                {
					/* 2003/10/28 sunsj add for auto width char */
					current_char_width = get_CharWidth(unichar);
					total_pixel += current_char_width;
					if( total_pixel > (len_x) )
					{
						break;
					}

                    mult_line_txt_uni[i][j++]=(char)*p;
                    mult_line_txt_uni[i][j++]=(char)*(p+1);
                    if(unichar<=0xff)
                        n++;
					/* 2003/10/13 sunsj pinyin code display number */
					else if(unichar >= 0xf461 && unichar <= 0xf490)
						n++;
                    else
                        n+=2;
                    p+=2;
                    unichar=(USHORT)((*p<<8)+*(p+1));
                }
                row++;
                mult_line_txt_uni[i][j]=0x00;//set the end byte to 0x00,0x00;
                mult_line_txt_uni[i][j+1]=0x00;
                if(unichar==NEWLINE&&(((*(p+2)<<8)+*(p+3))!=0x0000))
                {//if newline and next byte isn't 0x0000, get next byte;
                    p+=2;
                    unichar=(USHORT)((*p<<8)+*(p+1));
                }
                j=0;        
                n=0;
            }
        }
    }
    else
    {
        row=1;
        if(in_Attrib&DSPL_TXTATTR_ASCIIMODE)
        { // if ascii
            memcpy(mult_line_txt_asc,p,24);
            mult_line_txt_asc[0][charnum]=0;
        }
        else
        { // if unicode
            charnum=wstrlen(in_Text)-1;  //xsf add for real length of str 2003.03.10 minus 0x80
            memcpy(mult_line_txt_uni[0],&in_Text[1],charnum);
            mult_line_txt_uni[0][charnum+1]=0;
            mult_line_txt_uni[0][charnum]=0;
        }
    }
    // SH - If we want signed coordinates (i.e. if x and y can have negative numbers)
    // we need to convert the unsigned values into two's complement.

    if(in_Attrib & DSPL_TXTATTR_SIGNED_COORDS)
    {
        in_X_signed = (SHORT)(scrX-len

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -