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

📄 gui.c

📁 PDA程序开发PDA程序开发PDA程序开发PDA程序开发PDA程序开发PDA程序开发PDA程序开发PDA程序开发
💻 C
📖 第 1 页 / 共 2 页
字号:
/*========================================================================
 *
 *  版权所有 (C) 2000-2001 吴柏建. All Rights Reserved.
 *
 *  文件:       gui.c
 *  内容:		PSDE_DEMO_PDA处理显示和消息的函数。
 *	作者:			吴柏建。
 *	制作日期:		2000.8.6-2001.10.6
 *	修改日期:		2001..
 *
 *========================================================================*/
#include "pda.h"

/*定义队列中容纳的消息数量*/
#define MSG_QUEUE_SIZE 128
/*定义全局的消息队列*/
PDAMSG MsgQueue[MSG_QUEUE_SIZE];
/*定义全局消息队列的写指针*/
short MsgWrite=0;
/*定义全局消息队列的读指针*/
short MsgRead=0;

/*======================================================================
---向全局消息队列MsgQueue中发送消息----SendMsg---
======================================================================*/
void SendMsg(PDAMSG *msg)
{
	short i=(1+MsgWrite)%MSG_QUEUE_SIZE;
	if(msg->type!=MSG_NULL)
	{
		MsgQueue[MsgWrite]=*msg;
		MsgWrite=i;
		if(i==MsgRead)MsgRead=(++MsgRead)%MSG_QUEUE_SIZE;
	}
}
/*======================================================================
---转变TouchPanel坐标为LCD坐标消息和ICON消息----TranslateMsg---
======================================================================*/
void TranslateMsg(PDAMSG *pMsg)
{
	short i;
	RECT rc;

	if(pMsg->type!=MSG_PEN)return;
	if((pMsg->y<18||pMsg->y>178)&&pMsg->x>=2&&pMsg->x<162)
	{
		i=((pMsg->x-2)*10/160);
		rc.left=i*16+2;
		rc.right=16+rc.left;
		if(pMsg->y<18)
		{
			rc.top=1;
			rc.bottom=17;
		}
		else
		{
			i+=10;
			rc.top=179;
			rc.bottom=195;
		}
		while(pMsg->type==MSG_PEN)
		{
			if(!pMsg->PenStatus)
			{
				//ICON消息值为80~99。
				if(CheckPointInRect(pMsg->x,pMsg->y,&rc))pMsg->type=i+80;
				else pMsg->type=MSG_NULL;
				return;
			}
			GetMsg(pMsg);
		}
	}
	pMsg->type=MSG_LCD;
	pMsg->x-=2;
	pMsg->y-=18;
	if(pMsg->x<0||pMsg->x>=160||pMsg->y<0||pMsg->y>=160)pMsg->type=MSG_NULL;
}
/*======================================================================
---从全局消息队列MsgQueue中读一条消息----GetMsg---
======================================================================*/
void GetMsg(PDAMSG *msg)
{
	msg->type=MSG_NULL;
	while(MsgRead==MsgWrite)
	{
		#ifdef _PSDE_
		PSDE_CpuHalt();
		#else
		/*PDA使CPU halt的指令。*/
		#endif
	}
	*msg=MsgQueue[MsgRead];
	MsgRead=((++MsgRead)%MSG_QUEUE_SIZE);
}


#define LCD_WIDTH     160
#define LCD_HIGH      160
#define LCD_WIDTH_BYTE 80/* 80Bytes x 2Bits = 160Dots */

extern unsigned char DisBuffer[];
extern unsigned char *RomAddress;

/*======================================================================
---在LCD中以某一颜色显示一点----DispDot---
======================================================================*/
void DispDot(short x,short y,unsigned char c)
{
	unsigned char *s;
	if(c>0x0f)return;
	s=&DisBuffer[y*LCD_WIDTH_BYTE+(x>>1)];
	*s=(x&1)?(*s&0xf0)|(c&0x0f):(*s&0x0f)|(c<<4);
}
void ReverseDot(short x,short y)
{
	unsigned char *s=&DisBuffer[y*LCD_WIDTH_BYTE+(x>>1)];
	*s=(x&1)?(*s&0xf0)|(~*s&0x0f):(*s&0x0f)|(~*s&0xf0);
}
/*======================================================================
---在LCD中以图象数据s显示一幅图象----DispImage---
---画点方式效率低下,建议用户用逻辑和移位操作优化数据拷贝---
======================================================================*/
void DispImage(short x,short y,short w,short h,unsigned char *s)
{
	short i,j;
	if(w&1)w++;
	for(j=y;j<h+y;j++)
	{
		for(i=x;i<x+w;i+=2)
		{
			DispDot(i,j,*s>>4);
			DispDot(i+1,j,*s&0x0f);
			s++;
		}
	}
}
void DispImageGray(short x,short y,short w,short h,unsigned char *s)
{
	short i,j,k,f;
	unsigned char c;
	if(w&1)w++;
	for(j=y,k=0;j<h+y;j++,k=!k)
	{
		for(i=x,f=k;i<x+w;i+=2,f=!f)
		{
			c=(*s>>4);
			DispDot(i,j,f?c:COLOR1+c);
			c=(*s&0x0f);
			DispDot(i+1,j,f?COLOR1+c:c);
			s++;
		}
	}
}
void DispBar(short x,short y,short w,short h,unsigned char c)
{
	short i,j;
	for(j=y;j<y+h;j++)for(i=x;i<x+w;i++)DispDot(i,j,c);
}
void DispReverse(short x,short y,short w,short h)
{
	short i,j;
	for(j=y;j<y+h;j++)for(i=x;i<x+w;i++)ReverseDot(i,j);
}
void DrawBar(PDARECT *rc,unsigned char c)
{
	DispBar(rc->left,rc->top,(short)(rc->right-rc->left+1),(short)(rc->bottom-rc->top+1),c);
}
void ReverseBar(PDARECT *rc)
{
	DispReverse(rc->left,rc->top,(short)(rc->right-rc->left+1),(short)(rc->bottom-rc->top+1));
}



void DrawLineX(short x,short y,short w,unsigned char c)
{
	short i;
	for(i=x;i<x+w;i++)DispDot(i,y,c);
}
void ReverseLineX(short x,short y,short w)
{
	short i;
	for(i=x;i<x+w;i++)ReverseDot(i,y);
}
void DrawDotLineX(short x,short y,short w,short dot,unsigned char c)
{
	short i,f;
	for(i=x,f=0;i<x+w;i++,f++)
	{
		if(f>=dot)f=-dot;
		if(f>=0)DispDot(i,y,c);
	}
}
void ReverseDotLineX(short x,short y,short w,short dot)
{
	short i,f;
	for(i=x,f=0;i<x+w;i++,f++)
	{
		if(f>=dot)f=-dot;
		if(f>=0)ReverseDot(i,y);
	}
}
void DrawLineY(short x,short y,short h,unsigned char c)
{
	short i;
	for(i=y;i<y+h;i++)DispDot(x,i,c);
}
void ReverseLineY(short x,short y,short h)
{
	short i;
	for(i=y;i<y+h;i++)ReverseDot(x,i);
}
void DrawDotLineY(short x,short y,short h,short dot,unsigned char c)
{
	short i,f;
	for(i=y,f=-dot;i<y+h;i++,f++)
	{
		if(f>=dot)f=-dot;
		if(f>=0)DispDot(x,i,c);
	}
}
void ReverseDotLineY(short x,short y,short h,short dot)
{
	short i,f;
	for(i=y,f=-dot;i<y+h;i++,f++)
	{
		if(f>=dot)f=-dot;
		if(f>=0)ReverseDot(x,i);
	}
}
void DrawRect(PDARECT *rc,unsigned char c)
{
	short w,h;
	w=rc->right-rc->left+1;
	h=rc->bottom-rc->top+1;
	DrawLineX(rc->left,rc->top,w,c);
	DrawLineY(rc->left,rc->top,h,c);
	DrawLineY(rc->right,rc->top,h,c);
	DrawLineX(rc->left,rc->bottom,w,c);
}
void ReverseRect(PDARECT *rc)
{
	short w,h;
	w=rc->right-rc->left+1;
	h=rc->bottom-rc->top-1;
	ReverseLineX(rc->left,rc->top,w);
	ReverseLineY(rc->left,(short)(rc->top+1),h);
	ReverseLineY(rc->right,(short)(rc->top+1),h);
	ReverseLineX(rc->left,rc->bottom,w);
}
void DrawDotRect(PDARECT *rc,short dot,unsigned char c)
{
	static short y,w,h;
	w=rc->right-rc->left+1;
	h=rc->bottom-rc->top-1;
	y=rc->top+1;
	DrawDotLineX(rc->left,rc->top,w,dot,c);
	DrawDotLineY(rc->left,y,h,dot,c);
	DrawDotLineY(rc->right,y,h,dot,c);
	DrawDotLineX(rc->left,rc->bottom,w,dot,c);
}
void ReverseDotRect(PDARECT *rc,short dot)
{
	short y,w,h;
	w=rc->right-rc->left+1;
	h=rc->bottom-rc->top-1;
	y=rc->top+1;
	ReverseDotLineX(rc->left,rc->top,w,dot);
	ReverseDotLineY(rc->left,y,h,dot);
	ReverseDotLineY(rc->right,y,h,dot);
	ReverseDotLineX(rc->left,rc->bottom,w,dot);
}
void DrawLine(short x1,short y1,short x2,short y2,unsigned char c)
{
	short m,n,dx,dy,x_inc,y_inc,i,error,offset;

	error=0;
	offset=y1*LCD_WIDTH+x1;
	dx=x2-x1;
	dy=y2-y1;

	if(dx>=0)x_inc=1;
	else
	{
		x_inc=-1;
		dx=-dx;
	}
	if(dy>=0)y_inc=LCD_WIDTH;
	else
	{
		y_inc=-LCD_WIDTH;
		dy=-dy;
	}
	m=(dx>>1);n=(dy>>1);
	if(dx>dy)
	{
		for(i=0;i<=dx;i++)
		{
			DispDot((short)(offset%LCD_WIDTH),(short)(offset/LCD_WIDTH),c);
			error+=dy;
			if(error>m)
			{
				error-=dx;
				offset+=y_inc;
			}
			offset+=x_inc;
		}
	}
	else
	{
		for(i=0;i<=dy;i++)
		{
			DispDot((short)(offset%LCD_WIDTH),(short)(offset/LCD_WIDTH),c);
			error+=dx;
			if(error>n)
			{
				error-=dy;
				offset+=x_inc;
			}
			offset+=y_inc;
		}
	}
}
void ReverseLine(short x1,short y1,short x2,short y2)
{
	short m,n,dx,dy,x_inc,y_inc,i,error,offset;

	error=0;
	offset=y1*LCD_WIDTH+x1;
	dx=x2-x1;
	dy=y2-y1;

	if(dx>=0)x_inc=1;
	else
	{
		x_inc=-1;
		dx=-dx;
	}
	if(dy>=0)y_inc=LCD_WIDTH;
	else
	{
		y_inc=-LCD_WIDTH;
		dy=-dy;
	}
	m=(dx>>1);n=(dy>>1);
	if(dx>dy)
	{
		for(i=0;i<=dx;i++)
		{
			ReverseDot((short)(offset%LCD_WIDTH),(short)(offset/LCD_WIDTH));
			error+=dy;
			if(error>m)
			{
				error-=dx;
				offset+=y_inc;
			}
			offset+=x_inc;
		}
	}
	else
	{
		for(i=0;i<=dy;i++)
		{
			ReverseDot((short)(offset%LCD_WIDTH),(short)(offset/LCD_WIDTH));
			error+=dx;
			if(error>n)
			{
				error-=dy;
				offset+=x_inc;
			}
			offset+=y_inc;
		}
	}
}
short CheckPointInRect(short x,short y,PDARECT *pRc)
{
	if(x>=pRc->left&&x<=pRc->right&&y>=pRc->top&&y<=pRc->bottom)return 1;

⌨️ 快捷键说明

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