KNOB with background memory device containing transparency

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

    • KNOB with background memory device containing transparency

      Hello to everyone,

      I'm trying to implement a simple knob using memory devices containing transparency.

      Memory device for the knob is displayed correctly whereas memory device for the background loses its transparency.

      When checking data at the background device transparency is present.

      Here is the code (screen size 320*240) and screenshots:

      C Source Code

      1. #include "DIALOG.h"
      2. KNOB_Handle hKnob;
      3. GUI_MEMDEV_Handle hMem, hMemBk, hMemPrev;
      4. int i, x0, y0, x1, y1;
      5. // Callback for desktop window to draw some data
      6. static void _cbBk(WM_MESSAGE * pMsg) {
      7. switch (pMsg->MsgId) {
      8. case WM_PAINT:
      9. // Fill desktop with a color
      10. GUI_SetBkColor(GUI_BLUE);
      11. GUI_Clear();
      12. // Display background text
      13. GUI_SetFont(GUI_FONT_8X16X3X3);
      14. GUI_DispStringHCenterAt("Background", 160, 100);
      15. break;
      16. default:
      17. WM_DefaultProc(pMsg);
      18. break;
      19. }
      20. }
      21. void MainTask(void) {
      22. GUI_Init();
      23. WM_MULTIBUF_Enable(1);
      24. WM_SetSize(WM_HBKWIN, 320, 240);
      25. // Callback for desktop window
      26. WM_SetCallback(WM_HBKWIN, _cbBk);
      27. // Create background memdevice
      28. // Fill it with transparency
      29. // Draw circle and tickmarks with semitransparency
      30. hMemBk = GUI_MEMDEV_CreateFixed32(0, 0, 200, 200);
      31. hMemPrev = GUI_MEMDEV_Select(hMemBk);
      32. GUI_SetBkColor(GUI_TRANSPARENT);
      33. GUI_Clear();
      34. GUI_PreserveTrans(1);
      35. GUI_SetPenSize(30);
      36. GUI_SetColor((0x40ul << 24) | GUI_LIGHTGRAY);
      37. GUI_AA_DrawCircle(100, 100, 80);
      38. GUI_SetPenSize(1);
      39. GUI_SetColor((0x40ul << 24) | GUI_WHITE);
      40. for (i = 0; i < 360000; i += 30000) {
      41. x0 = 75 * GUI__SinHQ(i) * 0.0000152587890625 + 100;
      42. y0 = 75 * GUI__CosHQ(i) * 0.0000152587890625 + 100;
      43. x1 = 85 * GUI__SinHQ(i) * 0.0000152587890625 + 100;
      44. y1 = 85 * GUI__CosHQ(i) * 0.0000152587890625 + 100;
      45. GUI_AA_DrawLine(x0, y0, x1, y1);
      46. }
      47. GUI_PreserveTrans(0);
      48. // Create rotating memdevice
      49. // Fill it with transparency
      50. // Draw filled circle with point
      51. hMem = GUI_MEMDEV_CreateFixed32(0, 0, 200, 200);
      52. GUI_MEMDEV_Select(hMem);
      53. GUI_SetBkColor(GUI_TRANSPARENT);
      54. GUI_Clear();
      55. GUI_PreserveTrans(1);
      56. GUI_SetColor(GUI_RED);
      57. GUI_AA_FillCircle(100, 100, 67);
      58. GUI_SetColor(GUI_WHITE);
      59. GUI_AA_FillCircle(100, 50, 5);
      60. GUI_PreserveTrans(0);
      61. // Return context to LCD
      62. GUI_MEMDEV_Select(hMemPrev);
      63. // Create knob, set ticksize, set memdevices
      64. hKnob = KNOB_CreateEx(60, 20, 200, 200, WM_HBKWIN, WM_CF_SHOW, GUI_ID_KNOB0);
      65. KNOB_SetTickSize(hKnob, 300);
      66. KNOB_SetBkDevice(hKnob, hMemBk);
      67. KNOB_SetDevice(hKnob, hMem);
      68. while (1) {
      69. GUI_Delay(50);
      70. }
      71. }
      Display All



      Expecting to see the following:


      But see this instead:



      This had been seen using simulation v5.44 (GUISim.lib from SEGGER package) and real hardware using STemWin v5.44 (STemWin_CM7_wc32_ot.a from ST package).

      Thanks,
      Alex.

      The post was edited 3 times, last by LexaGB ().

    • Hi,

      It seems the knob removes the transparency from the BK device because of performance reasons.

      Below is your code with a little change. I have moved the KNOB and the memory device creation into a window. This window has the size of the KNOB and manages just the background by drawing hMemBk.
      The KNOB itself has no more a BK device.

      C Source Code

      1. #include "DIALOG.h"
      2. KNOB_Handle hKnob;
      3. GUI_MEMDEV_Handle hMem, hMemBk, hMemPrev;
      4. int i, x0, y0, x1, y1;
      5. /*********************************************************************
      6. *
      7. * _cbBk
      8. */
      9. static void _cbBk(WM_MESSAGE * pMsg) {
      10. switch (pMsg->MsgId) {
      11. case WM_PAINT:
      12. // Fill desktop with a color
      13. GUI_SetBkColor(GUI_BLUE);
      14. GUI_Clear();
      15. // Display background text
      16. GUI_SetFont(GUI_FONT_8X16X3X3);
      17. GUI_DispStringHCenterAt("Background", 160, 100);
      18. break;
      19. default:
      20. WM_DefaultProc(pMsg);
      21. break;
      22. }
      23. }
      24. /*********************************************************************
      25. *
      26. * _cbWinKnob
      27. */
      28. static void _cbWinKnob(WM_MESSAGE * pMsg) {
      29. int x;
      30. int y;
      31. switch (pMsg->MsgId) {
      32. case WM_CREATE:
      33. hMemBk = GUI_MEMDEV_CreateFixed32(0, 0, 200, 200);
      34. hMemPrev = GUI_MEMDEV_Select(hMemBk);
      35. GUI_SetBkColor(GUI_TRANSPARENT);
      36. GUI_Clear();
      37. GUI_PreserveTrans(1);
      38. GUI_SetPenSize(30);
      39. GUI_SetColor((0x40ul << 24) | (GUI_LIGHTGRAY & 0x00FFFFFF));
      40. GUI_AA_DrawCircle(100, 100, 80);
      41. GUI_SetPenSize(1);
      42. GUI_SetColor((0x40ul << 24) | (GUI_WHITE & 0x00FFFFFF));
      43. for (i = 0; i < 360000; i += 30000) {
      44. x0 = 75 * GUI__SinHQ(i) * 0.0000152587890625 + 100;
      45. y0 = 75 * GUI__CosHQ(i) * 0.0000152587890625 + 100;
      46. x1 = 85 * GUI__SinHQ(i) * 0.0000152587890625 + 100;
      47. y1 = 85 * GUI__CosHQ(i) * 0.0000152587890625 + 100;
      48. GUI_AA_DrawLine(x0, y0, x1, y1);
      49. }
      50. GUI_PreserveTrans(0);
      51. //
      52. // Create rotating memdevice
      53. // Fill it with transparency
      54. // Draw filled circle with point
      55. //
      56. GUI_MEMDEV_Select(0);
      57. GUI_MEMDEV_WriteAt(hMemBk, 10, 10);
      58. hMem = GUI_MEMDEV_CreateFixed32(0, 0, 200, 200);
      59. GUI_MEMDEV_Select(hMem);
      60. GUI_SetBkColor(GUI_TRANSPARENT);
      61. GUI_Clear();
      62. GUI_PreserveTrans(1);
      63. GUI_SetColor(GUI_RED);
      64. GUI_AA_FillCircle(100, 100, 67);
      65. GUI_SetColor(GUI_WHITE);
      66. GUI_AA_FillCircle(100, 50, 5);
      67. GUI_PreserveTrans(0);
      68. // Return context to LCD
      69. GUI_MEMDEV_Select(hMemPrev);
      70. GUI_SetBkColor(GUI_BLACK);
      71. GUI_Clear();
      72. GUI_DrawLine(0, 0, 320, 240);
      73. GUI_MEMDEV_WriteAt(hMem, 10, 10);
      74. // Create knob, set ticksize, set memdevices
      75. hKnob = KNOB_CreateEx(0, 0, 200, 200, pMsg->hWin, WM_CF_SHOW, GUI_ID_KNOB0);
      76. KNOB_SetTickSize(hKnob, 300);
      77. KNOB_SetDevice(hKnob, hMem);
      78. break;
      79. case WM_PAINT:
      80. x = WM_GetWindowOrgX(pMsg->hWin);
      81. y = WM_GetWindowOrgY(pMsg->hWin);
      82. GUI_MEMDEV_WriteAt(hMemBk, x, y);
      83. break;
      84. default:
      85. WM_DefaultProc(pMsg);
      86. break;
      87. }
      88. }
      89. /*********************************************************************
      90. *
      91. * MainTask
      92. */
      93. void MainTask(void) {
      94. GUI_Init();
      95. GUI_Clear();
      96. WM_MULTIBUF_Enable(1);
      97. WM_SetSize(WM_HBKWIN, 320, 240);
      98. //
      99. // Callback for desktop window
      100. //
      101. WM_SetCallback(WM_HBKWIN, _cbBk);
      102. GUI_DrawLine(0, 0, 320, 240);
      103. //
      104. // Create background memdevice
      105. // Fill it with transparency
      106. // Draw circle and tickmarks with semitransparency
      107. //
      108. WM_CreateWindowAsChild(60, 20, 200, 200, WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, _cbWinKnob, 0);
      109. while (1) {
      110. GUI_Delay(50);
      111. }
      112. }
      Display All

      I think it is pretty counterintuitive I guess we will change this in a future version.

      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.