界面做个电量显示图标,根据采集的AD数值来更换图片,将图片设置为透明模式显示在按钮上,但是每次更新后要点击按钮位置才会更新图片,怎么样才能直接更新图片?
//设置窗口,按键位置大小
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 272, 480, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 30, 450, 80, 30, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_1, 160, 450, 80, 30, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_2, 230, 10, 40, 20, 0, 0x0, 0 },//电量图标
};
extern u16 adcx;
//按钮位图设置
static void _cbButton(WM_MESSAGE * pMsg)
{
WM_HWIN hWin;
hWin = pMsg->hWin;
switch (pMsg->MsgId)
{
case WM_PAINT:
GUI_SetAlpha(0x100);
if(adcx>0x092E) //>2350
{GUI_DrawBitmap(&bmp_dianliang4, 0, 0);}
else if(adcx>0X0866&&adcx<0x092E) //2150-2350
{GUI_DrawBitmap(&bmp_dianliang3, 0, 0);}
else if(adcx>0X0708&&adcx<0X0866) //1800-2150
{GUI_DrawBitmap(&bmp_dianliang2, 0, 0);}
else //<1800
{GUI_DrawBitmap(&bmp_dianliang1, 0, 0);}
GUI_SetAlpha(0);
break;
default:
BUTTON_Callback(pMsg);
}
}
//位图刷新
static void DianLiang_Update(WM_MESSAGE * pMsg)
{
WM_SetHasTrans(WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2));
WM_SetCallback(WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2), _cbButton);
};
//窗口内容
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
int NCode;
int Id;
GUI_RECT rRTC={230, 10, 170, 20}; //设置刷新区域
WM_HWIN hWin = pMsg->hWin;
switch (pMsg->MsgId) {
case WM_TIMER:
WM_InvalidateRect(hWin, &rRTC); //指定区域
DianLiang_Update(pMsg); //更新电量图标
WM_RestartTimer(pMsg->Data.v,100); //10MS进入一次
break;
//初始化定义
case WM_INIT_DIALOG:
hItem = WM_GetDialogItem(pMsg->hWin, ID_WINDOW_0);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetFont(hItem, &GUI_FontHZ16);
BUTTON_SetText(hItem, "查看");
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
BUTTON_SetFont(hItem, &GUI_FontHZ16);
BUTTON_SetText(hItem, "选项");
//电量图标
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
WM_SetHasTrans(hItem);
WM_SetCallback(hItem, _cbButton);
break;
|