LISTWHEEL with semitransparent background

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

    • LISTWHEEL with semitransparent background

      How can I get the selected item of a LISTWHEEL item to have a semi-transparent background color?

      I tried this:

      C Source Code

      1. #include "GUI.h"
      2. #include "LISTWHEEL.h"
      3. #include <stdio.h>
      4. const char *pList[] =
      5. {
      6. "1st",
      7. "2nd",
      8. "3rd",
      9. "4th",
      10. NULL,
      11. };
      12. void MainTask(void)
      13. {
      14. GUI_Init();
      15. // GUI_EnableAlpha(1);
      16. GUI_SetBkColor(GUI_WHITE);
      17. GUI_Clear();
      18. GUI_DrawGradientV(13, 5, 70, 65, GUI_YELLOW, GUI_GREEN);
      19. LISTWHEEL_Handle hWin;
      20. hWin = LISTWHEEL_CreateEx(10, 10, 50, 45, WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, 0, GUI_ID_LISTWHEEL0, pList);
      21. LISTWHEEL_SetBkColor(hWin, LISTWHEEL_CI_SEL, GUI_MAKE_COLOR((0x70uL << 24) | 0x0000FF));
      22. LISTWHEEL_SetBkColor(hWin, LISTWHEEL_CI_UNSEL, GUI_TRANSPARENT);
      23. while(1)
      24. {
      25. GUI_Delay(100);
      26. }
      27. }
      Display All


      and the result is:

      [img]https://s17.postimg.org/73dzfhw8f/semitransparent_List_Wheel.png[/img]

      instead, I can get the text semi-transparent if I try to get it.

      best regards
      Max
    • Hi,

      Unfortunately, it is not that easy.

      If the LISTWHEEL gets created with the transparency flag set it will be completely transparent and does not fill its background.

      If you want a semi transparent background you have to set a owner draw function. Within that owner draw function you check for the item which background should be drawn. Then call GUI_EnableAlpha(1) to enable the use of the alpha bits of a color, perform a clear, and disable the use of the alpha bits again. After that call LISTWHEEL_OwnerDraw() to draw the rest of the widget.

      Here is an example on you this can be achieved.

      C Source Code

      1. #include "DIALOG.h"
      2. /*********************************************************************
      3. *
      4. * Externals
      5. *
      6. **********************************************************************
      7. */
      8. /*********************************************************************
      9. *
      10. * Defines
      11. *
      12. **********************************************************************
      13. */
      14. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      15. #define ID_LISTWHEEL_0 (GUI_ID_USER + 0x01)
      16. /*********************************************************************
      17. *
      18. * Static data
      19. *
      20. **********************************************************************
      21. */
      22. /*********************************************************************
      23. *
      24. * _aDialogCreate
      25. */
      26. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      27. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
      28. { LISTWHEEL_CreateIndirect, "Listwheel", ID_LISTWHEEL_0, 200, 20, 80, 120, 0, 0x0, 0 },
      29. };
      30. /*********************************************************************
      31. *
      32. * Static code
      33. *
      34. **********************************************************************
      35. */
      36. /*********************************************************************
      37. *
      38. * _OwnerDraw
      39. */
      40. static int _OwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
      41. switch (pDrawItemInfo->Cmd) {
      42. case WIDGET_ITEM_DRAW:
      43. //
      44. // Check if the current item is the selected
      45. //
      46. if (pDrawItemInfo->ItemIndex == LISTWHEEL_GetSel(pDrawItemInfo->hWin)) {
      47. //
      48. // Enable alpha, the upper 8 bits (most significant) will be taken into account
      49. //
      50. GUI_EnableAlpha(1);
      51. //
      52. // Get LISTWHEEL color and set it as current bk color
      53. //
      54. GUI_SetBkColor(LISTWHEEL_GetBkColor(pDrawItemInfo->hWin, LISTWHEEL_CI_SEL));
      55. //
      56. // Clear item area with the color
      57. //
      58. GUI_ClearRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
      59. //
      60. // Disable alpha again.
      61. //
      62. GUI_EnableAlpha(0);
      63. }
      64. return LISTWHEEL_OwnerDraw(pDrawItemInfo);
      65. case WIDGET_ITEM_DRAW_BACKGROUND:
      66. return LISTWHEEL_OwnerDraw(pDrawItemInfo);
      67. default:
      68. return LISTWHEEL_OwnerDraw(pDrawItemInfo);
      69. }
      70. }
      71. /*********************************************************************
      72. *
      73. * _cbDialog
      74. */
      75. static void _cbDialog(WM_MESSAGE * pMsg) {
      76. WM_HWIN hItem;
      77. int NCode;
      78. int Id;
      79. GUI_RECT Rect;
      80. switch (pMsg->MsgId) {
      81. case WM_INIT_DIALOG:
      82. //
      83. // Initialization of 'Listwheel'
      84. //
      85. hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_0);
      86. LISTWHEEL_AddString(hItem, "String0");
      87. LISTWHEEL_AddString(hItem, "String1");
      88. LISTWHEEL_AddString(hItem, "String2");
      89. LISTWHEEL_AddString(hItem, "String3");
      90. LISTWHEEL_AddString(hItem, "String4");
      91. LISTWHEEL_AddString(hItem, "String5");
      92. LISTWHEEL_AddString(hItem, "String6");
      93. LISTWHEEL_AddString(hItem, "String7");
      94. LISTWHEEL_AddString(hItem, "String8");
      95. LISTWHEEL_AddString(hItem, "String9");
      96. LISTWHEEL_AddString(hItem, "String10");
      97. WM_SetHasTrans(hItem); // Same as if created with WM_CF_HASTRANS
      98. LISTWHEEL_SetOwnerDraw(hItem, _OwnerDraw); // Set a owner draw
      99. LISTWHEEL_SetBkColor(hItem, LISTWHEEL_CI_SEL, GUI_MAKE_COLOR((0x70uL << 24) | 0x0000FF));
      100. LISTWHEEL_SetBkColor(hItem, LISTWHEEL_CI_UNSEL, GUI_TRANSPARENT);
      101. break;
      102. case WM_NOTIFY_PARENT:
      103. Id = WM_GetId(pMsg->hWinSrc);
      104. NCode = pMsg->Data.v;
      105. switch(Id) {
      106. case ID_LISTWHEEL_0: // Notifications sent by 'Listwheel'
      107. switch(NCode) {
      108. case WM_NOTIFICATION_CLICKED:
      109. break;
      110. case WM_NOTIFICATION_RELEASED:
      111. break;
      112. case WM_NOTIFICATION_SEL_CHANGED:
      113. break;
      114. }
      115. break;
      116. }
      117. break;
      118. case WM_PAINT:
      119. WM_GetClientRect(&Rect);
      120. GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_WHITE, GUI_BLACK);
      121. GUI_DrawLine(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
      122. GUI_DrawLine(Rect.x0, Rect.y1, Rect.x1, Rect.y0);
      123. break;
      124. default:
      125. WM_DefaultProc(pMsg);
      126. break;
      127. }
      128. }
      129. /*********************************************************************
      130. *
      131. * Public code
      132. *
      133. **********************************************************************
      134. */
      135. /*********************************************************************
      136. *
      137. * MainTask
      138. */
      139. void MainTask(void) {
      140. GUI_Init();
      141. WM_MULTIBUF_Enable(1);
      142. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      143. while (1) {
      144. GUI_Delay(100);
      145. }
      146. }
      147. /*************************** End of file ****************************/
      Display All


      Regards
      Sven
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.