?? gui.c
字號:
/*========================================================================
*
* 版權(quán)所有 (C) 2000-2001 吳柏建. All Rights Reserved.
*
* 文件: gui.c
* 內(nèi)容: PSDE_DEMO_PDA處理顯示和消息的函數(shù)。
* 作者: 吳柏建。
* 制作日期: 2000.8.6-2001.10.6
* 修改日期: 2001..
*
*========================================================================*/
#include "pda.h"
/*定義隊(duì)列中容納的消息數(shù)量*/
#define MSG_QUEUE_SIZE 128
/*定義全局的消息隊(duì)列*/
PDAMSG MsgQueue[MSG_QUEUE_SIZE];
/*定義全局消息隊(duì)列的寫指針*/
short MsgWrite=0;
/*定義全局消息隊(duì)列的讀指針*/
short MsgRead=0;
/*======================================================================
---向全局消息隊(duì)列MsgQueue中發(fā)送消息----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;
}
}
/*======================================================================
---轉(zhuǎn)變TouchPanel坐標(biāo)為LCD坐標(biāo)消息和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;
}
/*======================================================================
---從全局消息隊(duì)列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中以某一顏色顯示一點(diǎn)----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中以圖象數(shù)據(jù)s顯示一幅圖象----DispImage---
---畫點(diǎn)方式效率低下,建議用戶用邏輯和移位操作優(yōu)化數(shù)據(jù)拷貝---
======================================================================*/
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;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -