?? tft_api.c
字號(hào):
//=============================================================
//語(yǔ)法格式: short TFT_GetChineseFont(STR_WINDOW *Window, STR_FONT *FontInfo);
//實(shí)現(xiàn)功能: 獲取當(dāng)前使用的中文字庫(kù)信息
//參數(shù): Window - 工作窗口指針
// FontInfo - 字庫(kù)信息結(jié)構(gòu)體地址
//返回值: 字庫(kù)序號(hào)
//=============================================================
FONT TFT_GetChineseFont(WIN_HANDLE Handle, STR_FONT *FontInfo)
{
STR_WINDOW *Window = g_WinList + Handle;
if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0))
return -1;
FontInfo->CharWidth = 0;
FontInfo->CharHeight = 0;
FontInfo->FontBuf = FONT_UNUSE_FLAG;
TFT_GetAsciiFontInfo(Window->ChineseFont, FontInfo);
return Window->ChineseFont;
}
//=============================================================
//語(yǔ)法格式: void TFT_SetAsciiFont(STR_WINDOW *Window, short FontType);
//實(shí)現(xiàn)功能: 設(shè)置當(dāng)前使用的ASCII字庫(kù)
//參數(shù): Window - 工作窗口指針
// FontType - 字庫(kù)序號(hào)(0~n)
//返回值: 無(wú)
//=============================================================
void TFT_SetAsciiFont(WIN_HANDLE Handle, FONT FontID)
{
STR_WINDOW *Window = g_WinList + Handle;
if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0))
return;
Window->AsciiFont = FontID;
}
//=============================================================
//語(yǔ)法格式: short TFT_GetAsciiFont(STR_WINDOW *Window, STR_FONT *FontInfo);
//實(shí)現(xiàn)功能: 獲取當(dāng)前使用的ASCII字庫(kù)信息
//參數(shù): Window - 工作窗口指針
// FontInfo - 字庫(kù)信息結(jié)構(gòu)體地址
//返回值: 字庫(kù)序號(hào)
//=============================================================
FONT TFT_GetAsciiFont(WIN_HANDLE Handle, STR_FONT *FontInfo)
{
STR_WINDOW *Window = g_WinList + Handle;
if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0))
return -1;
FontInfo->CharWidth = 0;
FontInfo->CharHeight = 0;
FontInfo->FontBuf = FONT_UNUSE_FLAG;
TFT_GetChineseFontInfo(Window->ChineseFont, FontInfo);
return Window->ChineseFont;
}
//=============================================================
//語(yǔ)法格式: void TFT_PutChar(STR_WINDOW *Window, unsigned short CharCode);
//實(shí)現(xiàn)功能: 顯示一個(gè)字符或漢字
//參數(shù): Window - 工作窗口指針
// CharCode - 字庫(kù)或漢字的編碼
//返回值: 無(wú)
//=============================================================
void TFT_PutChar(WIN_HANDLE Handle, unsigned short CharCode)
{
STR_WINDOW *Window = g_WinList + Handle;
STR_FONT Font_Char;
short i, j, Temp;
unsigned short *pDispBuf;
unsigned char *pCharBuf;
unsigned char Mask;
short W, H;
if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0))
return;
TFT_GetWorkBufSize(&W, &H);
TFT_CallBack_GetCharBuf(Window, CharCode, &Font_Char); // 獲得字模數(shù)據(jù)
for(i=0; i<Font_Char.CharHeight; i++)
{
Temp = Window->TLy + Window->CurTextY + i;
if(Window->CurTextY + i < 0 || Temp < 0 || Temp > Window->BRy)
continue;
pDispBuf = TFT_SelWorkBuf(-1) + Temp * W + Window->TLx + Window->CurTextX;
pCharBuf = Font_Char.FontBuf + i * ((Font_Char.CharWidth+7)>>3);
Mask = 0x80;
for(j=0; j<Font_Char.CharWidth; j++)
{
Temp = Window->TLx + Window->CurTextX + j;
if(Window->CurTextX+j>=0 && Temp>=0 && Temp<=Window->BRx)
{
if(*pCharBuf & Mask)
{
if(Window->Transparency==0)
*(pDispBuf+j) = Window->FGColor;
else
*(pDispBuf+j) = TFT_CalcTransparent(Window, *(pDispBuf+j), Window->FGColor);
}
else if(Window->BGColor!=COLOR_BLACK)
{
if(Window->Transparency==0)
*(pDispBuf+j) = Window->BGColor;
else
*(pDispBuf+j) = TFT_CalcTransparent(Window, *(pDispBuf+j), Window->BGColor);
}
}
Mask >>= 1;
if(Mask==0x00)
{
Mask = 0x80;
pCharBuf++;
}
}
}
}
//=============================================================
//語(yǔ)法格式: void TFT_PutString(STR_WINDOW *Window, unsigned char *CharBuf);
//實(shí)現(xiàn)功能: 顯示字符串
//參數(shù): Window - 工作窗口指針
// CharBuf - 字符串的起始地址
//返回值: 無(wú)
//=============================================================
void TFT_PutString(WIN_HANDLE Handle, char *CharBuf)
{
STR_WINDOW *Window = g_WinList + Handle;
unsigned char *pCharBuf = (unsigned char *)CharBuf;
unsigned short CharCode;
STR_FONT AsciiFont_Char;
STR_FONT ChineseFont_Char;
if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0))
return;
if( (TFT_GetAsciiFontInfo(Window->AsciiFont, &AsciiFont_Char) == 0) ||
(TFT_GetChineseFontInfo(Window->ChineseFont, &ChineseFont_Char) == 0))
return;
while((CharCode = *pCharBuf++)!='\0')
{
if(CharCode>=0x80) // 漢字
{
if(Window->CurTextX+Window->TLx+ChineseFont_Char.CharWidth > (Window->BRx + 1))
{
Window->CurTextX = 0;
Window->CurTextY += ChineseFont_Char.CharHeight;
if(Window->CurTextY>Window->BRy)break;
}
CharCode |= *(pCharBuf++) << 8;
TFT_PutChar(Handle, CharCode);
Window->CurTextX += ChineseFont_Char.CharWidth;
}
else if(CharCode==0x0D) // 回車
{
Window->CurTextX = 0;
Window->CurTextY += ChineseFont_Char.CharHeight;
if(Window->CurTextY>Window->BRy) break;
if(*pCharBuf==0x0A) pCharBuf++;
}
else if(CharCode==0x0A) // 回車
{
Window->CurTextX = 0;
Window->CurTextY += ChineseFont_Char.CharHeight;
if(Window->CurTextY>Window->BRy) break;
if(*pCharBuf==0x0D) pCharBuf++;
}
else // 字符
{
if(Window->CurTextX+Window->TLx+AsciiFont_Char.CharWidth > (Window->BRx + 1))
{
Window->CurTextX = 0;
Window->CurTextY += AsciiFont_Char.CharHeight;
if(Window->CurTextY>Window->BRy) break;
}
TFT_PutChar(Handle, CharCode);
Window->CurTextX += AsciiFont_Char.CharWidth;
}
}
}
//=============================================================
//語(yǔ)法格式: void TFT_Print(STR_WINDOW *Window, unsigned char *format, ...);
//實(shí)現(xiàn)功能: 根據(jù)指定格式打印字符串
//參數(shù): Window - 工作窗口指針
// format - 格式化字符串
//返回值: 無(wú)
//=============================================================
char linebuf[256];
void TFT_Print(WIN_HANDLE Handle, const char *format, ...)
{
va_list ap;
va_start(ap, format);
vsprintf(linebuf, format, ap);
va_end(ap);
linebuf[255] = 0;
TFT_PutString(Handle, linebuf);
}
//=============================================================
//語(yǔ)法格式: void TFT_PutImage(WIN_HANDLE Handle, short x, short y, STR_IMAGE *pImage);
//實(shí)現(xiàn)功能: 在工作區(qū)中顯示位圖
//參數(shù): Handle - 窗口句柄
// x - 位圖的左上角x坐標(biāo)(相對(duì)于工作區(qū))
// y - 位圖的左上角y坐標(biāo)(相對(duì)于工作區(qū))
// pImage - 存儲(chǔ)位圖信息的結(jié)構(gòu)體地址
//返回值: 無(wú)
//=============================================================
void TFT_PutImage(WIN_HANDLE Handle, short x, short y, STR_IMAGE *pImage)
{
TFT_PutImageEx(Handle, x, y, pImage->Width, pImage->Height, pImage->ImageBuf);
}
//=============================================================
//語(yǔ)法格式: void TFT_PutImageEx(WIN_HANDLE Handle, short x, short y, short width, short height, void *pImage)
//實(shí)現(xiàn)功能: 在工作區(qū)中顯示位圖
//參數(shù): Handle - 窗口句柄
// x - 位圖的左上角x坐標(biāo)(相對(duì)于工作區(qū))
// y - 位圖的左上角y坐標(biāo)(相對(duì)于工作區(qū))
// width - 位圖寬度
// height - 位圖高度
// pImage - 位圖數(shù)據(jù)首地址
//返回值: 無(wú)
//=============================================================
void TFT_PutImageEx(WIN_HANDLE Handle, short x, short y, short width, short height, void *pImage)
{
STR_WINDOW *Window = g_WinList + Handle;
short W, H;
short ScrSx, ScrSy, ScrEx, ScrEy;
short ImgSx, ImgSy, ImgEx, ImgEy;
short i, j;
unsigned short *pImgBuf, *pDispBuf;
if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0))
return;
TFT_GetWorkBufSize(&W, &H);
ScrSx = (x<0) ? Window->TLx : Window->TLx + x; // 計(jì)算實(shí)際顯示區(qū)域
if(ScrSx<0) ScrSx = 0;
if(ScrSx>Window->BRx || ScrSx>=W) return;
ImgSx = ScrSx - Window->TLx - x;
ScrSy = (y<0) ? Window->TLy : Window->TLy + y;
if(ScrSy<0) ScrSy = 0;
if(ScrSy>Window->BRy || ScrSx>=H) return;
ImgSy = ScrSy - Window->TLy - y;
ScrEx = Window->TLx + x + width - 1;
if(ScrEx > Window->BRx) ScrEx = Window->BRx;
if(ScrEx >= W) ScrEx = W - 1;
if(ScrEx<0 || ScrEx<Window->TLx) return;
ImgEx = ScrEx - Window->TLx - x;
ScrEy = Window->TLy + y + height - 1;
if(ScrEy > Window->BRy) ScrEy = Window->BRy;
if(ScrEy >= H) ScrEy = H - 1;
if(ScrEy<0 || ScrEy<Window->TLy) return;
ImgEy = ScrEy - Window->TLy - y;
if(Window->Transparency==0) // 透明度為0則直接顯示
{
for(i=ImgSy; i<=ImgEy; i++)
{
pImgBuf = (unsigned short*)pImage + i * width;
pDispBuf = TFT_SelWorkBuf(-1) + ScrSy * W + ScrSx;
for(j=ImgSx; j<=ImgEx; j++)
{
*(pDispBuf++) = *(pImgBuf+j);
}
ScrSy++;
}
}
else // 透明度不為0則計(jì)算疊加顏色后顯示
{
for(i=ImgSy; i<=ImgEy; i++)
{
pImgBuf = (unsigned short*)pImage + i * width;
pDispBuf = TFT_SelWorkBuf(-1) + ScrSy * W + ScrSx;
for(j=ImgSx; j<=ImgEx; j++)
{
*pDispBuf = TFT_CalcTransparent(Window, *pDispBuf, *(pImgBuf+j));
pDispBuf++;
}
ScrSy++;
}
}
}
//=============================================================
//語(yǔ)法格式: void TFT_PutPicture(WIN_HANDLE Handle, short x, short y, unsigned char *pImage, int AutoScale)
//實(shí)現(xiàn)功能: 在工作區(qū)中顯示圖像
//參數(shù): Window - 工作窗口指針
// x,y - 圖像的顯示坐標(biāo)
// pImage - 位圖文件首地址
// AutoScale - 是否自適應(yīng)窗口
//返回值: 無(wú)
//備注: 自適應(yīng)窗口用于當(dāng)圖像大于窗口時(shí),并且圖像顯示的起始不能在窗口之外
//=============================================================
void TFT_PutPicture(WIN_HANDLE Handle, short x, short y, unsigned char *pImage, int AutoScale)
{
STR_WINDOW *Window = g_WinList + Handle;
STR_IMAGE Image;
int Ret = 1;
if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0))
return;
Image.ImageBuf = (unsigned char *)TFT_DEPRESS_ADDR;
Ret = TFT_DepressImage(&Image, pImage);
if(Ret == 0)
{
short CurX, CurY;
TFT_GetTextPos(Handle, &CurX, &CurY);
TFT_SetTextPos(Handle, x, y);
TFT_Print(Handle, "不支持的圖像格式");
TFT_SetTextPos(Handle, CurX, CurY);
return;
}
if(AutoScale)
{
if((x >= 0) && (y >= 0))
if((Image.Width > Window->Width - x) || (Image.Height > Window->Height - y))
{
float HScale, VScale;
int ScaleSize;
HScale = (float)Image.Width / (Window->Width - x);
VScale = (float)Image.Height / (Window->Height - y);
if(HScale >= VScale)
{
// Scale the image to fit for the width of screen
ScaleSize = Image.Height / HScale;
TFT_ScaleImage( Image.Width, Image.Height, // Image size before scale
Window->Width - x, ScaleSize, // Image size after scale
(void*)TFT_DEPRESS_ADDR, (void*)TFT_DEPRESS_ADDR, // Replace the image by scaled one
0, 0); // No Reverse
Image.Width = Window->Width - x;
Image.Height = ScaleSize;
}
else
{
// Scale the image to fit for the height of screen
ScaleSize = Image.Width / VScale;
TFT_ScaleImage( Image.Width, Image.Height, // Image size before scale
ScaleSize, Window->Height - y, // Image size after scale
(void*)TFT_DEPRESS_ADDR, (void*)TFT_DEPRESS_ADDR, // Replace the image by scaled one
0, 0); // No Reverse
Image.Width = ScaleSize;
Image.Height = Window->Height - y;
}
}
}
TFT_PutImage(Handle, x, y, &Image);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -