LISTVIEW_Transparent background

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

    • LISTVIEW_Transparent background

      Good Morning:

      I'm using the listview widget and I can not get the background to look transparent


      I activate the transparent flag in the creation of the object.




      static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      { WINDOW_CreateIndirect, "Window", ID_WINDOW_LISTA, 0, 0, 480, 272, WM_CF_MEMDEV | WM_CF_MEMDEV_ON_REDRAW, 0x0, 0 },
      { IMAGE_CreateIndirect, "Image", ID_LISTA_IMAGE_0, 0, 0, 480, 272, 0, 0, 0 },
      { LISTVIEW_CreateIndirect, "Listview", ID_LISTVIEW_0, 0, 40, 480, 232, WM_CF_HASTRANS, 0x0, 0 },
      { IMAGE_CreateIndirect, "Image", ID_LISTA_IMAGE_BARRA, 0, 0, 480, 40, 0, 0, 0 },
      { TEXT_CreateIndirect, "Text", ID_LISTA_TEXT_REFRIGERANTE, 20, 0, 460, 40, 0, 0x0, 0 },
      { TEXT_CreateIndirect, "Text", ID_LISTA_TEXT_MENU, 0, 0, 460, 40, 0, 0x0, 0 },
      // USER START (Optionally insert additional widgets)
      // USER END
      };

      When I define the color of the background, I indicate that it is transparent and the screen paints the background of black color



      LISTVIEW_SetBkColor(hItem, LISTVIEW_CI_UNSEL, GUI_TRANSPARENT);
      LISTVIEW_SetBkColor(hItem, LISTVIEW_CI_SEL, GUI_TRANSPARENT);
      LISTVIEW_SetBkColor(hItem, LISTVIEW_CI_SELFOCUS, GUI_ORANGE);

      But, if I define that the background is "invalid color", the screen paints the background of white color.


      LISTVIEW_SetBkColor(hItem, LISTVIEW_CI_UNSEL, GUI_INVALID_COLOR);
      LISTVIEW_SetBkColor(hItem, LISTVIEW_CI_SEL, GUI_INVALID_COLOR);
      LISTVIEW_SetBkColor(hItem, LISTVIEW_CI_SELFOCUS, GUI_ORANGE);

      What should I do to see the transparent background?
    • Hi,

      I agree with you that the widget should become transparent if the transparency flag is set and GUI_TRANSPARENT is its bk color.
      We will change the drawing behavior of the LISTVIEW in a future release.

      For now you can set a custom owner draw function for the widget and react on WIDGET_ITEM_DRAW_BACKGROUND. Simply do nothing if the item to be drawn is not the selected one. IF the item is the selected call the default owner draw function to clear the area with orange.

      Here is an example on how to achieve a transparent LISTVIEW:

      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_LISTVIEW_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. { LISTVIEW_CreateIndirect, "Listview", ID_LISTVIEW_0, 40, 40, 240, 150, 0, 0x0, 0 },
      29. };
      30. /*********************************************************************
      31. *
      32. * Static code
      33. *
      34. **********************************************************************
      35. */
      36. /*********************************************************************
      37. *
      38. * _cbDialog
      39. */
      40. static int _OwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
      41. int Sel;
      42. switch (pDrawItemInfo->Cmd) {
      43. case WIDGET_ITEM_DRAW_BACKGROUND:
      44. //
      45. // Check if the current item is the selected.
      46. //
      47. Sel = LISTVIEW_GetSel(pDrawItemInfo->hWin);
      48. if ((Sel == pDrawItemInfo->ItemIndex) && (Sel != -1)) {
      49. //
      50. // If it is, use the default owner draw to fill the area with orange
      51. //
      52. LISTVIEW_OwnerDraw(pDrawItemInfo);
      53. } else {
      54. //
      55. // Else, do nothing, the background gets cleared by the window behind the LISTVIEW
      56. //
      57. return 0;
      58. }
      59. default:
      60. return LISTVIEW_OwnerDraw(pDrawItemInfo);
      61. }
      62. }
      63. /*********************************************************************
      64. *
      65. * _cbDialog
      66. */
      67. static void _cbDialog(WM_MESSAGE * pMsg) {
      68. WM_HWIN hItem;
      69. int NCode;
      70. int Id;
      71. GUI_RECT Rect;
      72. switch (pMsg->MsgId) {
      73. case WM_INIT_DIALOG:
      74. //
      75. // Initialization of 'Listview'
      76. //
      77. hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_0);
      78. WM_SetHasTrans(hItem);
      79. LISTVIEW_SetOwnerDraw(hItem, _OwnerDraw);
      80. LISTVIEW_AddColumn(hItem, 80, "Col 0", GUI_TA_HCENTER | GUI_TA_VCENTER);
      81. LISTVIEW_AddColumn(hItem, 80, "Col 1", GUI_TA_HCENTER | GUI_TA_VCENTER);
      82. LISTVIEW_AddColumn(hItem, 80, "Col 2", GUI_TA_HCENTER | GUI_TA_VCENTER);
      83. LISTVIEW_AddRow(hItem, NULL);
      84. LISTVIEW_AddRow(hItem, NULL);
      85. LISTVIEW_AddRow(hItem, NULL);
      86. LISTVIEW_SetItemText(hItem, 0, 0, "Item");
      87. LISTVIEW_SetItemText(hItem, 0, 1, "Item");
      88. LISTVIEW_SetItemText(hItem, 0, 2, "Item");
      89. LISTVIEW_SetItemText(hItem, 1, 0, "Item");
      90. LISTVIEW_SetItemText(hItem, 1, 1, "Item");
      91. LISTVIEW_SetItemText(hItem, 1, 2, "Item");
      92. LISTVIEW_SetItemText(hItem, 2, 0, "Item");
      93. LISTVIEW_SetItemText(hItem, 2, 1, "Item");
      94. LISTVIEW_SetItemText(hItem, 2, 2, "Item");
      95. LISTVIEW_SetGridVis(hItem, 1);
      96. LISTVIEW_SetBkColor(hItem, LISTVIEW_CI_UNSEL, GUI_TRANSPARENT);
      97. LISTVIEW_SetBkColor(hItem, LISTVIEW_CI_SEL, GUI_TRANSPARENT);
      98. LISTVIEW_SetBkColor(hItem, LISTVIEW_CI_SELFOCUS, GUI_ORANGE);
      99. break;
      100. case WM_NOTIFY_PARENT:
      101. Id = WM_GetId(pMsg->hWinSrc);
      102. NCode = pMsg->Data.v;
      103. switch(Id) {
      104. case ID_LISTVIEW_0: // Notifications sent by 'Listview'
      105. switch(NCode) {
      106. case WM_NOTIFICATION_CLICKED:
      107. break;
      108. case WM_NOTIFICATION_RELEASED:
      109. break;
      110. case WM_NOTIFICATION_SEL_CHANGED:
      111. break;
      112. }
      113. break;
      114. }
      115. break;
      116. case WM_PAINT:
      117. WM_GetClientRect(&Rect);
      118. GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_RED, GUI_GREEN);
      119. break;
      120. default:
      121. WM_DefaultProc(pMsg);
      122. break;
      123. }
      124. }
      125. /*********************************************************************
      126. *
      127. * Public code
      128. *
      129. **********************************************************************
      130. */
      131. /*********************************************************************
      132. *
      133. * MainTask
      134. */
      135. void MainTask(void) {
      136. GUI_Init();
      137. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      138. while (1) {
      139. GUI_Delay(100);
      140. }
      141. }
      142. /*************************** End of file ****************************/
      Display All


      Regards
      Sven