硬汉嵌入式论坛

 找回密码
 立即注册
查看: 4209|回复: 4
收起左侧

[emWin] swipelist用法,大家来讨论讨论

[复制链接]

7

主题

70

回帖

91

积分

初级会员

积分
91
发表于 2016-8-16 22:43:09 | 显示全部楼层 |阅读模式
从国外一个网站找到关于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 ****************************/
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115717
QQ
发表于 2016-8-17 10:22:24 | 显示全部楼层
还没有用过这个控件,帮顶。
回复

使用道具 举报

268

主题

597

回帖

1401

积分

至尊会员

积分
1401
发表于 2016-8-17 13:12:38 | 显示全部楼层
讨论就讨论呗,还直接上上了代码,代码有什么好讨论的
回复

使用道具 举报

3

主题

68

回帖

77

积分

初级会员

积分
77
发表于 2016-9-2 00:05:07 | 显示全部楼层
那里看到的,我试了一下 ,跑一会挂掉了,我的是5.32b 版本
回复

使用道具 举报

25

主题

300

回帖

380

积分

高级会员

积分
380
发表于 2016-9-2 11:57:10 | 显示全部楼层
我试了没问题,可以用,但要结合手势来滑动,
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-5-14 07:42 , Processed in 0.268372 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表