📄 gui.c
字号:
/*========================================================================
*
* 版权所有 (C) 2000-2001 吴柏建. All Rights Reserved.
*
* 文件: gui.c
* 内容: PSDE_DEMO_ED处理显示和消息的函数。
* 作者: 吴柏建。
* 制作日期: 2000.8.6-2001.8.6
* 修改日期: 2001..
*
*========================================================================*/
#include "pda.h"
/*定义队列中容纳的消息数量*/
#define MSG_QUEUE_SIZE 32
/*定义全局的消息队列*/
PDAMSG MsgQueue[MSG_QUEUE_SIZE];
/*定义全局消息队列的写指针*/
int MsgWrite=0;
/*定义全局消息队列的读指针*/
int MsgRead=0;
/*======================================================================
---向全局消息队列MsgQueue中发送消息----SendMsg---
======================================================================*/
void SendMsg(PDAMSG *msg)
{
if(msg->type!=MSG_NULL)
{
MsgQueue[MsgWrite]=*msg;
MsgWrite=((++MsgWrite)%MSG_QUEUE_SIZE);
}
}
/*======================================================================
---从全局消息队列MsgQueue中读一条消息----GetMsg---
======================================================================*/
short GetMsg(PDAMSG *msg)
{
msg->type=MSG_NULL;
if(MsgRead!=MsgWrite)
{
*msg=MsgQueue[MsgRead];
MsgRead=((++MsgRead)%MSG_QUEUE_SIZE);
return 1;/*msg有效*/
}
return 0;/*队列中无消息*/
}
#define LCD_WIDTH 112
#define LCD_HIGH 48
#define LCD_WIDTH_BYTE 14/* 6Bytes x 8Bits = 48Dots */
extern unsigned char DisBuffer[672];
extern unsigned char *RomAddress;
/*======================================================================
---在LCD中以某一颜色显示一点----DispDot---
======================================================================*/
void DispDot(int x,int y,unsigned char c)
{
int offset=y*LCD_WIDTH_BYTE+(x>>3);
unsigned char mask=(x&0x07);
if(c)c=0x80;
DisBuffer[offset]&=(~(0x80>>mask));
DisBuffer[offset]|=(c>>mask);
}
/*======================================================================
---在LCD中以图象数据s显示一幅图象----DispImage---
---画点方式效率低下,建议用户用逻辑和移位操作优化数据拷贝---
======================================================================*/
void DispImage(int x,int y,int w,int h,unsigned char *s)
{
int i,j,k;
unsigned char mask;
for(j=y;j<h+y;j++)
{
for(i=x;i<=x+w-8;i+=8)
{
mask=0x80;
for(k=0;k<8;k++)
{
DispDot(i+k,j,*s&mask);
mask=(mask>>1);
}
s++;
}
}
if(w&0x07)
{
mask=0x80;
for(j=y;j<h+y;j++)
{
for(k=0;k<(w&0x07);k++)DispDot(i+k,j,*s&mask);
mask=(mask>>1);
}
s++;
}
}
typedef struct _BMPHEAD
{
unsigned char mode;
unsigned char gray;
unsigned short width;
unsigned short high;
}BMPHEAD;
/*======================================================================
---在LCD中以包括图象头的图象数据s显示一幅图象----DispBmp---
======================================================================*/
void DispBmp(int x,int y,unsigned char *s)
{
BMPHEAD *pBmphead=(BMPHEAD *)s;
if(pBmphead->mode==0&&pBmphead->gray==1)DispImage(x,y,pBmphead->width,pBmphead->high,&s[sizeof(BMPHEAD)]);
}
unsigned char * GetFont8x16(unsigned char CharCode)
{
return RomAddress+ROM_ASCII16+(long)(CharCode*16);
}
unsigned char * GetFont16x16(unsigned short CharCode)
{
return RomAddress+ROM_HZK16+(((((CharCode&0x00ff)-0xa1)*94+((CharCode>>8)-0xa1)))*32);
}
int DispChar(int x,int y,unsigned short CharCode)
{
if((CharCode>>8)&0x80)
{
if(16+x>=LCD_WIDTH)return 0;
DispImage(x,y,16,16,GetFont16x16(CharCode));
return 16;
}
else
{
if(8+x>=LCD_WIDTH)return 0;
DispImage(x,y,8,16,GetFont8x16((unsigned char)CharCode));
return 8;
}
}
void DispStr(short x,short y,unsigned char *s)
{
int i;
while(*s&&*s!='\n'&&*s!='\r')
{
if((*s)&0x80)
{
i=DispChar(x,y,*((unsigned short*)s));
s+=2;
}
else
{
i=DispChar(x,y,(unsigned short)(*s));
s++;
}
if(!i)break;
x+=i;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -