⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gchar.c

📁 达盛EL-ARM-830
💻 C
字号:
/*
;************************************************************************************************************
;*				    				     北京达盛科技有限公司
;*                                     	    研    发    部
;*
;*                                 	    http://www.techsine.com
;*
;*--------------------------------------------- 文件信息 ----------------------------------------------------                                      
;*
;* 文件名称 : Gchar.c	
;* 文件功能 : 该文件为GUI的字符显示程序。
;* 补充说明 : 
;*-------------------------------------------- 最新版本信息 -------------------------------------------------
;* 修改作者 : ARM开发小组
;* 修改日期 : 2004/00/00
;* 版本声明 : V1.0.1
;*-------------------------------------------- 历史版本信息 -------------------------------------------------
;* 文件作者 : ARM开发小组
;* 创建日期 : 2004/07/07
;* 版本声明 : v1.0.0
;*-----------------------------------------------------------------------------------------------------------
*************************************************************************************************************
*/
	#include "..\Glib\Glib.h"
	
	Context GUI_Context;
	extern U16 LCD_BKCOLOR;
	
	void 	DispString(const I8 *s); 
 	U16 	GUI_GetLineLen(const I8 *s, U16 MaxLen); 
	U16 	GUI_GetLineDistX(const I8 *s, U16 Len); 
	U16 	GUI_GetCharDistX(void);
	void 	GUI_DispLine(const I8 *s, I16 Len, const GUI_RECT* pr); 
	void 	GL_DispChar(U16 c); 
	U16 	GUI_DB2UC_CN (U8 Byte0, U8 Byte1); 
	void 	GUI_DispNextLine(void); 
	U16 	GUI_GetFontDistY(void); 
	void 	GUIMONO_DispChar(U16P c); 
	void 	LCD_DrawBitmap   (U16 x0, U16 y0,
                       		U16 xsize, U16 ysize,
                       		U16 xMul, U16 yMul,
                       		U16 BitsPerPixel,
                       		U16 BytesPerLine,
                       		const U8* pPixel);
/*
*************************************************************************************************************
- 函数名称 : const Set_Font(const GUI_FONT* pNewFont)
- 函数说明 : 设定字体函数
- 输入参数 : color
- 输出参数 : 无
*************************************************************************************************************
*/
void  Set_Font( GUI_FONT* pFont) 
{
  	if (pFont)
  	{
    	GUI_Context.pAFont = pFont;
	}
}

/*
*************************************************************************************************************
- 函数名称 : void DispStringAt(const U8 *s, I16 x, I16 y)
- 函数说明 : 显示字符串的API
- 输入参数 : s,x,y
- 输出参数 : 无
*************************************************************************************************************
*/
void Disp_String(const I8 *s, I16 x, I16 y) 
{
  	GUI_Context.DispPosX = x;
  	GUI_Context.DispPosY = y;
  	DispString(s);
}

/*
*************************************************************************************************************
- 函数名称 : void DispString(const U8 *s)
- 函数说明 : 显示字符串
- 输入参数 : s
- 输出参数 : 无
*************************************************************************************************************
*/

void DispString(const I8 *s) 
{
  	I16 	xOrg;
  	U8 		FontSizeY;
  	
  	if (!s)
    	return;
 
  	FontSizeY = GUI_Context.pAFont->YDist;
  	
  	xOrg = GUI_Context.DispPosX;
  	
  	for (; *s; s++) 
  	{
    	GUI_RECT r;
    	
    	U16 LineLen= GUI_GetLineLen(s,0x7fff);
    	
    	U16 xLineSize = GUI_GetLineDistX(s, LineLen);
    	
    	r.x0 = GUI_Context.DispPosX;
    	r.x1 = r.x0 + xLineSize-1;    
    	r.y0 = GUI_Context.DispPosY;
    	r.y1 = r.y0 + FontSizeY-1; 
    	   
    	GUI_DispLine(s, LineLen, &r);
    	
    	GUI_Context.DispPosY = r.y0;
    	
    	s += LineLen;
    	
    	if ((*s=='\n') || (*s=='\r')) 
    	{
      		GUI_Context.DispPosX = GUI_Context.LBorder;
      		
       		if (*s=='\n')
        		GUI_Context.DispPosY += GUI_GetFontDistY();
    	} 
    	else 
    	{
      		GUI_Context.DispPosX = r.x0+xLineSize;
    	}
    	if (*s==0)    			
      		break;
  	}
}
/*
*************************************************************************************************************
- 函数名称 : U16 GUI_GetLineLen(const U8 *s, U16 MaxLen) 
- 函数说明 : 得到显示字符串的长度数
- 输入参数 : s,MaxLen
- 输出参数 : len
*************************************************************************************************************
*/
U16 GUI_GetLineLen(const I8 *s, U16 MaxLen) 
{
  	U16 Len =0;
  	
  	if (!s)
    	return 0;
    	
  	{
    	U8 c0;
    	
    	U8 CNActive = 0;
    
    	while (((c0 = *(U8*)s) != 0) && Len < MaxLen) 
    	{
      		s++;
      		if (CNActive) 
      		{
        		switch (c0) 
        		{
        			case CHINESE_ENDCHAR: //case GUI_UC_ENDCHAR: 
        				CNActive = 0; 
        				break;
        			default: 
        				Len++; s++;
        		}
      		} 
      		else 
      		{ 									
        		switch (c0) 
        		{
        			case CHINESE_STARTCHAR: //case GUI_UC_STARTCHAR: 
        				CNActive = 1; 
        				break;
        			
        			case '\n': 
        				return Len;
        			
        			case '\r': 
        				return Len;
        		}
      		}
      		Len++;
    	}
  	}
  return Len;
}
/*
*************************************************************************************************************
- 函数名称 : U16 GUI_GetLineDistX(const U8 GUI_FAR *s, U16 Len)
- 函数说明 : 得到显示字符串的长度
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/

U16 GUI_GetLineDistX(const I8 *s, U16 Len) 
{
  	U16 Dist =0;
  	U8  c1;
    {
      	U8 c0;
      	U8 CNActive=0;
      	
      	while (((c0 = *(U8*)s) !=0) && Len >0) 
      	{
        	s++; Len--;
        	
        	if (CNActive) 
        	{
          		if (c0 == CHINESE_ENDCHAR) //GUI_UC_ENDCHAR)
            	{
            		CNActive = 0;
            	}
          		else 
          		{
            		c1 = *(U8*)s++;
            		Len--;
            		Dist += GUI_GetCharDistX();
          		}
        	} 
        	else 
        	{ 							
          		if (c0 == CHINESE_STARTCHAR) //GUI_UC_STARTCHAR)
            		CNActive = 1;
          		else
            		Dist += GUI_GetCharDistX();
        	}
      	}
  	}
  return Dist;
}

/*
*************************************************************************************************************
- 函数名称 : U16 GUI_GetCharDistX(U16 c)
- 函数说明 : 得到单个字符的X方向长度
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/

U16 GUI_GetCharDistX(void)
{
   	const GUI_FONT_MONO* pMono = GUI_Context.pAFont->pMono;
  	return pMono->XDist;
}

/*
*************************************************************************************************************
- 函数名称 : void GUI_DispLine(const U8 *s, U16 Len, const GUI_RECT* pr)
- 函数说明 : 显示行字符的API
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/

void GUI_DispLine(const I8 *s, I16 Len, const GUI_RECT* pr) 
{
  	GUI_RECT r;
  	U8 c0;
    U8 CNActive = 0;
    
  	r = *pr;
    GUI_Context.DispPosX = r.x0;
    GUI_Context.DispPosY = r.y0;
    
    while (--Len >=0) 
    {
      	c0 = *(U8*)s++;
      	
      	if (CNActive) 
      	{
        	if (c0 == CHINESE_ENDCHAR)//GUI_UC_ENDCHAR)
        	{
          		CNActive = 0;
        	}
        	else 
        	{
          		U8  c1 = *(U8*)s++;
          		Len--;
          		GL_DispChar (GUI_DB2UC_CN(c0, c1));
        	}
      	} 
      	else 
      	{ 					
        	if (c0 == CHINESE_STARTCHAR)//GUI_UC_STARTCHAR)
          		CNActive = 1;
        	else
          		GL_DispChar(c0);
      	}
    }
}

/*
*************************************************************************************************************
- 函数名称 : void GL_DispChar(U16 c)
- 函数说明 : 显示字符
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/

void GL_DispChar(U16 c) 
{
  	if (c == '\n') 
  	{
    	GUI_DispNextLine();
  	} 
  	else 
  	{
    	if (c != '\r') 
    	{
      		GUIMONO_DispChar(c);
    	}
  	}
}

/*
*************************************************************************************************************
- 函数名称 : U16 GUI_DB2UC_CN (U8 Byte0, U8 Byte1)
- 函数说明 : 内码转换
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/

U16 GUI_DB2UC_CN (U8 Byte0, U8 Byte1) 
{
  	U8 GB2312_HZK_QU_CODE;
  	U8 GB2312_HZK_WEI_CODE;
  
  	GB2312_HZK_QU_CODE   =  Byte0;       
  	GB2312_HZK_WEI_CODE  =  Byte1;
  	GB2312_HZK_QU_CODE  -=  0xa1;                       //内码转换
  	GB2312_HZK_WEI_CODE -=  0xa1;
  	return (GB2312_HZK_QU_CODE*94 + GB2312_HZK_WEI_CODE);
}

/*
*************************************************************************************************************
- 函数名称 : void GUI_DispNextLine(void) 
- 函数说明 : 从下一行显示
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/

void GUI_DispNextLine(void) 
{
  	GUI_Context.DispPosY += GUI_GetFontDistY();
  	GUI_Context.DispPosX  = GUI_Context.LBorder;
}

/*
*************************************************************************************************************
- 函数名称 : U16 GUI_GetFontDistY(void)
- 函数说明 : 得到字体的Y大小
- 输入参数 : 无
- 输出参数 : r
*************************************************************************************************************
*/

U16 GUI_GetFontDistY(void) 
{
  	U16 r;
  	r = GUI_Context.pAFont->YDist * GUI_Context.pAFont->YMag;
  	return r;
}

/*
*************************************************************************************************************
- 函数名称 : void GUIMONO_DispChar(U16P c)
- 函数说明 : 单字体显示
- 输入参数 : c
- 输出参数 : 无
*************************************************************************************************************
*/

void GUIMONO_DispChar(U16P c) 
{
  	I16 c0, c1;
  	U8 * pd;
  	U16 x = GUI_Context.DispPosX;
  	U16 y = GUI_Context.DispPosY;
																	
  	const GUI_FONT_MONO* pMono = GUI_Context.pAFont->pMono;
  	U16 FirstChar = pMono->FirstChar;
  																	
     																	
	if ((c >= (U16P)FirstChar) &&(c <= (U16P)pMono->LastChar)) 
  	{
    	pd = (U8*)pMono->pData;
    	c0 = ((U16)c) - FirstChar;
    	c1 = -1;
  	} 
  	else 
  	{

  	}
  	if (c0!=-1) 
  	{
    	U16 BytesPerChar = GUI_Context.pAFont->YSize*pMono->BytesPerLine;
     	U16 XSize = pMono->XSize;
    	U16 YSize = GUI_Context.pAFont->YSize;
  
        LCD_DrawBitmap( x, y,
                         	XSize, YSize,
                        	GUI_Context.pAFont->XMag,  GUI_Context.pAFont->YMag,
                         	1,     
                         	pMono->BytesPerLine,
                         	pd + c0* BytesPerChar);
    }
  	GUI_Context.DispPosX += pMono->XDist;
}

/*
*************************************************************************************************************
- 函数名称 : LCD_DrawBitmap
- 函数说明 : LCD画API
- 输入参数 : 
- 输出参数 : 无
*************************************************************************************************************
*/

void LCD_DrawBitmap   (U16 x0, U16 y0,
                       U16 xsize, U16 ysize,
                       U16 xMul, U16 yMul,
                       U16 BitsPerPixel,
                       U16 BytesPerLine,
                       const U8* pPixel) 
{
  	U16 x1, y1;
  	const U16* pTrans;
  	U16 Diff = 0;
  	
  	y1 = y0+ysize-1;
  	x1 = x0+xsize-1;
 
	pTrans = (BitsPerPixel != 1) ? NULL : &LCD_BKCOLOR;
		
  	if ((xMul==1) && (yMul==1)) 
  	{
      	LCD_L0_DrawBitmap(x0,y0, xsize, ysize, BitsPerPixel, BytesPerLine, pPixel, Diff, pTrans);
  	} 
  	else 
  	{
    }
}
/*
*****************************************************************************************************************
**                                                  结束文件                                                   **
*****************************************************************************************************************
*/

⌨️ 快捷键说明

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