硬汉嵌入式论坛

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

[emWin教程入门篇] 【STemWin教程】第23章 游标

[复制链接]

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
发表于 2015-1-31 10:50:16 | 显示全部楼层 |阅读模式
特别说明:完整STemWin的1-60期教程和配套实例下载地址:链接
第23章 游标

    本期教程比较简单,跟大家讲解一下游标的使用。在小型的嵌入式系统中,外接鼠标和键盘的情况比较少,所以游标的显示就显的不那么重要,不过在需要触摸校准的时候游标就比较重要了,可以帮助我们很方便的看出X,Y轴镜像和翻转问题。
    23. 1  STemWin支持的游标效果
    23. 2 模拟器上演示游标
    23. 3 模拟器上演示动态游标
    23. 4 总结
23.1 STemWin支持的游标效果
23.1.png

    当前emWin支持的游标效果就是上面几种,初始化emWin后是不显示游标的,需要调用函数GUI_CURSOR_Show()才会显示出来,显示出来的是GUI_CursorArrowM(中箭头)。要选择其它的箭头可以调用函数GUI_CURSOR_Select()进行选择其它的箭头。STemWin进入到5.22版本后加入了动态的游标,效果如下:
23.2.png

23.2 模拟器上演示游标
    官方有一个例子是专门的演示游标的,程序位置在:
23.3.png
    主要程序如下(数据部分没有贴出):
  1. static const GUI_BITMAP bmSeggerLogoBlue = {
  2. 138,                  // XSize
  3.   65,                  // YSize
  4.   69,                  // BytesPerLine
  5.    4,                  // BitsPerPixel
  6. acSeggerLogoBlue16,   // Pointer to picture data (indices)
  7. &PalSeggerLogoBlue16  // Pointer to palette
  8. };
  9. static const GUI_CURSOR* _apCursor[] = { (1)
  10. &GUI_CursorArrowS,  &GUI_CursorArrowM,  &GUI_CursorArrowL,
  11. &GUI_CursorArrowLI, &GUI_CursorArrowMI, &GUI_CursorArrowSI,
  12. &GUI_CursorCrossS,  &GUI_CursorCrossM,  &GUI_CursorCrossL,
  13. &GUI_CursorCrossLI, &GUI_CursorCrossMI, &GUI_CursorCrossSI
  14. };
  15. static char* _aacCursorName[] = {
  16. "GUI_CursorArrowS",  "GUI_CursorArrowM",  "GUI_CursorArrowL",
  17. "GUI_CursorArrowLI", "GUI_CursorArrowMI", "GUI_CursorArrowSI",
  18. "GUI_CursorCrossS",  "GUI_CursorCrossM",  "GUI_CursorCrossL",
  19. "GUI_CursorCrossLI", "GUI_CursorCrossMI", "GUI_CursorCrossSI"
  20. };
  21. /*********************************************************************
  22. *
  23. *       Static code
  24. *
  25. **********************************************************************
  26. */
  27. /*********************************************************************
  28. *
  29. *       _MoveCursor
  30. */
  31. static void _MoveCursor(void) {(2)
  32.   int x;
  33.   int y;
  34.   int tm;
  35.   int cnt;
  36.   int yStep;
  37.   int xPos;
  38.   int yPos;
  39.   cnt  = 0;
  40.   yStep=-1;
  41.   xPos = LCD_GetXSize() / 2 - bmSeggerLogoBlue.XSize/2;
  42.   yPos = LCD_GetYSize() / 2 - bmSeggerLogoBlue.YSize/2+25;
  43.   GUI_DispStringHCenterAt("Cursor shape can be changed\nand the cursor can be moved", 160,  75);
  44.   GUI_CURSOR_Show();  (3)
  45.   GUI_DrawBitmap(&bmSeggerLogoBlue, xPos, yPos );
  46.   y = 150;
  47.   for (x = 0; x < 320; x++) {
  48.     if ((x % 54) == 0) {
  49.       GUI_CURSOR_Select(_apCursor[cnt++]); (4)
  50.     }
  51.     tm = GUI_GetTime();
  52.     y += yStep;
  53.     if(y<=80) yStep=1;
  54.     if(y>=150) yStep=-1;
  55.     GUI_CURSOR_SetPosition(x, y);(5)
  56.     while ((GUI_GetTime() - tm) < 10);
  57.   }
  58.   for (x = 320; x > 0; x--) {  (6)
  59.     tm = GUI_GetTime();
  60.     if ((x % 54) == 0) {
  61.       GUI_CURSOR_Select(_apCursor[cnt++]);
  62.     }
  63.     y += yStep;
  64.     if(y<=80) yStep=1;
  65.     if(y>=150) yStep=-1;
  66.     GUI_CURSOR_SetPosition(x, y);
  67.     while ((GUI_GetTime() - tm) < 10);
  68.   }
  69.   GUI_CURSOR_Hide();  (7)
  70.   GUI_Delay(500);
  71. }
  72. /*********************************************************************
  73. *
  74. *       _DispCursor
  75. */
  76. static void _DispCursor(void) {  (8)
  77.   int i;
  78.   int x;
  79.   int y;
  80.   GUI_DispStringHCenterAt("Available cursors:", 160,  80);
  81.   for (i = 0; i < 12; i++) {
  82.     x = 160 - (_apCursor[i]->pBitmap->XSize / 2);
  83.     y = 120 - (_apCursor[i]->pBitmap->YSize / 2);
  84.     GUI_DrawBitmap(_apCursor[i]->pBitmap, x, y);
  85.     GUI_DispStringHCenterAt(_aacCursorName[i], 160,145);
  86.     GUI_Delay(750);
  87.     GUI_ClearRect(0, 100, 319, 165);
  88.   }
  89.   GUI_ClearRect(0, 80, 319, 100);
  90.   GUI_Delay(500);
  91. }
  92. /*********************************************************************
  93. *
  94. *       _DemoCursor
  95. */
  96. static void _DemoCursor(void) {
  97.   GUI_SetBkColor(GUI_BLUE);
  98.   GUI_Clear();
  99.   GUI_SetColor(GUI_WHITE);
  100.   GUI_SetFont(&GUI_Font24_ASCII);
  101.   GUI_DispStringHCenterAt("CURSOR_Sample - Sample", 160, 5);
  102.   GUI_SetFont(&GUI_Font8x16);
  103.   while (1) {
  104.     _DispCursor();
  105.     GUI_ClearRect(0, 60, 319, 200);
  106.     _MoveCursor();
  107.     GUI_ClearRect(0, 60, 319, 200);
  108.   }
  109. }
  110. /*********************************************************************
  111. *
  112. *       Public code
  113. *
  114. **********************************************************************
  115. */
  116. /*********************************************************************
  117. *
  118. *       MainTask
  119. */
  120. void MainTask(void) {
  121.   GUI_Init();
  122.   _DemoCursor();
  123. }
复制代码
1. 大家要学会这种定义方法,这样在选择不同的游标时就非常的方便了,用下面这种方式即可
    for (i = 0;i<1 0; x++)
    {
    GUI_CURSOR_Select(_apCursor[i]);
    }
2. 这个函数主要实现游标的移动效果。
3. GUI_CURSOR_Show()  显示游标。
4. GUI_CURSOR_Select() 设置指定的游标。
5. GUI_CURSOR_SetPosition() 设置游标位置。
6. 大家要学会这种延迟方法,这样可以实现准确的时间间隔
    for (x = 320; x > 0; x--)
    {
    tm = GUI_GetTime();
    //用户程序
    while ((GUI_GetTime() - tm) < 10);
    }
7. GUI_CURSOR_Hide() 隐藏游标。
8. 这个函数实现游标的轮番展示。其中GUI_CURSOR的定义如下:
    typedef struct {
    const GUI_BITMAP  * pBitmap;
    int                 xHot;
    int                 yHot;
    } GUI_CURSOR;
    此DEMO程序显示效果如下:
23.4.png
23.5.png

23.3 模拟器上演示动态游标
    只要对上面的例子稍作修改就可以显示动态游标,修改的地方如下:
  1. /*********************************************************************
  2. *
  3. *       _DispCursor
  4. */
  5. static void _DispCursor(void) {
  6.   int i;
  7.   int x;
  8.   int y;
  9.   /* 动态游标的演示 */
  10.   GUI_CURSOR_SelectAnim(&GUI_CursorAnimHourglassM);(1)
  11.   GUI_Delay(5000);
  12.   GUI_DispStringHCenterAt("Available cursors:", 160,  80);
  13.   for (i = 0; i < 12; i++) {
  14.     x = 160 - (_apCursor[i]->pBitmap->XSize / 2);
  15.     y = 120 - (_apCursor[i]->pBitmap->YSize / 2);
  16.     GUI_DrawBitmap(_apCursor[i]->pBitmap, x, y);
  17.     GUI_DispStringHCenterAt(_aacCursorName[i], 160,145);
  18.     GUI_Delay(750);
  19.     GUI_ClearRect(0, 100, 319, 165);
  20.   }
  21.   GUI_ClearRect(0, 80, 319, 100);
  22.   GUI_Delay(500);
  23. }
复制代码
1. 添加这两行代码即可,让其显示5秒的时间。
    实际显示效果如下(游标是动态的,这里只贴了一幅图):
23.6.png

    这个动态的游标也支持自定义图形,有兴趣的可以尝试。
23.4 总结
    游标显示的知识就跟大家讲这么多,相对来说比前面几期都要简单很多。
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-16 08:00 , Processed in 0.304834 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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