|
发表于 2018-1-24 10:21:01
|
显示全部楼层
也没问题,修改下你的文本显示API,可以参考我们F429的裸机API,可以设置透明,也就是不绘制字体背景色,仅绘制前景色。
- /*
- *********************************************************************************************************
- * 函 数 名: 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]; /* 最大支持24点阵汉字 */
- 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; /* 字符串实际宽度 */
- switch (_tFont->FontCode)
- {
- case FC_ST_12: /* 12点阵 */
- font_height = 12;
- font_width = 12;
- break;
-
- case FC_ST_16:
- font_height = 16;
- font_width = 16;
- break;
- case FC_ST_24:
- font_height = 24;
- font_width = 24;
- break;
-
- case FC_ST_32:
- font_height = 32;
- font_width = 32;
- 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 */
- //memcpy(buf, &pAscDot[code1 * (font_bytes / 2)], (font_bytes / 2));
- _LCD_ReadAsciiDot(code1, _tFont->FontCode, buf); /* 读取ASCII字符点阵 */
- width = font_width / 2;
- }
- else
- {
- code2 = *++_ptr;
- if (code2 == 0)
- {
- break;
- }
- /* 读1个汉字的点阵 */
- _LCD_ReadHZDot(code1, code2, _tFont->FontCode, buf);
- width = font_width;
- }
-
- y = _usY;
- /* 开始刷LCD */
- for (m = 0; m < font_height; m++) /* 字符高度 */
- {
- x = _usX;
- for (i = 0; i < width; i++) /* 字符宽度 */
- {
- if ((buf[m * ((2 * width) / font_width) + 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++; /* 指向下一个字符 */
- }
- }
复制代码
|
|