|
由于效率太低,和扩展性不高,我决定重写,同时,老版本的给各位友友研究,并且希望认识喜欢GUI的人。
我只上传了NormalButton的代码,不过相信肯定不会让大部分人失望,至于GUI高手,希望不要喷了,毕竟我
初来乍到,谢谢。
我做一些讲解,LHL_GUICore文件是底层抽象函数,由于我没有拿计算机图形学的书来看,所以有些函数效率比较低下,我一有空就解决,希望不要吐槽,谢谢。
LHL_NormalButton是按键控件的源码部分。
如果要按键显示文字的话,需要调用一个函数:
void LHL_FontPutStringAt(unsigned short xPos,unsigned short yPos,char *ch,unsigned short Fontcolor,unsigned short Bkcolor,unsigned char Type);
我写一个例程如下:
#include "LHL_GUICore.h"
#include "LHL_NormalButton.h"
#include "MyString.h"
#include "MyAPP.h"
enum
{
MyAPP_BackGroundColor=RGB(255,255,255),
};
static char MyAPPRunState=0;//应用正在运行
static LHL_NormalButtonTypeDef ReturnButton,MyButton;//按键对象实体化
static void APP_ReturnCallBack(MsgType Picchange,MsgType Messagesend);//按键消息响应函数声明
static void APP_MyBtnCallBack(MsgType Picchange,MsgType Messagesend);//按键消息响应函数声明
void MyAPPCreate(void)//当应用创建的时候调用此函数
{
/*****************创建控件************************/
NMBTN_NormalButtonCreate(&ReturnButton,LCD_WIDTH-85,LCD_HEIGHT-30,80,25,1,0);//创建返回按钮
NMBTN_SetText(&ReturnButton,"退出应用");//设置按键显示的文字信息
NMBTN_SetCallBack(&ReturnButton,&APP_ReturnCallBack);//设置消息映射回调函数
NMBTN_NormalButtonCreate(&MyButton,20,20,80,25,1,0);
NMBTN_SetText(&MyButton,"我的按钮");
NMBTN_SetCallBack(&MyButton,&APP_MyBtnCallBack);
MyAPPReDraw();
MyAPPRunState=1;
}
void MyAPPReDraw(void)//应用重绘整个窗口函数
{
short i=0,j=(LCD_HEIGHT-20)/2;
for(;i<=j;i++)
{
GUICore_DrawHLine(0,j-i+20,400,MyAPP_BackGroundColor);
GUICore_DrawHLine(0,j+i+20,400,MyAPP_BackGroundColor);
GUICore_Delay(0x3fff);
}
NMBTN_ButtonUpdate(&ReturnButton,ReturnButton.State);
NMBTN_ButtonUpdate(&MyButton,ReturnButton.State);
}
unsigned char m_R=0,m_G=0,m_B=0,ColorIsChange=0;
short mCount=0;
short xpos=0,ypos=20,xposAdd=1,yposAdd=1;
void MyAPPOnDraw(void)//应用重绘函数
{
if(!MyAPPRunState)
{
return;
}
mCount++;
if(mCount%120==0)
{
m_R++;
ColorIsChange=1;
}
if(mCount%130==0)
{
m_G++;
ColorIsChange=1;
}
if(mCount%150==0)
{
m_B++;
ColorIsChange=1;
}
if(mCount%150==0)
{
if(xposAdd)
{
xpos++;
if(xpos==320)xposAdd=0;
}
else
{
xpos--;
if(xpos==0)xposAdd=1;
}
if(yposAdd)
{
ypos++;
if(ypos==180)yposAdd=0;
}
else
{
ypos--;
if(ypos==20)yposAdd=1;
}
GUICore_FillRect(MyButton.x0,MyButton.y0,MyButton.x0+MyButton.xlen,MyButton.y0+MyButton.ylen,MyAPP_BackGroundColor);
NMBTN_SetPos(&MyButton,xpos,ypos);
}
if(ColorIsChange)
{
NMBTN_SetTextColor(&MyButton,((m_R&0x001f)<<11)|((m_G&0x003f)<<5)|(m_R&0x001f));
NMBTN_SetColor(&MyButton,~(((m_R&0x001f)<<11)|((m_G&0x003f)<<5)|(m_R&0x001f)));
NMBTN_ButtonUpdate(&MyButton,MyButton.State);
ColorIsChange=0;
}
}
void MyAPPDelete(void)//当退出应用时候,调用此函数
{
NMBTN_DelButton(&ReturnButton);
NMBTN_DelButton(&MyButton);
WM_DesktopHide(1);
MyAPPRunState=0;
}
void APP_ReturnCallBack(MsgType Picchange,MsgType Messagesend)
{
if(Picchange==BTNNOTPRESSED&&Messagesend==1)
{
MyAPPDelete();
}
}
void APP_MyBtnCallBack(MsgType Picchange,MsgType Messagesend)
{
}
然后,你需要周期调用这个函数:
short NMBTN_ButtonMessageCheck(short xPos,short yPos,unsigned char Pressed);
参数为你的触摸点位置和是否被按下,返回值为按键产生的消息,如果没有,则返回0. |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|