论坛元老
 
- 积分
- 10653
- 金钱
- 10653
- 注册时间
- 2017-4-14
- 在线时间
- 2780 小时
|
发表于 2022-4-5 18:55:22
|
显示全部楼层
- //在指定位置开始显示一个字符串
- //支持自动换行
- //(x,y):起始坐标
- //width,height:区域
- //str :字符串
- //size :字体大小
- //mode:0,正常显示,1,反色显示
- void TFT_Show_Str(u16 x,u16 y,u16 width,u16 height,u8 size,u8 mode,u8*str)
- {
- u16 x0=x;
- u16 y0=y;
- if(mode==1)
- TFT_Change_Back_Brush_Color();
- while(*str!=0)//数据未结束
- {
- if((*str)<=0x80)//字符
- {
- if(x>(x0+width-size/2))//换行
- {
- y+=size;
- x=x0;
- }
- if(y>(y0+height-size))break;//越界返回
- if(*str==13)//换行符号
- {
- y+=size;
- x=x0;
- str++;
- }
- else TFT_ShowChar(x,y,*str,size);//有效部分写入
- str++;
- x+=size/2; //字符,为全字的一半
- }
- if(*str>0x80) //中文
- {
- #if (Font_Weizhi!=0)//#if (SET_W25Qxx==0&&SET_SD==0)
- if(x>(x0+width-size))//换行
- {
- y+=size;
- x=x0;
- }
- if(y>(y0+height-size))break;//越界返回
- TFT_Show_Font(x,y,str,size); //显示这个汉字,空心显示
- x+=size;//下一个汉字偏移
- #endif
- str+=2;
- }
- }
- if(mode==1)
- TFT_Change_Back_Brush_Color();
- }
- //在指定位置开始显示一个字符串
- //支持自动换行
- //(x,y):起始坐标
- //width,height:区域
- //str :字符串
- //size :字体大小
- //mode:0,正常显示,1,反色显示
- void TFT_Printf(u16 x,u16 y,u16 width,u16 height,u8 size,u8 mode,char *fmt, ...)
- {
- u8 temp[100];
- va_list arg_ptr;
- va_start(arg_ptr, fmt);
- vsnprintf((char *)temp, 100+1, fmt, arg_ptr);
- va_end(arg_ptr);
- TFT_Show_Str(x,y,width,height,size,mode,temp);
- }
复制代码 |
|