|
从国外一个网站找到关于swipelist的用法,但本人英文很烂,不是很明白,和大家一起讨论,共同学习学习。
下面是程序代码,请高手解释一下。
#include <stdio.h>
#include "DIALOG.h"
#include "SWIPELIST.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_SWIPELIST_0 (GUI_ID_USER + 0x01)
#define ID_RADIO_0 (GUI_ID_USER + 0x02)
#define ID_CHECK_0 (GUI_ID_USER + 0x03)
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
/*********************************************************************
*
* _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
{ SWIPELIST_CreateIndirect, "Swipelist", ID_SWIPELIST_0, 20, 20, 220, 232, 0, 0x0, 0 },
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _SwipeOwnerDraw
*/
static int _SwipeOwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
//
// Distinguish between different commands
//
switch (pDrawItemInfo->Cmd) {
case WIDGET_ITEM_DRAW_SEP:
GUI_DrawGradientH(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y1, GUI_DARKGRAY, GUI_BLACK);
GUI_DrawGradientH(pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_BLACK, GUI_DARKGRAY);
break;
case WIDGET_ITEM_DRAW_TEXT:
//
// Just set a text mode but let the default owner draw routine handle the rest
//
GUI_SetTextMode(GUI_TM_TRANS);
SWIPELIST_OwnerDraw(pDrawItemInfo);
break;
case WIDGET_ITEM_DRAW_BITMAP:
break;
case WIDGET_ITEM_DRAW_BACKGROUND:
//
// Handle drawing of the background of the items
//
switch (pDrawItemInfo->ItemIndex) {
case 0: // 1st separator
case 5: // 2nd separator
case 10: // 3rd separator
case 15: // 4th separator
GUI_SetColor(GUI_BLACK);
GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 2, GUI_BLACK, GUI_GRAY);
GUI_SetColor(GUI_LIGHTGRAY);
GUI_DrawRoundedRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - 1, 5);
return 0;
default: // Any other item
//
// Determin if the item to drawn is the currently selected
//
if (SWIPELIST_GetSelItem(pDrawItemInfo->hWin) == pDrawItemInfo->ItemIndex) {
//
// Draw the selected one different
//
GUI_SetColor(GUI_DARKRED);
GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) * 2 / 3, GUI_BLACK, GUI_DARKRED);
GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 3, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_DARKRED, GUI_BLACK);
} else {
//
// Draw any other items this way
//
GUI_SetColor(GUI_DARKGRAY);
GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
}
}
break;
default:
//
// Anything we do not catch in this routine gets handled by the default owner draw
//
return SWIPELIST_OwnerDraw(pDrawItemInfo);
}
return 0;
}
/*********************************************************************
*
* _cbSwipe
*/
static void _cbSwipe(WM_MESSAGE * pMsg) {
int NCode;
int Id;
WM_HWIN hItem;
int Value;
switch (pMsg->MsgId) {
case WM_NOTIFY_PARENT:
//
// Get Id of the child got something
//
Id = WM_GetId(pMsg->hWinSrc);
//
// Get an idea of what it got
//
NCode = pMsg->Data.v;
switch(Id) {
case ID_RADIO_0: // Notifications sent by the RADIO widget
switch(NCode) {
case WM_NOTIFICATION_VALUE_CHANGED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_RADIO_0);
Value = RADIO_GetValue(hItem);
break;
}
break;
case ID_CHECK_0: // Notifications sent by CHECKBOX widget
switch(NCode) {
case WM_NOTIFICATION_VALUE_CHANGED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECK_0);
Value = CHECKBOX_GetState(hItem);
break;
}
break;
}
break;
default:
SWIPELIST_Callback(pMsg);
break;
}
}
/*********************************************************************
*
* _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
GUI_RECT Rect;
int NCode;
int Id;
char aText[30];
int i;
int j;
int Item;
static int ItemIndex = 0;
static GUI_RECT TRect;
WM_HWIN hAttachItem;
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
//
// Init SWIPELIST
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
WM_SetCallback(hItem, _cbSwipe);
WM_MOTION_SetMoveable(hItem, WM_CF_MOTION_Y, 1);
//
// Four separator
//
Item = 1;
for (j = 0; j < 4; j++) {
sprintf(aText, "Separator %i", j);
SWIPELIST_AddSepItem(hItem, aText, 30);
//
// Four subitems for each separator
//
for (i = 0; i < 4; i++) {
sprintf(aText, "Item %i", j + Item++);
SWIPELIST_AddItem(hItem, aText, 60);
}
}
hAttachItem = RADIO_CreateEx(0, 0, 20, 50, pMsg->hWin, WM_CF_SHOW, 0, ID_RADIO_0, 3, 15);
SWIPELIST_ItemAttachWindow(hItem, 1, hAttachItem, 70, 5);
hAttachItem = CHECKBOX_CreateEx(0, 0, 20, 20, pMsg->hWin, WM_CF_SHOW, 0, ID_CHECK_0);
SWIPELIST_ItemAttachWindow(hItem, 2, hAttachItem, 70, 20);
//
// Set an owner draw function
//
SWIPELIST_SetOwnerDraw(hItem, _SwipeOwnerDraw);
//
// Set Text rect
//
TRect.x0 = LCD_GetXSize() / 2;
TRect.y0 = 0;
TRect.x1 = LCD_GetXSize();
TRect.y1 = LCD_GetYSize();
break;
case WM_PAINT:
//
// Draw the background of the dialog window
//
WM_GetClientRect(&Rect);
GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_BLACK, GUI_GRAY);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
//
// Draw a frame around the SWIPELIST
//
WM_GetWindowRectEx(hItem, &Rect);
Rect.x0 -= 1;
Rect.y0 -= 1;
Rect.x1 += 1;
Rect.y1 += 1;
GUI_SetColor(GUI_LIGHTGRAY);
GUI_DrawRectEx(&Rect);
if (ItemIndex) {
sprintf(aText, "Item %i selected", ItemIndex); // build a string
} else {
sprintf(aText, "no item selected"); // build a string
}
GUI_SetTextMode(GUI_TM_TRANS);
GUI_SetFont(GUI_FONT_24B_1);
GUI_SetColor(GUI_WHITE);
GUI_DispStringInRect(aText, &TRect, GUI_TA_HCENTER | GUI_TA_VCENTER); // and display it centered
break;
case WM_NOTIFY_PARENT:
//
// Get Id of the child got something
//
Id = WM_GetId(pMsg->hWinSrc);
//
// Get an idea of what it got
//
NCode = pMsg->Data.v;
switch(Id) {
//
// Which child
//
case ID_SWIPELIST_0: // Notifications sent by 'Swipelist'
switch(NCode) {
//
// got what
//
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
ItemIndex = SWIPELIST_GetReleasedItem(hItem);
WM_InvalidateRect(pMsg->hWin, &TRect);
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
WM_SetCreateFlags(WM_CF_MEMDEV);
GUI_Init();
WM_MOTION_Enable(1);
GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/ |
|