⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tft_api.c

📁 Taiwan sunplus develop spce3200, it is a test program ----- testboard source code
💻 C
📖 第 1 页 / 共 2 页
字号:
	if(Mode == PAINT_SOLID)									// Solid circle
	{
		while(dy <= dx)
		{
			if(dx > ref)
				TFT_Line(x + ref + 1, y + dy, x + dx, y + dy);

			if(x >= ref + 1 && dx > ref)
			{
				if(x < dx)
					Temp = 0;
				else
					Temp = x - dx;
				TFT_Line(Temp, y + dy, x - ref - 1, y + dy);
			}
			
			if(y >= dy && dx > ref)
				TFT_Line(x + ref + 1, y - dy, x + dx, y - dy);
			if(x >= ref + 1 && y >= dy && dx > ref)
			{
				if(x < dx)
					Temp = 0;
				else
					Temp = x - dx;
				TFT_Line(Temp, y - dy, x - ref - 1, y - dy);
			}

			if(dy != dx || dx == ref)
			{
				if(y < dx)
					Temp = 0;
				else
					Temp = y - dx;
				TFT_Line(x + dy, Temp, x + dy, y + dx);
			}

			if(x >= dy && (dy != dx || dy == ref))
			{
				if(y < dx)
					Temp = 0;
				else
					Temp = y - dx;
				TFT_Line(x - dy, Temp, x - dy, y + dx);
			}			
			dy++;
			if((r*r-dy*dy)<=(dx-1)*dx)
				dx--;
		}

		TFT_Line(x + ref + 1, y, x + r, y);

		if(x >= ref + 1)
		{
			if(x < r)
				Temp = 0;
			else
				Temp = x - r;
			TFT_Line(Temp, y, x - ref - 1, y);
		}

		if(y < r)
			Temp = 0;
		else
			Temp = y - r;
		TFT_Line(x, Temp, x, y + r);
	}
	else													// Hollow circle
	{
		while(dy <= dx)
		{
			TFT_PutPixel(x + dx, y + dy);
			TFT_PutPixel(x - dx, y + dy);
			TFT_PutPixel(x + dx, y - dy);
			TFT_PutPixel(x - dx, y - dy);
			if(dx != dy)
			{
				TFT_PutPixel(x + dy, y + dx);
				TFT_PutPixel(x + dy, y - dx);
				TFT_PutPixel(x - dy, y + dx);
				TFT_PutPixel(x - dy, y - dx);
			}
			dy++;
			if((r*r-dy*dy)<=(dx-1)*dx)
				dx--;
		}
		TFT_PutPixel(x + r, y);
		TFT_PutPixel(x - r, y);
		TFT_PutPixel(x, y + r);
		TFT_PutPixel(x, y - r);
	}	
}

//=============================================================================
// Prototype:		void TFT_Rectangle(unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned Mode);
// Description:		Draw a rectangle in window.
// Arguments:		
//					x1 - Relative x-coordinate of the top left corner of a rectangle
//					y1 - Relative y-coordinate of the top left corner of a rectangle
//					x2 - Relative x-coordinate of the bottom right corner of a rectangle
//					y2 - Relative y-coordinate of the bottom right corner of a rectangle
//					Mode -  0(PAINT_HOLLOW): hollow rectangle
//							1(PAINT_SOLID): solid rectangle
// Return Value:	
//					None
//=============================================================================
void TFT_Rectangle(unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned Mode)
{
	int i;
	
	if(x1>x2)
	{
		i = x1;
		x1 = x2;
		x2 = i;
	}
	if(y1>y2)
	{
		i = y1;
		y1 = y2;
		y2 = i;
	}
	
	if(Mode == PAINT_SOLID)									// Solid rectangle
	{
		for(i=y1; i<=y2; i++)
		{
			TFT_Line(x1, i, x2, i);
		}
	}
	else													// Hollow rectangle
	{
		TFT_Line(x1, y1, x2, y1);
		TFT_Line(x1, y2, x2, y2);
		TFT_Line(x1, y1+1, x1, y2-1);
		TFT_Line(x2, y1+1, x2, y2-1);
	}
}

//=============================================================================
// Prototype:		void TFT_PutImage(short x, short y, STR_IMAGE *pImage);
// Description:		Display a bitmap in window.
// Arguments:		
//					x - Relative x-coordinate of the top left corner of a bitmap
//					y - Relative y-coordinate of the top left corner of a bitmap
//					pImage - Structure address in which bitmap info is stored
// Return Value:	
//					None
//=============================================================================
void TFT_PutImage(short x, short y, STR_IMAGE *pImage)
{
	short ScrSx, ScrSy, ScrEx, ScrEy;
	short ImgSx, ImgSy, ImgEx, ImgEy;
	short i, j;
	unsigned short *pImgBuf, *pDispBuf;
	
	ScrSx = (x<0) ? Window_TLx : Window_TLx + x;			// Calculate the actual display area
	if(ScrSx<0) ScrSx = 0;
	if(ScrSx>Window_BRx || ScrSx>=TFT_WIDTH) return;
	ImgSx = ScrSx - Window_TLx - x;
	
	ScrSy = (y<0) ? Window_TLy : Window_TLy + y;
	if(ScrSy<0) ScrSy = 0;
	if(ScrSy>Window_BRy || ScrSx>=TFT_HEIGHT) return;
	ImgSy = ScrSy - Window_TLy - y;
	
	ScrEx = Window_TLx + x + pImage->Width - 1;
	if(ScrEx > Window_BRx) ScrEx = Window_BRx;
	if(ScrEx >= TFT_WIDTH) ScrEx = TFT_WIDTH - 1;
	if(ScrEx<0 || ScrEx<Window_TLx) return;
	ImgEx = ScrEx - Window_TLx - x;
	
	ScrEy = Window_TLy + y + pImage->Height - 1;
	if(ScrEy > Window_BRy) ScrEy = Window_BRy;
	if(ScrEy >= TFT_HEIGHT) ScrEy = TFT_HEIGHT - 1;
	if(ScrEy<0 || ScrEy<Window_TLy) return;
	ImgEy = ScrEy - Window_TLy - y;

	if(Transparency==0)										// If transparency is 0, the bitmap will be displayed directly
	{
		for(i=ImgSy; i<=ImgEy; i++)
		{
			pImgBuf = (unsigned short*)pImage->ImageBuf + i * pImage->Width;
			pDispBuf = pTFT_WorkBuf + ScrSy * TFT_WIDTH + ScrSx;
			for(j=ImgSx; j<=ImgEx; j++)
			{
				*(pDispBuf++) = *(pImgBuf+j);
			}
			ScrSy++;
		}
	}
	else													// Otherwise, the bitmap will be displayed after color blending calculation
	{
		for(i=ImgSy; i<=ImgEy; i++)
		{
			pImgBuf = (unsigned short*)pImage->ImageBuf + i * pImage->Width;
			pDispBuf = pTFT_WorkBuf + ScrSy * TFT_WIDTH + ScrSx;
			for(j=ImgSx; j<=ImgEx; j++)
			{
				*pDispBuf = TFT_CalcTransparent(*pDispBuf, *(pImgBuf+j));
				pDispBuf++;
			}
			ScrSy++;
		}
	}
}

//=============================================================================
// Prototype:		void TFT_SetTextPos(short x, short y);
// Description:		Set text position for displaying in window.
// Arguments:		
//					x - Relative x-coordinate of the top left corner of text
//					y - Relative y-coordinate of the top left corner of text
// Return Value:	
//					None
//=============================================================================
void TFT_SetTextPos(short x, short y)
{
	CurTextx = x;
	CurTexty = y;
}

//=============================================================================
// Prototype:		void TFT_GetTextPos(short *x, short *y);
// Description:		Get the position of text to be displayed in window.
// Arguments:		
//					x - Relative x-coordinate of the top left corner of text
//					y - Relative y-coordinate of the top left corner of text
// Return Value:	
//					None
//=============================================================================
void TFT_GetTextPos(short *x, short *y)
{
	*x = CurTextx;
	*y = CurTexty;
}

//=============================================================================
// Prototype:		void TFT_SetChineseFont(short FontType);
// Description:		Set current Chinese font.
// Arguments:		FontType - Font number (0~n)
// Return Value:	None
//=============================================================================
void TFT_SetChineseFont(short FontType)
{
	gChineseFontType = FontType;
	TFT_CallBack_UpdateFont();
}

//=============================================================================
// Prototype:		short TFT_GetChineseFont(STR_FONT *FontInfo);
// Description:		Get information of current Chinese font.
// Arguments:		FontInfo - Address of font info structure 
// Return Value:	Font number
//=============================================================================
short TFT_GetChineseFont(STR_FONT *FontInfo)
{
	FontInfo->CharWidth = gChineseFont.CharWidth;
	FontInfo->CharHeight = gChineseFont.CharHeight;
	FontInfo->FontBuf = gChineseFont.FontBuf;
	return gChineseFontType;
}

//=============================================================================
// Prototype:		void TFT_SetAsciiFont(short FontType);
// Description:		Set current ASCII font.
// Arguments:		FontType - Font number (0~n)
// Return Value:	None
//=============================================================================
void TFT_SetAsciiFont(short FontType)
{
	gAsciiFontType = FontType;
	TFT_CallBack_UpdateFont();
}

//=============================================================================
// Prototype:		short TFT_GetAsciiFont(STR_FONT *FontInfo);
// Description:		Get information of current ASCII font.
// Arguments:		FontInfo - Address of font info structure
// Return Value:	Font number
//=============================================================================
short TFT_GetAsciiFont(STR_FONT *FontInfo)
{
	FontInfo->CharWidth = gAsciiFont.CharWidth;
	FontInfo->CharHeight = gAsciiFont.CharHeight;
	FontInfo->FontBuf = gAsciiFont.FontBuf;
	return gAsciiFontType;
}

//=============================================================================
// Prototype:		void TFT_PutChar(unsigned short CharCode);
// Description:		Display a character or Chinese character.
// Arguments:		CharCode - Character code
// Return Value:	None
//=============================================================================
void TFT_PutChar(unsigned short CharCode)
{
	STR_FONT Font_Char;
	short i, j, Temp;
	unsigned short *pDispBuf;
	unsigned char *pCharBuf;
	unsigned char Mask;
	
	TFT_CallBack_GetCharBuf(CharCode, &Font_Char);			// Get dot matrix data
	
	for(i=0; i<Font_Char.CharHeight; i++)
	{
		Temp = Window_TLy+CurTexty+i;
		if(CurTexty+i<0 || Temp<0 || Temp>Window_BRy || Temp>=TFT_HEIGHT)
			continue;
		pDispBuf = pTFT_WorkBuf + Temp * TFT_WIDTH + Window_TLx + CurTextx;
		pCharBuf = Font_Char.FontBuf + i * ((Font_Char.CharWidth+7)>>3);
		Mask = 0x80;
		
		for(j=0; j<Font_Char.CharWidth; j++)
		{
			Temp = Window_TLx + CurTextx + j;
			if(CurTextx+j>=0 && Temp>=0 && Temp<=Window_BRx && Temp<TFT_WIDTH)
			{
				if(*pCharBuf & Mask)
				{
					if(Transparency==0)
						*(pDispBuf+j) = Color;
					else
						*(pDispBuf+j) = TFT_CalcTransparent(*(pDispBuf+j), Color);
				}
				else if(BGColor!=COLOR_BLACK)
				{
					if(Transparency==0)
						*(pDispBuf+j) = BGColor;
					else
						*(pDispBuf+j) = TFT_CalcTransparent(*(pDispBuf+j), BGColor);
				}
			}
			Mask >>= 1;
			if(Mask==0x00)
			{
				Mask = 0x80;
				pCharBuf++;
			}
		}
	}
}

//=============================================================================
// Prototype:		void TFT_Print(char *CharBuf);
// Description:		Display a character string.
// Arguments:		CharBuf - Start address of a character string
// Return Value:	None
//=============================================================================
void TFT_Print(char *CharBuf)
{
	unsigned char *pCharBuf = (unsigned char *)CharBuf;
	unsigned short CharCode;
	
	while((CharCode = *pCharBuf++)!='\0')
	{
		if(CharCode>=0x80)									// Chinese character
		{
			if(CurTextx+Window_TLx+gChineseFont.CharWidth>Window_BRx)
			{
				CurTextx = 0;
				CurTexty += gChineseFont.CharHeight;
				if(CurTexty>Window_BRy)break;
			}
			CharCode |= *(pCharBuf++) << 8;
			TFT_PutChar(CharCode);
			CurTextx += gChineseFont.CharWidth;
		}
		else if(CharCode==0x0D)								// Enter
		{
			CurTextx = 0;
			CurTexty += gChineseFont.CharHeight;
			if(CurTexty>Window_BRy) break;
			if(*pCharBuf==0x0A) pCharBuf++;
		}
		else if(CharCode==0x0A)								// Enter
		{
			CurTextx = 0;
			CurTexty += gChineseFont.CharHeight;
			if(CurTexty>Window_BRy) break;
			if(*pCharBuf==0x0D) pCharBuf++;
		}
		else												// Character
		{
			if(CurTextx+Window_TLx+gAsciiFont.CharWidth>Window_BRx)
			{
				CurTextx = 0;
				CurTexty += gChineseFont.CharHeight;
				if(CurTexty>Window_BRy) break;
			}
			TFT_PutChar(CharCode);
			CurTextx += gAsciiFont.CharWidth;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -