[Solved] Alpha blending with text widget

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

  • [Solved] Alpha blending with text widget

    I was trying Alpha blending effect. i tried 2 approaches , one without any window and other with window. I was successful to make alpha blending effect without window however i failed to do it with window and text widget. Here text is not mixed with the background.

    For without window operation i used following code snippet and it worked. Image is attached :


    C Source Code

    1. GUI_SetColor(GUI_WHITE);
    2. GUI_SetFont(&GUI_Font24B_ASCII);
    3. GUI_DispStringHCenterAt("Maria Jos \n ID= 24358915 \n Duration=21:45 \nAge =45", 100, 120);
    4. GUI_SetColor(GUI_RED);
    5. for (i = 0; i < 100; i++)
    6. {
    7. U8 Alpha;
    8. Alpha = (i * 255 / 100);
    9. GUI_SetAlpha(Alpha);
    10. GUI_DrawHLine(240 - i, 0, 320);
    11. }
    12. GUI_SetAlpha(0);
    Display All


    code for "with window" operation is attached. Can anybody help me to achieve the alpha blending for text widget on a window created by dialogue box ?
    Images
    • Alpha_withoutWindow.png

      2.84 kB, 320×240, viewed 408 times
    Files

    The post was edited 1 time, last by amit251291 ().

  • Hello amit,

    please try the following:

    C Source Code

    1. #include "DIALOG.h"
    2. /*********************************************************************
    3. *
    4. * _cbWindow
    5. */
    6. static void _cbWindow (WM_MESSAGE * pMsg) {
    7. GUI_RECT Rect;
    8. switch (pMsg->MsgId) {
    9. case WM_PAINT:
    10. GUI_SetBkColor(GUI_BLACK);
    11. GUI_Clear();
    12. GUI_SetColor(GUI_WHITE);
    13. GUI_SetTextMode(GUI_TM_TRANS);
    14. GUI_DispString("Test\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\n");
    15. WM_GetClientRect(&Rect);
    16. GUI_EnableAlpha(1);
    17. GUI_DrawGradientV(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_TRANSPARENT, GUI_RED);
    18. GUI_EnableAlpha(0);
    19. return;
    20. }
    21. }
    22. /*********************************************************************
    23. *
    24. * _cbBk
    25. */
    26. static void _cbBk(WM_MESSAGE * pMsg) {
    27. int xSize;
    28. int ySize;
    29. switch (pMsg->MsgId) {
    30. case WM_PAINT:
    31. xSize = LCD_GetXSize();
    32. ySize = LCD_GetYSize();
    33. GUI_DrawGradientH(0, 0, xSize, ySize, GUI_BLACK, GUI_GRAY);
    34. break;
    35. }
    36. }
    37. /*********************************************************************
    38. *
    39. * MainTask
    40. */
    41. void MainTask(void) {
    42. GUI_Init();
    43. WM_SetCallback(WM_HBKWIN, _cbBk);
    44. WINDOW_CreateEx(0, 0, 200, 200, WM_HBKWIN, WM_CF_SHOW, 0x0, 0, _cbWindow);
    45. while (1) {
    46. GUI_Delay(10);
    47. }
    48. }
    Display All


    Regards,
    Sven