Hello to everyone,
I have a question implementing a listwheel with semitransparent rounded rect as a background.
Here is the code for 320 * 240 desktop:
Display All
All is ok until listwheel reacts on moving. Then it loses transparency.
It is solved with using a memory device:
Display All
Now all is ok. But why it is not working when drawing "on the run"?
Thanks,
Alex.
I have a question implementing a listwheel with semitransparent rounded rect as a background.
Here is the code for 320 * 240 desktop:
C Source Code
- #include "DIALOG.h"
- // Listwheel and its items
- LISTWHEEL_Handle hLstw;
- const GUI_ConstString pItems[] = { "10", "20", "30", "40", "50" };
- // Draw some data on the desktop
- void _cbBk(WM_MESSAGE * pMsg) {
- switch (pMsg->MsgId) {
- case WM_PAINT:
- GUI_SetBkColor(GUI_DARKBLUE);
- GUI_Clear();
- GUI_SetFont(GUI_FONT_8X16X3X3);
- GUI_DispStringHCenterAt("Background", 160, 100);
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- // Draw green semitransparent rounded rect as a background of the listwheel
- int _LISTWHEEL_Draw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
- switch (pDrawItemInfo->Cmd) {
- case WIDGET_ITEM_DRAW_BACKGROUND:
- GUI_EnableAlpha(1);
- GUI_SetColor((0x80uL << 24) | GUI_GREEN);
- GUI_AA_FillRoundedRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, 5);
- GUI_EnableAlpha(0);
- break;
- default:
- return LISTWHEEL_OwnerDraw(pDrawItemInfo);
- break;
- }
- return 0;
- }
- void MainTask(void) {
- GUI_Init();
- WM_MULTIBUF_Enable(1);
- WM_SetSize(WM_HBKWIN, 320, 240);
- // Set desktop callback
- WM_SetCallback(WM_HBKWIN, _cbBk);
- // Create a listwheel, set some parameters and owner draw function
- hLstw = LISTWHEEL_CreateEx(110, 40, 100, 160, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_LISTWHEEL0, pItems);
- LISTWHEEL_SetFont(hLstw, GUI_FONT_32_ASCII);
- LISTWHEEL_SetTextAlign(hLstw, GUI_TA_HCENTER | GUI_TA_VCENTER);
- LISTWHEEL_SetTextColor(hLstw, LISTWHEEL_CI_UNSEL, GUI_LIGHTGRAY);
- LISTWHEEL_SetTextColor(hLstw, LISTWHEEL_CI_SEL, GUI_DARKBLUE);
- LISTWHEEL_SetOwnerDraw(hLstw, _LISTWHEEL_Draw);
- WM_SetHasTrans(hLstw);
- while (1) {
- GUI_Delay(50);
- }
- }
It is solved with using a memory device:
C Source Code
- #include "DIALOG.h"
- // Listwheel and its items
- LISTWHEEL_Handle hLstw;
- const GUI_ConstString pItems[] = { "10", "20", "30", "40", "50" };
- // Memory device for the background
- GUI_MEMDEV_Handle hMem;
- // Draw some data on the desktop
- void _cbBk(WM_MESSAGE * pMsg) {
- switch (pMsg->MsgId) {
- case WM_PAINT:
- GUI_SetBkColor(GUI_DARKBLUE);
- GUI_Clear();
- GUI_SetFont(GUI_FONT_8X16X3X3);
- GUI_DispStringHCenterAt("Background", 160, 100);
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- // Draw green semitransparent rounded rect as a background of the listwheel from the memory device
- int _LISTWHEEL_Draw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
- switch (pDrawItemInfo->Cmd) {
- case WIDGET_ITEM_DRAW_BACKGROUND:
- GUI_MEMDEV_WriteAt(hMem, 110, 40);
- break;
- default:
- return LISTWHEEL_OwnerDraw(pDrawItemInfo);
- break;
- }
- return 0;
- }
- void MainTask(void) {
- GUI_Init();
- WM_MULTIBUF_Enable(1);
- WM_SetSize(WM_HBKWIN, 320, 240);
- // Set desktop callback
- WM_SetCallback(WM_HBKWIN, _cbBk);
- // Create a memory device and draw green semitransparent rounded rect in there
- hMem = GUI_MEMDEV_CreateFixed32(0, 0, 100, 160);
- GUI_MEMDEV_Select(hMem);
- GUI_SetBkColor(GUI_TRANSPARENT);
- GUI_Clear();
- GUI_PreserveTrans(1);
- GUI_SetColor((0x80uL << 24) | GUI_GREEN);
- GUI_AA_FillRoundedRect(0, 0, 99, 159, 5);
- GUI_PreserveTrans(0);
- GUI_MEMDEV_Select(0);
- // Create a listwheel, set some parameters and owner draw function
- hLstw = LISTWHEEL_CreateEx(110, 40, 100, 160, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_LISTWHEEL0, pItems);
- LISTWHEEL_SetFont(hLstw, GUI_FONT_32_ASCII);
- LISTWHEEL_SetTextAlign(hLstw, GUI_TA_HCENTER | GUI_TA_VCENTER);
- LISTWHEEL_SetTextColor(hLstw, LISTWHEEL_CI_UNSEL, GUI_LIGHTGRAY);
- LISTWHEEL_SetTextColor(hLstw, LISTWHEEL_CI_SEL, GUI_DARKBLUE);
- LISTWHEEL_SetOwnerDraw(hLstw, _LISTWHEEL_Draw);
- WM_SetHasTrans(hLstw);
- while (1) {
- GUI_Delay(50);
- }
- }
Thanks,
Alex.
The post was edited 2 times, last by LexaGB ().