Lost alpha value

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

    • Lost alpha value

      Hello,

      I'm working with memory devices and trying to switch one memory device into another on the screen using GUI_MEMDEV_WriteAlpha() (non-blocking method).

      Each device is filled with BMP data (32bit with alpha created with Bitmap Converter then converted with Bin2C).

      The problem is that when switching animation is starting alpha value is lost (background gradient is not visible).

      Here is the small example. BMP data in attach.

      C Source Code: Main.c

      1. #include "DIALOG.h"
      2. // BMP data
      3. extern const unsigned char _acbmp1[307254UL + 1];
      4. extern const unsigned char _acbmp2[307254UL + 1];
      5. // Pointers for switching BMP data
      6. const void * _acmemdev1;
      7. const void * _acmemdev2;
      8. // Memory devices
      9. GUI_MEMDEV_Handle hMem1, hMem2;
      10. // For animation
      11. int _DoAnimate = 0;
      12. // Alpha value
      13. int _Alpha = 0;
      14. // Button for switching
      15. BUTTON_Handle hButton;
      16. // Callback for the BK win
      17. void _cbBk(WM_MESSAGE * pMsg) {
      18. switch (pMsg->MsgId) {
      19. case WM_PAINT:
      20. GUI_DrawGradientV(0, 0, 319, 239, GUI_WHITE, GUI_DARKMAGENTA);
      21. GUI_MEMDEV_Write(hMem1);
      22. break;
      23. case WM_NOTIFY_PARENT:
      24. // Do switching animation when the button is released
      25. if ((pMsg->hWinSrc == hButton) && (pMsg->Data.v == WM_NOTIFICATION_RELEASED)) {
      26. WM_DisableWindow(hButton);
      27. _DoAnimate = 1;
      28. }
      29. break;
      30. case WM_TIMER:
      31. // Animation handler
      32. if (_DoAnimate == 1) {
      33. GUI_MEMDEV_Select(hMem1);
      34. GUI_SetBkColor(GUI_TRANSPARENT);
      35. GUI_Clear();
      36. GUI_BMP_Draw(_acmemdev1, 0, 0);
      37. GUI_MEMDEV_WriteAlpha(hMem2, _Alpha);
      38. _Alpha += 15;
      39. // In the end switch BMP data beetween devices and clear alpha
      40. if (_Alpha == 255) {
      41. _acmemdev1 = (_acmemdev1 == _acbmp1) ? _acbmp2 : _acbmp1;
      42. _acmemdev2 = (_acmemdev2 == _acbmp1) ? _acbmp2 : _acbmp1;
      43. GUI_MEMDEV_Select(hMem1);
      44. GUI_SetBkColor(GUI_TRANSPARENT);
      45. GUI_Clear();
      46. GUI_BMP_Draw(_acmemdev1, 0, 0);
      47. GUI_MEMDEV_Select(hMem2);
      48. GUI_BMP_Draw(_acmemdev2, 0, 0);
      49. WM_EnableWindow(hButton);
      50. _Alpha = 0;
      51. _DoAnimate = 0;
      52. }
      53. GUI_MEMDEV_Select(0);
      54. GUI_MEMDEV_Write(hMem1);
      55. WM_Invalidate(WM_HBKWIN);
      56. }
      57. WM_RestartTimer(pMsg->Data.v, 50);
      58. break;
      59. default:
      60. WM_DefaultProc(pMsg);
      61. break;
      62. }
      63. }
      64. void MainTask(void) {
      65. GUI_Init();
      66. WM_MULTIBUF_Enable(1);
      67. // Set callback and timer for BK win
      68. WM_SetCallback(WM_HBKWIN, _cbBk);
      69. WM_CreateTimer(WM_HBKWIN, 0, 50, 0);
      70. // Create memory devices
      71. hMem1 = GUI_MEMDEV_CreateFixed32(0, 0, 320, 240);
      72. hMem2 = GUI_MEMDEV_CreateFixed32(0, 0, 320, 240);
      73. // Set initial BMP data
      74. _acmemdev1 = _acbmp1;
      75. _acmemdev2 = _acbmp2;
      76. // Enable transparency for BMP data
      77. GUI_BMP_EnableAlpha();
      78. // Draw BMP data in memory devices
      79. GUI_MEMDEV_Select(hMem1);
      80. GUI_SetBkColor(GUI_TRANSPARENT);
      81. GUI_Clear();
      82. GUI_BMP_Draw(_acmemdev1, 0, 0);
      83. GUI_MEMDEV_Select(hMem2);
      84. GUI_BMP_Draw(_acmemdev2, 0, 0);
      85. GUI_MEMDEV_Select(0);
      86. // Create a button for switching
      87. hButton = BUTTON_CreateEx(120, 200, 100, 20, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_BUTTON0);
      88. BUTTON_SetText(hButton, "Switch memdevice");
      89. while (1) {
      90. GUI_Delay(50);
      91. }
      92. }
      Display All
      Using STemWin v5.44.

      What am I doing wrong?

      Thank you.
      Files
      • bmpdata.zip

        (61.69 kB, downloaded 421 times, last: )