emwin

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Hi,all~
      When I was learning progress bars, I had trouble writing custom skin functions for the PROGBAR. How to write the PROGBAR color function in the custom function.

      /****************Customize skin functions****************************************/
      static int _ProgbarSkin(const WIDGET_ITEM_DRAW_INFO *pDrawItemInfo)
      {
      WM_HWIN hWin;

      hWin = pDrawItemInfo->hWin;
      switch (pDrawItemInfo->Cmd)
      {
      /******************Draw the border*********************/
      case WIDGET_ITEM_DRAW_FRAME:
      GUI_SetBkColor(GUI_BLUE);
      GUI_Clear();
      break;
      /****************Draw the PROGBAR COLOR*********************/
      /***************I don't know how to write***********************/
      }
      break;
      default:
      return PROGBAR_DrawSkinFlex(pDrawItemInfo);
      }
      return 0;
      }
    • New

      Hi Parker,

      Here is a short example on how to use a custom skinning routine for the PROGBAR widget.

      C Source Code

      1. #include "DIALOG.h"
      2. /*********************************************************************
      3. *
      4. * Externals
      5. *
      6. **********************************************************************
      7. */
      8. /*********************************************************************
      9. *
      10. * Types
      11. *
      12. **********************************************************************
      13. */
      14. /*********************************************************************
      15. *
      16. * Defines
      17. *
      18. **********************************************************************
      19. */
      20. /*********************************************************************
      21. *
      22. * Static data
      23. *
      24. **********************************************************************
      25. */
      26. /*********************************************************************
      27. *
      28. * Static code
      29. *
      30. **********************************************************************
      31. */
      32. /*********************************************************************
      33. *
      34. * _ProgbarSkin
      35. */
      36. static int _ProgbarSkin(const WIDGET_ITEM_DRAW_INFO *pDrawItemInfo) {
      37. PROGBAR_SKINFLEX_INFO * pInfo;
      38. switch (pDrawItemInfo->Cmd) {
      39. case WIDGET_ITEM_DRAW_FRAME:
      40. GUI_SetColor(GUI_BLUE);
      41. GUI_DrawRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
      42. return 0;
      43. case WIDGET_ITEM_DRAW_BACKGROUND:
      44. pInfo = (PROGBAR_SKINFLEX_INFO *)pDrawItemInfo->p;
      45. if (pInfo) {
      46. switch (pInfo->Index) {
      47. case PROGBAR_SKINFLEX_L:
      48. GUI_DrawGradientH(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_YELLOW, GUI_RED);
      49. break;
      50. case PROGBAR_SKINFLEX_R:
      51. GUI_SetColor(GUI_LIGHTGRAY);
      52. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
      53. break;
      54. }
      55. }
      56. return 0;
      57. default:
      58. return PROGBAR_DrawSkinFlex(pDrawItemInfo);
      59. }
      60. }
      61. /*********************************************************************
      62. *
      63. * _cbBk
      64. */
      65. static void _cbBk(WM_MESSAGE * pMsg) {
      66. switch (pMsg->MsgId) {
      67. case WM_PAINT:
      68. GUI_SetBkColor(GUI_BLACK);
      69. GUI_Clear();
      70. break;
      71. default:
      72. WM_DefaultProc(pMsg);
      73. break;
      74. }
      75. }
      76. /*********************************************************************
      77. *
      78. * Public code
      79. *
      80. **********************************************************************
      81. */
      82. /*********************************************************************
      83. *
      84. * MainTask
      85. */
      86. void MainTask(void) {
      87. WM_HWIN hProgbar;
      88. int Dir;
      89. int Value;
      90. GUI_Init();
      91. WM_MULTIBUF_Enable(1);
      92. WM_SetCallback(WM_HBKWIN, _cbBk);
      93. hProgbar = PROGBAR_CreateEx(10, 10, 120, 30, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_PROGBAR0);
      94. PROGBAR_SetSkin(hProgbar, _ProgbarSkin);
      95. Dir = 0;
      96. Value = 0;
      97. while (1) {
      98. GUI_Delay(100);
      99. if (Dir == 0) {
      100. Value++;
      101. PROGBAR_SetValue(hProgbar, Value);
      102. if (Value == 100) {
      103. Dir = 1;
      104. }
      105. } else {
      106. Value--;
      107. PROGBAR_SetValue(hProgbar, Value);
      108. if (Value == 0) {
      109. Dir = 0;
      110. }
      111. }
      112. WM_InvalidateWindow(hProgbar); // Invalidate the whole progbar, per default only the changed area will be redrawn.
      113. // This way we make sure the complete PROGBAR gets redrawn.
      114. }
      115. }
      116. /*************************** End of file ****************************/
      Display All

      Regards,
      Sven