draw.c

来自「ucOS 模拟环境」· C语言 代码 · 共 942 行 · 第 1/2 页

C
942
字号
#include "M_Data.h"
#include "draw.h"
#include "typedef.h"
#include <string.h>
short LcdColor;
unsigned char g_Thread;
DispRam GvramRecord[GRAM_MAX_COUNT];
#define GVRAM1 1
#ifdef PCVER
UB		DispMap[ DISP_BUF_SIZE +10];
static void MD_MakeData(const uchar* buf, uchar* DataBuf);
static void MD_VToHCharater(uchar *Hbuf ,uchar *Vbuf);
extern void UpdateScr(void);
static void MD_MakeDataHZ( const uchar* buf, uchar* DataBuf);
static void MD_DrawVertLine (uint x, uint y0, uint y1, UB color)
{
	uint	offset;
	UB Mask0;
	uint uk;

	if(x>=XDOTS) 				return;
	if(y1>=YDOTS || y0>y1) 	return;

	//	Calculate start position.
	offset = y0 * (uint)SCRW;		//	Need optimal multiply
	offset += (x >> 3);

	Mask0 = (0x80 >> (x & 0x07));
	

	for(uk=y0;uk<=y1;uk++)
	{
		
			if(color==CL_BLACK)
				DispMap[offset] |= Mask0;
			else
				DispMap[offset] &= ~Mask0;
		
		offset += SCRW;
	}
}

static void MD_DrawHorzLine (uint y, uint x0, uint x1, UB color)
{
	INT	i, k, off;
	UB TypeMask[3];

	if(y>=YDOTS) 				return;
	if(x1>=XDOTS || x0>x1) 	return;

	if(x0==0 && x1==XDOTS-1)
	{
		off = (uint)y * SCRW;

		TypeMask[0] = TypeMask[1] = TypeMask[2] = 0xff;
				TypeMask[0] = 0xbd;
				TypeMask[1] = 0xd6;
				TypeMask[2] = 0x6b;
		
		k = 0;
		for (i = 0; i < SCRW; )
		{
			DispMap[off + i++] |= TypeMask[k++];
			if(k==3) k = 0;
		}
	}
	else
	{
		uint	offset;
		uchar Mask0, Mask1;
		uchar byw;

		x1++;                //

		//	Calculate start position.
		offset = (uint)(y * (uint)SCRW);		//	Need optimal multiply
		offset += (x0 >> 3);

		byw = (uchar)((x1 >> 3) - (x0 >> 3));

		Mask0 = (uchar)(~(0xff >> (x0 & 0x07)));


		if(x1 & 0x07)
		{
			Mask1 =(uchar) (0xff >> (x1 & 0x07));
		
		}
		else Mask1 = 0xff;

		if(byw!=0)
		{
			if(color==CL_BLACK)
			{
				DispMap[offset++]	|= ~Mask0;
				while((--byw)!=0) 				
					DispMap[offset++]	= 0xFF;
				if(Mask1!=0xff)
					DispMap[offset++]	|= ~Mask1;
			}
			else 
			{
				DispMap[offset++]	&= Mask0;
				while((--byw)!=0) 				
					DispMap[offset++]	= 0x00;
				if(Mask1!=0xff)
					DispMap[offset++]	&= Mask1;
			}
		}
		else //if(byw==0)
		{
			if(color==CL_BLACK)
			{
				if(Mask1!=0xff)	Mask0 |= Mask1;
				DispMap[offset] |= ~Mask0;
			}
			else
			{
				if(Mask1!=0xff)	Mask0 &= ~Mask1;
				DispMap[offset] &= Mask0;
			}
		}
	}
}
#endif


void MD_Line( uint usStartX, uint usStartY, uint usEndX, uint usEndY, uchar usLineCol, uchar usGvramNo)
{
  INT k;
  uint StartY,StartX,Endy,Endx;
  k = MD_SearchGvram(usGvramNo);
  StartX = GvramRecord[k].startx + usStartX;
  Endy =  GvramRecord[k].starty + usEndY;
  StartY = GvramRecord[k].starty + usStartY;
  Endx = GvramRecord[k].startx + usEndX;
#ifdef PCVER
  if(usStartX == usEndX)
  {
	  MD_DrawVertLine (StartX,StartY,Endy,usLineCol);
  }else if(StartY == Endy)
  {
	 MD_DrawHorzLine(StartY,StartX,Endx,usLineCol);
 }else
	 {
	 return;
 }
#else

	Line( StartX, StartY, Endx, Endy, 0XFFFF, 0,  GVRAM1 );
	
#endif

 
}

//======================================================================
// Function	:void  MD_Square (uint usStartX, uint usStartY, uint usEndX, uint usEndY, uchar usLineCol,uchar GvramNo)
// Parameter:	None
// Return   :	
// Remarks  :	draw a square in a gvram block 
//======================================================================


void  MD_Square (uint usStartX, uint usStartY, uint usEndX, uint usEndY, uchar usLineCol,uchar GvramNo)
{
//#ifndef PCVER
//	Square(  x0,  y0,  x1,  y1,  tile,  0,  GVRAM  );
//#else
	MD_Line(usStartX,usStartY,usStartX,usEndY,usLineCol,GvramNo);
	MD_Line(usStartX,usStartY,usEndX,usStartY,usLineCol,GvramNo);
	MD_Line(usStartX,usEndY,usEndX,usEndY,usLineCol,GvramNo);
	MD_Line(usEndX,usStartY,usEndX,usEndY,usLineCol,GvramNo);
//#endif
}



void MD_AscTextV(UB ucText, UB Gvramno,UB ucFontStyle)
{
  	
	INT  i = 0 ;
	INT  count = 0;
	INT  k,StartX = 0,StartY = 0,EndY,p,Loopy,EndX;
	UB DrawOneText[16];
	UB TempBuf[65];
	UB TempBuf1[32];
	uint  MaskCount;
	UB    TemData1 = 0;
	UB    TempData = 0;
	
	memset(TempBuf,0,sizeof(TempBuf));
	memset(TempBuf1,0,sizeof(TempBuf1));
	
	if((k = MD_SearchGvram(Gvramno)) != -1)
	{
		StartX = GvramRecord[k].startx + GvramRecord[k].curx;
		StartY = GvramRecord[k].starty + GvramRecord[k].cury;
		EndY = GvramRecord[k].endy ;
		EndX = GvramRecord[k].endx ;
		GvramRecord[k].curflag = 0;//
	}
#ifdef PCVER	
	if(MD_GetAscFontData(ucText,TempBuf1) == -1)  return;
	for(i = 0; i<16;i++)
	{
		DrawOneText[i] = TempBuf1[i];
	}
	
	
	if(ucFontStyle == RESERVE)
	{
		for(i = 0; i<16; i++)
		{
			DrawOneText[i]=~DrawOneText[i];
		}
	}
	
	if((StartX & 0x07) == 0)
	{
	
		if(StartX > EndX -8)
		{
			StartY +=  FONTHEIGHT ;
			StartX = GvramRecord[k].startx;
		}
		if(StartY >= EndY)
		{
			return;
		}
		p  = SCRW * StartY + (StartX >>3);
	
	
			for (Loopy = 0; Loopy < FONTHEIGHT; Loopy++)
			{
			
				DispMap[p] = DrawOneText[count];
				count ++;
				p += (SCRW ) ;
			}
		StartX += 	CH_FONTWIDTH ;
	
		GvramRecord[k].curx = StartX - GvramRecord[k].startx;
		GvramRecord[k].cury = StartY - GvramRecord[k].starty;
	}else
	{		
		MaskCount = StartX & 0x07;
	
		if(StartX > EndX -8)
		{
			StartY +=  FONTHEIGHT ;
			StartX = GvramRecord[k].startx;
		}
		if(StartY >= EndY)
		{
			return;
		}
		p  = SCRW * StartY + (StartX >>3);
			for (Loopy = 0; Loopy < FONTHEIGHT; Loopy++)
			{
				
				TempData = DispMap[p];
				DispMap[p]  = 0x00;
				DispMap[p] |= (TempData >>(8- MaskCount))<<(8-MaskCount);
				DispMap[p] |= DrawOneText[count]>>MaskCount;
				p++;
				TempData = DispMap[p];
				DispMap[p] = 0x00;
				DispMap[p] |= DrawOneText[count]<<(8- MaskCount);
				TemData1 = (TempData<<  MaskCount);
				DispMap[p] |= TemData1>>MaskCount;
				count ++;
				p += (SCRW -1) ;
	
			}
	
		StartX += 	CH_FONTWIDTH ;
		GvramRecord[k].curx = StartX - GvramRecord[k].startx;
		GvramRecord[k].cury = StartY - GvramRecord[k].starty;
	}
	 
#else
		TempBuf1[0]= ucText;
		PutStrSjis( StartX , StartY, TempBuf1, 1, 4, 0, 0, 3, 0, GVRAM1 );
		if(ucFontStyle == RESERVE)
		{
			MD_Reverse(GvramRecord[k].curx, GvramRecord[k].cury, GvramRecord[k].curx + CH_FONTWIDTH	,GvramRecord[k].cury + FONTHEIGHT, Gvramno);
		}
		StartX += 	CH_FONTWIDTH;	
		GvramRecord[k].curx = StartX - GvramRecord[k].startx;
		GvramRecord[k].cury = StartY - GvramRecord[k].starty;

#endif
}





void MD_UnicTextV(uint usText, UB GvramNo,UB ucFontStyle)
{
	
	INT   i = 0 ;
	INT   count = 0;
	INT   k,StartX = 0,StartY = 0,EndY,p,Loopy,EndX;
	UB    DrawOneText[32];
	UB    TempBuf[65];
	UB	  TempBuf1[32];
	uint  MaskCount;
	UB    TempData = 0;

	memset(TempBuf, 0, sizeof(TempBuf));
	memset(TempBuf1, 0, sizeof(TempBuf1));

	if((k = MD_SearchGvram(GvramNo)) != -1)
	{
		StartX = GvramRecord[k].startx + GvramRecord[k].curx;
		StartY = GvramRecord[k].starty + GvramRecord[k].cury;
		EndY = GvramRecord[k].endy ;
		EndX = GvramRecord[k].endx ;
		GvramRecord[k].curflag = 0;//
	}
#ifdef PCVER
	if(MD_GetFontData(usText, DrawOneText ) == -1)  return;		//改动
	
	if(ucFontStyle == RESERVE)
	{
		for(i = 0; i<32; i++)
		{
			DrawOneText[i]=~DrawOneText[i];
		}
	}
	
	if((StartX & 0x07) == 0)
	{
		
		p  = SCRW * StartY + (StartX >>3);
		for (Loopy = 0; Loopy < FONTHEIGHT; Loopy++)
		{
		
			DispMap[p] = DrawOneText[count];
			count ++;
			p++;
			DispMap[p] = DrawOneText[count];
			count ++;
			p += (SCRW -1 ) ;
		}
		StartX += 	FONTWIDTH ;
		GvramRecord[k].curx = StartX - GvramRecord[k].startx;
		GvramRecord[k].cury = StartY - GvramRecord[k].starty;
	}else
	{		
			MaskCount = StartX & 0x07;
			p  = SCRW * StartY + (StartX >>3);
			for (Loopy = 0; Loopy < FONTHEIGHT; Loopy++)
			{
				
				TempData = DispMap[p];
				DispMap[p]  = 0x00;
				DispMap[p] |= (TempData >>(8- MaskCount))<<(8-MaskCount);
				DispMap[p] |= DrawOneText[count]>>MaskCount;
				p++;
	
				TempData = DispMap[p];
				DispMap[p] = 0x00;
				DispMap[p] |= (DrawOneText[count]<<(8- MaskCount));
				DispMap[p] |= TempData>> MaskCount;
				count ++;
				DispMap[p] |= (DrawOneText[count]>>MaskCount);
				p++;
				TempData = DispMap[p];
				DispMap[p] = 0x00;
				DispMap[p] |= (DrawOneText[count]<<(8- MaskCount));
				DispMap[p] |= (TempData<<MaskCount)>>MaskCount;
				count++;
				p += (SCRW -2) ;
	
			}
	
		StartX += 	FONTWIDTH ;
		//
		GvramRecord[k].curx = StartX - GvramRecord[k].startx;
		GvramRecord[k].cury = StartY - GvramRecord[k].starty;
	}
#else
		dispdata[0] = usText;
		PutStrGB( StartX , StartY, (B*)dispdata, 2, 4, 0, 0, 3, 0, GVRAM1 );
		if(ucFontStyle == RESERVE)
		{
			MD_Reverse(GvramRecord[k].curx, GvramRecord[k].cury, GvramRecord[k].curx + FONTWIDTH,GvramRecord[k].cury + FONTHEIGHT, GvramNo);
		}
		StartX += 	FONTWIDTH;
		GvramRecord[k].curx = StartX - GvramRecord[k].startx;
		GvramRecord[k].cury = StartY - GvramRecord[k].starty;
		
#endif


}



//======================================================================
// Function	:void MD_Clear(uint usStartX, uint usStartY, uint usEndX, uint usEndY, uchar GvramNo)
// Parameter:	None
// Return   :	
// Remarks  :	clear a rectange block from gvram 
//======================================================================

void MD_Clear(uint usStartX, uint usStartY, uint usEndX, uint usEndY, uchar GvramNo)
{
	uchar color,TempCol,tempcol1;
	int i,k;
	int p;
	int Width ;
	int MaskCountx0,MaskCountx1;	
	uint StartY,StartX,EndX,EndY;
	k = MD_SearchGvram(GvramNo);
	StartX = GvramRecord[k].startx + usStartX;
	StartY = GvramRecord[k].starty + usStartY;
	EndX =	GvramRecord[k].startx + usEndX;
	EndY = GvramRecord[k].starty + usEndY;
#ifdef PCVER
	Width = XDOTS >> 3;
	for(i=0; i < GRAM_MAX_COUNT ; i++)
	{
		if( GvramRecord[i].GvramNo == GvramNo)
		{
			color = GvramRecord[i].col;
			break;
		}
	}
	
	MaskCountx0 = StartX & 0x07;
	MaskCountx1 = EndX & 0x07;
	i = 0;
	p = Width * (StartY) + ((StartX)>>3);

	while( i < (usEndY - usStartY))
	{
		k = 0;
		//
		TempCol = DispMap[p];
		DispMap[p] = 0;
		tempcol1 =(TempCol>>(8-MaskCountx0));
		DispMap[p] |= tempcol1<<(8-MaskCountx0);
		DispMap[p] |= color>>MaskCountx0;
		k++;
		//
		while(k< ((EndX>>3) - (StartX>>3)))
		{
			DispMap[p +k] = color;
			k++;
		}
		//
		TempCol = DispMap[p +k];
		DispMap[p +k] = 0;
		DispMap[p +k] |= (color>>(8-MaskCountx1))<<(8-MaskCountx1);
		tempcol1 =(TempCol<<MaskCountx1);
		DispMap[p +k] |= tempcol1 >>MaskCountx1;
		p += Width ;
		i++;
	}
#else
	Clear( StartX, StartY, EndX, EndY, GVRAM1 );
#endif



//#endif

⌨️ 快捷键说明

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