|
修改如下两个函数即可,在文件bsp_tft_lcd.C文件:
- /*
- *********************************************************************************************************
- * 函 数 名: LCD_DispStrEx
- * 功能说明: 在LCD指定坐标(左上角)显示一个字符串。 增强型函数。支持左\中\右对齐,支持定长清屏。
- * 形 参:
- * _usX : X坐标
- * _usY : Y坐标
- * _ptr : 字符串指针
- * _tFont : 字体结构体,包含颜色、背景色(支持透明)、字体代码、文字间距等参数。可以指定RA8875字库显示汉字
- * _Width : 字符串显示区域的宽度. 0 表示不处理留白区域,此时_Align无效
- * _Align :字符串在显示区域的对齐方式,
- * ALIGN_LEFT = 0,
- * ALIGN_CENTER = 1,
- * ALIGN_RIGHT = 2
- * 返 回 值: 无
- *********************************************************************************************************
- */
- void LCD_DispStrEx(uint16_t _usX, uint16_t _usY, char *_ptr, FONT_T *_tFont, uint16_t _Width,
- uint8_t _Align)
- {
- uint32_t i;
- uint8_t code1;
- uint8_t code2;
- uint8_t buf[32 * 32 / 8]; /* 最大支持32点阵汉字 */
- uint8_t width;
- uint16_t m;
- uint8_t font_width = 0;
- uint8_t font_height = 0;
- uint16_t x, y;
- uint16_t offset;
- uint16_t str_width; /* 字符串实际宽度 */
-
- uint8_t line_bytes;
- uint8_t asc_bytes = 0;
- uint8_t hz_bytes = 0;
- switch (_tFont->FontCode)
- {
- case FC_ST_12: /* 12点阵 */
- font_height = 12;
- font_width = 12;
- asc_bytes = 1;
- hz_bytes = 2;
- break;
-
- case FC_ST_16:
- font_height = 16;
- font_width = 16;
- asc_bytes = 1;
- hz_bytes = 2;
- break;
- case FC_ST_24:
- font_height = 24;
- font_width = 24;
- asc_bytes = 2;
- hz_bytes = 3;
- break;
-
- case FC_ST_32:
- font_height = 32;
- font_width = 32;
- asc_bytes = 2;
- hz_bytes = 4;
- break;
- }
-
- str_width = LCD_GetStrWidth(_ptr, _tFont); /* 计算字符串实际宽度(RA8875内部ASCII点阵宽度为变长 */
- offset = 0;
- if (_Width > str_width)
- {
- if (_Align == ALIGN_RIGHT) /* 右对齐 */
- {
- offset = _Width - str_width;
- }
- else if (_Align == ALIGN_CENTER) /* 左对齐 */
- {
- offset = (_Width - str_width) / 2;
- }
- else /* 左对齐 ALIGN_LEFT */
- {
- ;
- }
- }
- /* 左侧填背景色, 中间对齐和右边对齐 */
- if (offset > 0)
- {
- LCD_Fill_Rect(_usX, _usY, LCD_GetFontHeight(_tFont), offset, _tFont->BackColor);
- _usX += offset;
- }
-
- /* 右侧填背景色 */
- if (_Width > str_width)
- {
- LCD_Fill_Rect(_usX + str_width, _usY, LCD_GetFontHeight(_tFont), _Width - str_width - offset, _tFont->BackColor);
- }
-
- /* 使用CPU内部字库. 点阵信息由CPU读取 */
- {
- /* 开始循环处理字符 */
- while (*_ptr != 0)
- {
- code1 = *_ptr; /* 读取字符串数据, 该数据可能是ascii代码,也可能汉字代码的高字节 */
- if (code1 < 0x80)
- {
- /* 将ascii字符点阵复制到buf */
- _LCD_ReadAsciiDot(code1, _tFont->FontCode, buf); /* 读取ASCII字符点阵 */
- width = font_width / 2;
- line_bytes = asc_bytes;
- }
- else
- {
- code2 = *++_ptr;
- if (code2 == 0)
- {
- break;
- }
- /* 读1个汉字的点阵 */
- _LCD_ReadHZDot(code1, code2, _tFont->FontCode, buf);
- width = font_width;
- line_bytes = hz_bytes;
- }
-
- y = _usY;
- /* 开始刷LCD */
- for (m = 0; m < font_height; m++) /* 字符高度 */
- {
- x = _usX;
- for (i = 0; i < width; i++) /* 字符宽度 */
- {
- if ((buf[m * line_bytes + i / 8] & (0x80 >> (i % 8 ))) != 0x00)
- {
- LCD_PutPixel(x, y, _tFont->FrontColor); /* 设置像素颜色为文字色 */
- }
- else
- {
- if (_tFont->BackColor != CL_MASK) /* 透明色 */
- {
- LCD_PutPixel(x, y, _tFont->BackColor); /* 设置像素颜色为文字背景色 */
- }
- }
-
- x++;
- }
- y++;
- }
-
- if (_tFont->Space > 0)
- {
- /* 如果文字底色按_tFont->usBackColor,并且字间距大于点阵的宽度,那么需要在文字之间填充(暂时未实现) */
- }
- _usX += width + _tFont->Space; /* 列地址递增 */
- _ptr++; /* 指向下一个字符 */
- }
- }
- }
复制代码- /*
- *********************************************************************************************************
- * 函 数 名: _LCD_ReadAsciiDot
- * 功能说明: 读取1个ASCII字符的点阵数据
- * 形 参:
- * _code : ASCII字符的编码,1字节。1-128
- * _fontcode :字体代码
- * _pBuf : 存放读出的字符点阵数据
- * 返 回 值: 文字宽度
- *********************************************************************************************************
- */
- static void _LCD_ReadAsciiDot(uint8_t _code, uint8_t _fontcode, uint8_t *_pBuf)
- {
- const uint8_t *pAscDot;
- uint8_t font_bytes = 0;
- uint16_t m;
- uint16_t address;
- uint8_t fAllHz = 0; /* 1表示程序中内嵌全部的ASCII字符集 */
- pAscDot = 0;
- switch (_fontcode)
- {
- case FC_ST_12: /* 12点阵 */
- font_bytes = 24 / 2;
- pAscDot = g_Ascii12;
- fAllHz = 1;
- break;
-
- case FC_ST_16:
- /* 缺省是16点阵 */
- font_bytes = 32 / 2;
- pAscDot = g_Ascii16;
- fAllHz = 1;
- break;
-
- case FC_ST_24:
- font_bytes = 48;
- pAscDot = g_Ascii24;
- break;
-
- case FC_ST_32:
- font_bytes = 64;
- pAscDot = g_Ascii32;
- break;
-
- default:
- return;
- }
- if (fAllHz == 1) /* 内嵌全部ASCII字符点阵 */
- {
- /* 将CPU内部Flash中的ascii字符点阵复制到buf */
- memcpy(_pBuf, &pAscDot[_code * (font_bytes)], (font_bytes));
- }
- else /* 内嵌部分字符,字模数组首字节是ASCII码 */
- {
- m = 0;
- while(1)
- {
- address = m * (font_bytes + 1);
- m++;
- if (_code == pAscDot[address + 0])
- {
- address += 1;
- memcpy(_pBuf, &pAscDot[address], font_bytes);
- break;
- }
- else if ((pAscDot[address + 0] == 0xFF) && (pAscDot[address + 1] == 0xFF))
- {
- /* 字库搜索完毕,未找到,则填充全FF */
- memset(_pBuf, 0xFF, font_bytes);
- break;
- }
- }
- }
- }
复制代码
|
|