How to make transparent dialog box?

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

    • How to make transparent dialog box?

      Hello.

      How to make transparent dialog box (transparent background of client window), created by GUI_CreateDialogBox?
      I used for it the functions WM_SetTransState and WM_SetHasTrans but they give no effect.

      C Source Code

      1. #define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
      2. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      3. { FRAMEWIN_CreateIndirect, "EmptyFramewin", ID_FRAMEWIN_0, 0, 0, 400, 300 },
      4. { TEXT_CreateIndirect, "only text", GUI_ID_TEXT0, 10, 10, 60, 50 },
      5. { BUTTON_CreateIndirect, "click me", GUI_ID_BUTTON0, 10, 40, 50, 20 },
      6. { DROPDOWN_CreateIndirect, "ABCD", GUI_ID_DROPDOWN0, 100, 10, 80, 50 },
      7. };
      8. WM_HWIN CreateFramewin(void) {
      9. WM_HWIN hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      10. FRAMEWIN_SetMoveable(hWin, 1);
      11. WM_SetHasTrans(hWin);
      12. WM_SetTransState(hWin, WM_CF_HASTRANS | WM_CF_CONST_OUTLINE);
      13. return hWin;
      14. }
      Display All
      Should I do something in callback-function of FrameWindow?

      I succeeded to create a window with the transparent background only via WM_CreateWindowAsChild , but I need dialog window (with key TAB).
      Best regards,
      Volodymyr.
    • Sven had told me in another thread I opened to try this
      (although at the time I was trying to use both hardware layers of the lcd controller in my mcu, but I put that aside for now)


      Add a callback function to your frame window, see if it works?

      Source Code

      1. case WM_PAINT:
      2. GUI_SetBkColor(GUI_TRANSPARENT);
      3. GUI_Clear();
      4. break;
      5. default:
      6. WM_DefaultProc(pMsg);
      7. break;
    • MikeFlyersFan wrote:

      Sven had told me in another thread I opened to try this
      (although at the time I was trying to use both hardware layers of the lcd controller in my mcu, but I put that aside for now)


      Add a callback function to your frame window, see if it works?

      Source Code

      1. case WM_PAINT:
      2. GUI_SetBkColor(GUI_TRANSPARENT);
      3. GUI_Clear();
      4. break;
      5. default:
      6. WM_DefaultProc(pMsg);
      7. break;
      I already tried this way, it gives black background, but not transparent.
      I tested it on simulator.

      P.S. There is a way presented by SEGGER, see file ALPHA_TransparentDialog.c (folder Sample\Tutorial), but it uses GUI_SetAlpha() and gives slow refresh on weak ARM-processors without GPU.
      Best regards,
      Volodymyr.

      The post was edited 2 times, last by volodymyr ().

    • Hello,

      try this code. It is for 800x600 screen example.

      C Source Code

      1. #include "DIALOG.h"
      2. #define ID_FRAMEWIN (GUI_ID_USER + 0x00)
      3. FRAMEWIN_Handle hFramewin;
      4. WM_HWIN hClient;
      5. static void _cbBk(WM_MESSAGE * pMsg) {
      6. switch (pMsg->MsgId) {
      7. case WM_PAINT:
      8. GUI_DrawGradientV(0, 0, 799, 299, GUI_MAKE_COLOR(GUI_LIGHTRED), GUI_MAKE_COLOR(GUI_LIGHTBLUE));
      9. GUI_DrawGradientV(0, 300, 799, 599, GUI_MAKE_COLOR(GUI_LIGHTBLUE), GUI_MAKE_COLOR(GUI_LIGHTGREEN));
      10. break;
      11. default:
      12. WM_DefaultProc(pMsg);
      13. break;
      14. }
      15. }
      16. void MainTask(void) {
      17. GUI_Init();
      18. WM_MULTIBUF_Enable(1);
      19. WM_SetCallback(WM_HBKWIN, _cbBk);
      20. hFramewin = FRAMEWIN_CreateEx(0, 0, 320, 240, WM_HBKWIN, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, ID_FRAMEWIN, "Framewin", NULL);
      21. FRAMEWIN_SetClientColor(hFramewin, GUI_INVALID_COLOR);
      22. hClient = WM_GetClientWindow(hFramewin);
      23. WM_SetHasTrans(hClient);
      24. while(1)
      25. {
      26. GUI_Delay(50);
      27. }
      28. }
      Display All
      Alex.
    • LexaGb wrote:

      Hello,

      try this code. It is for 800x600 screen example.

      C Source Code

      1. #include "DIALOG.h"
      2. #define ID_FRAMEWIN (GUI_ID_USER + 0x00)
      3. FRAMEWIN_Handle hFramewin;
      4. WM_HWIN hClient;
      5. static void _cbBk(WM_MESSAGE * pMsg) {
      6. switch (pMsg->MsgId) {
      7. case WM_PAINT:
      8. GUI_DrawGradientV(0, 0, 799, 299, GUI_MAKE_COLOR(GUI_LIGHTRED), GUI_MAKE_COLOR(GUI_LIGHTBLUE));
      9. GUI_DrawGradientV(0, 300, 799, 599, GUI_MAKE_COLOR(GUI_LIGHTBLUE), GUI_MAKE_COLOR(GUI_LIGHTGREEN));
      10. break;
      11. default:
      12. WM_DefaultProc(pMsg);
      13. break;
      14. }
      15. }
      16. void MainTask(void) {
      17. GUI_Init();
      18. WM_MULTIBUF_Enable(1);
      19. WM_SetCallback(WM_HBKWIN, _cbBk);
      20. hFramewin = FRAMEWIN_CreateEx(0, 0, 320, 240, WM_HBKWIN, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, ID_FRAMEWIN, "Framewin", NULL);
      21. FRAMEWIN_SetClientColor(hFramewin, GUI_INVALID_COLOR);
      22. hClient = WM_GetClientWindow(hFramewin);
      23. WM_SetHasTrans(hClient);
      24. while(1)
      25. {
      26. GUI_Delay(50);
      27. }
      28. }
      Display All
      Alex.


      LexaGb, you are simply the best.

      These three lines of code give so elegant solution of this problem, that I have no words.
      It is the best solution of this issue without using any callbacks and so on.


      Thank you very much.
      Best regards,
      Volodymyr.

      The post was edited 2 times, last by volodymyr ().

    • Hi All,

      Unfortunately, it is not mentioned in the manual (I'm sorry will be added) that GUI_INVALID_COLOR is used for transparent background of some widgets (of course the WM_CF_HASTRANS flag has to be set). In the default callback of e.g. a WINDOW widget we check if the background color is GUI_INVALID_COLOR. If it is we simply do nothing and leave the background (drawn by the window in the background) untouched.

      If you overwrite the callback of a widget which should be transparent, for example a button, simply don't draw the entire area of the button. A call of

      Source Code

      1. case WM_PAINT:
      2. GUI_SetBkColor(GUI_TRANSPARENT);
      3. GUI_Clear();
      4. break;
      would clear the area with that "color" and would also erase the already drawn background.

      For example, a transparent button with only a red circle in it would look like this:


      C Source Code

      1. case WM_PAINT:
      2. GUI_SetColor(GUI_RED);
      3. GUI_DrawCircle(40, 10, 5);
      4. break;
      Regards,
      Sven