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.
Display All
Using STemWin v5.44.
What am I doing wrong?
Thank you.
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
- #include "DIALOG.h"
- // BMP data
- extern const unsigned char _acbmp1[307254UL + 1];
- extern const unsigned char _acbmp2[307254UL + 1];
- // Pointers for switching BMP data
- const void * _acmemdev1;
- const void * _acmemdev2;
- // Memory devices
- GUI_MEMDEV_Handle hMem1, hMem2;
- // For animation
- int _DoAnimate = 0;
- // Alpha value
- int _Alpha = 0;
- // Button for switching
- BUTTON_Handle hButton;
- // Callback for the BK win
- void _cbBk(WM_MESSAGE * pMsg) {
- switch (pMsg->MsgId) {
- case WM_PAINT:
- GUI_DrawGradientV(0, 0, 319, 239, GUI_WHITE, GUI_DARKMAGENTA);
- GUI_MEMDEV_Write(hMem1);
- break;
- case WM_NOTIFY_PARENT:
- // Do switching animation when the button is released
- if ((pMsg->hWinSrc == hButton) && (pMsg->Data.v == WM_NOTIFICATION_RELEASED)) {
- WM_DisableWindow(hButton);
- _DoAnimate = 1;
- }
- break;
- case WM_TIMER:
- // Animation handler
- if (_DoAnimate == 1) {
- GUI_MEMDEV_Select(hMem1);
- GUI_SetBkColor(GUI_TRANSPARENT);
- GUI_Clear();
- GUI_BMP_Draw(_acmemdev1, 0, 0);
- GUI_MEMDEV_WriteAlpha(hMem2, _Alpha);
- _Alpha += 15;
- // In the end switch BMP data beetween devices and clear alpha
- if (_Alpha == 255) {
- _acmemdev1 = (_acmemdev1 == _acbmp1) ? _acbmp2 : _acbmp1;
- _acmemdev2 = (_acmemdev2 == _acbmp1) ? _acbmp2 : _acbmp1;
- GUI_MEMDEV_Select(hMem1);
- GUI_SetBkColor(GUI_TRANSPARENT);
- GUI_Clear();
- GUI_BMP_Draw(_acmemdev1, 0, 0);
- GUI_MEMDEV_Select(hMem2);
- GUI_BMP_Draw(_acmemdev2, 0, 0);
- WM_EnableWindow(hButton);
- _Alpha = 0;
- _DoAnimate = 0;
- }
- GUI_MEMDEV_Select(0);
- GUI_MEMDEV_Write(hMem1);
- WM_Invalidate(WM_HBKWIN);
- }
- WM_RestartTimer(pMsg->Data.v, 50);
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- void MainTask(void) {
- GUI_Init();
- WM_MULTIBUF_Enable(1);
- // Set callback and timer for BK win
- WM_SetCallback(WM_HBKWIN, _cbBk);
- WM_CreateTimer(WM_HBKWIN, 0, 50, 0);
- // Create memory devices
- hMem1 = GUI_MEMDEV_CreateFixed32(0, 0, 320, 240);
- hMem2 = GUI_MEMDEV_CreateFixed32(0, 0, 320, 240);
- // Set initial BMP data
- _acmemdev1 = _acbmp1;
- _acmemdev2 = _acbmp2;
- // Enable transparency for BMP data
- GUI_BMP_EnableAlpha();
- // Draw BMP data in memory devices
- GUI_MEMDEV_Select(hMem1);
- GUI_SetBkColor(GUI_TRANSPARENT);
- GUI_Clear();
- GUI_BMP_Draw(_acmemdev1, 0, 0);
- GUI_MEMDEV_Select(hMem2);
- GUI_BMP_Draw(_acmemdev2, 0, 0);
- GUI_MEMDEV_Select(0);
- // Create a button for switching
- hButton = BUTTON_CreateEx(120, 200, 100, 20, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_BUTTON0);
- BUTTON_SetText(hButton, "Switch memdevice");
- while (1) {
- GUI_Delay(50);
- }
- }
What am I doing wrong?
Thank you.