📄 tft_api.c
字号:
short W, H; if(((Handle < 0) && (Handle >= MAX_WINDOW)) || (Window->Flag == 0)) return 0; TFT_GetWorkBufSize(&W, &H); if((TLx >= W) || (TLy >= H)) return 0; if((TLx == Window->TLx) && (TLy == Window->TLy)) return 0; if(TLx >= 0) { x1 = Window->TLx >= 0 ? Window->TLx : 0; } else { x1 = Window->TLx - TLx >= 0 ? Window->TLx - TLx : 0; } if(TLy >= 0) { y1 = Window->TLy >= 0 ? Window->TLy : 0; } else { y1 = Window->TLy - TLy >= 0 ? Window->TLy - TLy : 0; } x2 = (TLx + Window->Width) < W ? Window->BRx : Window->TLx - TLx + W; y2 = (TLy + Window->Height) < H ? Window->BRy : Window->TLy - TLy + H; Dx1 = x1 - Window->TLx + TLx; Dy1 = y1 - Window->TLy + TLy; Dx2 = x2 + TLx - Window->TLx; Dy2 = y2 + TLy - Window->TLy; TFT_CopyRectToBuffer(TempBuf, x1, y1, x2, y2); if(Cut) { COLOR BGBack = TFT_GetBGColor(Handle); TFT_SetBGColor(Handle, COLOR_BLACK); TFT_ClearWindow(Handle); TFT_SetBGColor(Handle, BGBack); } TFT_CopyBufferToRect(TempBuf, Dx1, Dy1, Dx2, Dy2); Window->TLx = TLx; Window->TLy = TLy; Window->BRx = TLx + Window->Width - 1; Window->BRy = TLy + Window->Height - 1; return 1;}#if 0//=============================================================//语法格式: int TFT_CopyWindow(WIN_HANDLE Handle, short TLx, short TLy)//实现功能: 移动并复制窗口//参数: Handle - 窗口句柄// TLx,TLy - 新位置左上角坐标//返回值: 1: 成功; 0:失败//=============================================================int TFT_CopyWindow(WIN_HANDLE Handle, short TLx, short TLy){ return TFT_MoveWindowEx(Handle, TLx, TLy, 0);}//=============================================================//语法格式: int TFT_MoveWindow(WIN_HANDLE Handle, short TLx, short TLy)//实现功能: 移动窗口//参数: Handle - 窗口句柄// TLx,TLy - 新位置左上角坐标//返回值: 1: 成功; 0:失败//=============================================================int TFT_MoveWindow(WIN_HANDLE Handle, short TLx,short TLy){ return TFT_MoveWindowEx(Handle, TLx, TLy, 1);}#endif//=============================================================//语法格式: int TFT_ResetWindow(WIN_HANDLE Handle, short TLx, short TLy, short BRx, short BRy)//实现功能: 重设窗口//参数: Handle - 窗口句柄// TLx,TLy - 新位置左上角坐标// BRx,BRy - 新位置右下角坐标//返回值: 1: 成功; 0:失败//=============================================================int TFT_ResetWindow(WIN_HANDLE Handle, short TLx, short TLy, short BRx, short BRy){ STR_WINDOW *Window = g_WinList + Handle; short W, H; short TLxSet, TLySet, BRxSet, BRySet; if((Handle < 0) && (Handle >= MAX_WINDOW)) return 0; TFT_GetWorkBufSize(&W, &H); TLxSet = TLx < BRx ? TLx : BRx; if(TLxSet > W) return 0; TLySet = TLy < BRy ? TLy : BRy; if(TLySet > H) return 0; BRxSet = TLx > BRx ? TLx : BRx; if(BRxSet >= W) BRxSet = W - 1; BRySet = TLy >= BRy ? TLy : BRy; if(BRySet > H) BRySet = H - 1; if(((TLxSet < 0) && (BRxSet < 0)) || ((TLySet < 0) && (BRySet < 0))) return 0; Window->TLx = TLxSet; Window->TLy = TLySet; Window->BRx = BRxSet; Window->BRy = BRySet; Window->Width = BRxSet - TLxSet + 1; Window->Height = BRySet - TLySet + 1; return 1;}//=============================================================//语法格式: int TFT_MoveWindowBorder(WIN_HANDLE Handle, short TLx, short TLy)//实现功能: 移动窗口边框//参数: Handle - 窗口句柄// TLx,TLy - 新位置左上角坐标//返回值: 1: 成功; 0:失败//=============================================================int TFT_MoveWindowBorder(WIN_HANDLE Handle, short TLx, short TLy){ STR_WINDOW *Window = g_WinList + Handle; return TFT_ResetWindow(Handle, TLx, TLy, TLx + Window->Width - 1, TLy + Window->Height - 1);}//=============================================================//语法格式: void TFT_ClearWindow(STR_WINDOW *Window)//实现功能: 工作窗口清屏//参数: Window - 工作窗口指针//返回值: 无//=============================================================void TFT_ClearWindow(WIN_HANDLE Handle){ STR_WINDOW *Window = g_WinList + Handle; short W, H; short i, j; unsigned short *p_Buf; if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0)) return; TFT_GetWorkBufSize(&W, &H); for(i = (Window->TLy >= 0 ? Window->TLy : 0); i <= Window->BRy; i++) { p_Buf = TFT_SelWorkBuf(-1) + i * W; for(j=(Window->TLx >= 0 ? Window->TLx : 0); j <= Window->BRx; j++) { *(p_Buf+j) = Window->BGColor; } } Window->CurTextX = Window->CurTextY = 0; // 窗口初始文本绘制坐标}//=============================================================//语法格式: void TFT_SetTransparency(STR_WINDOW *Window, unsigned short TransparencySet);//实现功能: 设置新显示内容的透明度//参数: Window - 工作窗口指针// TransparencySet - 透明度参数,范围0~100(0为不透明,100为全透明)//返回值: 无//=============================================================void TFT_SetTransparency(WIN_HANDLE Handle, unsigned short TransparencySet){ STR_WINDOW *Window = g_WinList + Handle; if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0)) return; Window ->Transparency = TransparencySet * 128 / 100; // 内部采用128级,以减少计算量 if(Window ->Transparency > 128) Window ->Transparency = 128;}//=============================================================//语法格式: unsigned short TFT_GetTransparency(STR_WINDOW *Window);//实现功能: 获取当前设定的透明度//参数: Window - 工作窗口指针//返回值: 透明度参数,范围0~100(0为不透明,100为全透明)//=============================================================unsigned short TFT_GetTransparency(WIN_HANDLE Handle){ STR_WINDOW *Window = g_WinList + Handle; if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0)) return 0; return (Window ->Transparency * 100)>>7;}//=============================================================//语法格式: void TFT_SetColor(STR_WINDOW *Window, unsigned short ColorSet);//实现功能: 设置显示内容的前景色//参数: Window - 工作窗口指针// ColorSet - 颜色代码,以16位存储,格式为RRRRR-GGGGGG-BBBBB//返回值: 无//=============================================================void TFT_SetColor(WIN_HANDLE Handle, unsigned short ColorSet){ STR_WINDOW *Window = g_WinList + Handle; if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0)) return; Window->FGColor = ColorSet;}//=============================================================//语法格式: unsigned short TFT_GetColor(STR_WINDOW *Window);//实现功能: 获取当前设定的前景色//参数: Window - 工作窗口指针//返回值: 颜色代码,以16位存储,格式为RRRRR-GGGGGG-BBBBB//=============================================================unsigned short TFT_GetColor(WIN_HANDLE Handle){ STR_WINDOW *Window = g_WinList + Handle; if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0)) return 0; return Window->FGColor;}//=============================================================//语法格式: unsigned short TFT_PickColor(STR_WINDOW *Window, short x, short y);//实现功能: 获取工作区内指定坐标像素的颜色//参数: Window - 工作窗口指针// x - 相对于工作区的x坐标// y - 相对于工作区的y坐标//返回值: 颜色代码,以16位存储,格式为RRRRR-GGGGGG-BBBBB//=============================================================unsigned short TFT_PickColor(WIN_HANDLE Handle, short x, short y){ STR_WINDOW *Window = g_WinList + Handle; short AbsX, AbsY; short W, H; if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0)) return 0; TFT_GetWorkBufSize(&W, &H); AbsX = Window->TLx + x; AbsY = Window->TLy + y; if((AbsX<0)||(AbsY<0)||(AbsX>=W)||(AbsY>=H)) return 0x0000; return *(TFT_SelWorkBuf(-1) + AbsY * W + AbsX);}//=============================================================//语法格式: unsigned short TFT_PickColorAbsolute(STR_WINDOW *Window, short AbsX, short AbsY);//实现功能: 获取显示缓冲区中指定坐标像素的颜色//参数: Window - 工作窗口指针// AbsX - 相对于屏幕的x坐标// AbsY - 相对于屏幕的y坐标//返回值: 颜色代码,以16位存储,格式为RRRRR-GGGGGG-BBBBB//=============================================================unsigned short TFT_PickColorAbsolute(WIN_HANDLE Handle, short AbsX, short AbsY){ STR_WINDOW *Window = g_WinList + Handle; short W, H; if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0)) return 0; TFT_GetWorkBufSize(&W, &H); if((AbsX<0)||(AbsY<0)||(AbsX>=W)||(AbsY>=H)) return 0x0000; return *(TFT_SelWorkBuf(-1) + AbsY * W + AbsX);}//=============================================================//语法格式: void TFT_SetBGColor(STR_WINDOW *Window, unsigned short ColorSet);//实现功能: 设定显示背景色(对工作区、文本有效)//参数: Window - 工作窗口指针// ColorSet - 背景颜色代码,以16位存储,格式为RRRRR-GGGGGG-BBBBB// 当ColorSet=0x0000(COLOR_BLACK)时,背景色无效//返回值: 无//=============================================================void TFT_SetBGColor(WIN_HANDLE Handle, unsigned short ColorSet){ STR_WINDOW *Window = g_WinList + Handle; if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0)) return; Window->BGColor = ColorSet;}//=============================================================//语法格式: unsigned short TFT_GetBGColor(STR_WINDOW *Window);//实现功能: 获取当前设定的背景色//参数: Window - 工作窗口指针//返回值: 背景颜色代码,以16位存储,格式为RRRRR-GGGGGG-BBBBB//=============================================================unsigned short TFT_GetBGColor(WIN_HANDLE Handle){ STR_WINDOW *Window = g_WinList + Handle; if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0)) return 0; return Window->BGColor;}//=============================================================//语法格式: void TFT_PutPixelAbsolute(STR_WINDOW *Window, short AbsX, short AbsY);//实现功能: 在显示缓冲区的指定位置画点//参数: Window - 工作窗口指针// AbsX - 相对于屏幕的x坐标// AbsY - 相对于屏幕的y坐标//返回值: 无//=============================================================void TFT_PutPixelAbsolute(WIN_HANDLE Handle, short AbsX, short AbsY){ STR_WINDOW *Window = g_WinList + Handle; unsigned short *pBuf; short W, H; if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0)) return; TFT_GetWorkBufSize(&W, &H); if((AbsX>=0) && (AbsY>=0) && (AbsX < W)&&(AbsY < H)) { pBuf = TFT_SelWorkBuf(-1) + AbsY * W + AbsX; if(Window->Transparency==0) *pBuf = Window->FGColor; else *pBuf = TFT_CalcTransparent(Window, *pBuf, Window->FGColor); }}//=============================================================//语法格式: void TFT_PutPixel(STR_WINDOW *Window, short x, short y);//实现功能: 在工作区的指定位置画点//参数: Window - 工作窗口指针// x - 相对于工作区的x坐标// y - 相对于工作区的y坐标//返回值: 无//=============================================================void TFT_PutPixel(WIN_HANDLE Handle, short x, short y){ STR_WINDOW *Window = g_WinList + Handle; short AbsX, AbsY; if((Handle < 0) || (Handle >= MAX_WINDOW) || (Window->Flag == 0)) return; AbsX = Window->TLx+x; AbsY = Window->TLy+y; if(AbsX<Window->TLx || AbsX>Window->BRx)return; if(AbsY<Window->TLy || AbsY>Window->BRy)return; TFT_PutPixelAbsolute(Handle, AbsX, AbsY);}//=============================================================//语法格式: void TFT_PutPixelLine(STR_WINDOW *Window, short line, COLOR ColorTab[])//实现功能: 在工作区中根据颜色表绘制行//参数: Window - 工作窗口指针// x - 逻辑起始x坐标// y - 逻辑行// len - 绘制长度// ColorTab - 颜色表//返回值: 无//=============================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -