Frame window popup

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

  • Frame window popup

    In my project I'm implementing frame windows using FRAMEWIN acting as popup windows. I mean, I'm keeping the main windows on the background and creating a FRAMEWIN on the foreground and giving it focus.

    My main problem is that I need to make the background window less "bright", so the user can see clearly that the focus is on the FRAMEWIN and won't try using the background buttons and such.

    Is there a way to do this without resorting to using multi layers? Or can anyone see a different approach to this problem?

    Thanks for your time
  • Hello Damaso,

    I have created a short sample which shows how to blend the background of a window (please see below).
    This is done by using memory devices and no multi layers are required.

    C Source Code

    1. #include "DIALOG.h"
    2. /*********************************************************************
    3. *
    4. * _cbBk
    5. */
    6. static void _cbBk(WM_MESSAGE * pMsg) {
    7. int xSize, ySize;
    8. switch (pMsg->MsgId) {
    9. case WM_PAINT:
    10. xSize = LCD_GetXSize();
    11. ySize = LCD_GetYSize();
    12. GUI_DrawGradientV(0, 0, xSize - 1, ySize / 2, GUI_BLUE, GUI_DARKBLUE);
    13. GUI_DrawGradientV(0, ySize / 2, xSize - 1, ySize - 1, GUI_DARKBLUE, GUI_BLUE);
    14. break;
    15. default:
    16. WM_DefaultProc(pMsg);
    17. }
    18. }
    19. /*********************************************************************
    20. *
    21. * _cbWin
    22. */
    23. static void _cbWin(WM_MESSAGE * pMsg) {
    24. switch (pMsg->MsgId) {
    25. case WM_PAINT:
    26. GUI_SetBkColor(GUI_WHITE);
    27. GUI_Clear();
    28. break;
    29. default:
    30. WM_DefaultProc(pMsg);
    31. }
    32. }
    33. /*********************************************************************
    34. *
    35. * MainTask
    36. */
    37. void MainTask(void) {
    38. BUTTON_Handle hButton0, hButton1;
    39. FRAMEWIN_Handle hFrameWin;
    40. int Pressed;
    41. GUI_RECT Rect;
    42. GUI_Init();
    43. //
    44. // Set a callback to handle drawing of the background
    45. //
    46. WM_SetCallback(WM_HBKWIN, _cbBk);
    47. //
    48. // Create two buttons
    49. //
    50. hButton0 = BUTTON_CreateAsChild(20, LCD_GetYSize() - 100, 80, 20, WM_HBKWIN, 0, WM_CF_SHOW);
    51. hButton1 = BUTTON_CreateAsChild(120, LCD_GetYSize() - 100, 80, 20, WM_HBKWIN, 0, WM_CF_SHOW);
    52. //
    53. // And set some text
    54. //
    55. BUTTON_SetText(hButton0, "PopUp - Blend");
    56. BUTTON_SetText(hButton1, "PopUp - Blur");
    57. //
    58. // Init Pressed variable. Its purpose is to determine if we need to restore the background.
    59. //
    60. Pressed = 0;
    61. while (1) {
    62. if (BUTTON_IsPressed(hButton0)) {
    63. //
    64. // If "button is pressed create a window
    65. //
    66. hFrameWin = FRAMEWIN_CreateAsChild(10, 10, 100, 100, WM_HBKWIN, "PopUp", _cbWin, WM_CF_SHOW);
    67. //
    68. // Set Focus on the created window
    69. //
    70. WM_SetFocus(hFrameWin);
    71. //
    72. // Make modal, no other windows (including buttons) can be pressed
    73. //
    74. WM_MakeModal(hFrameWin);
    75. //
    76. // Tell emWin that the button is valid. We have to do this because the call of WM_SetFocus(hFrameWin) invalidates the button.
    77. // This would lead to an un-blended button.
    78. //
    79. WM_ValidateWindow(hButton0);
    80. //
    81. // Finally, blend the background of the popup window.
    82. // hFrameWin -> handle to the window whose background should be blended
    83. // 1000 -> duration for blending process in ms
    84. // GUI_BLACK -> the color to be used for blending
    85. // 0x80 -> how much should be blended. A value up to 0xFF
    86. //
    87. GUI_MEMDEV_BlendWinBk(hFrameWin, 1000, GUI_BLACK, 0x80);
    88. Pressed = 1;
    89. } else if (BUTTON_IsPressed(hButton1)) {
    90. //
    91. // Almost the same as before.
    92. //
    93. hFrameWin = FRAMEWIN_CreateAsChild(10, 10, 100, 100, WM_HBKWIN, "PopUp", _cbWin, WM_CF_SHOW);
    94. WM_SetFocus(hFrameWin);
    95. WM_MakeModal(hFrameWin);
    96. WM_ValidateWindow(hButton1);
    97. //
    98. // Instead of blending, we blur the background.
    99. // hFrameWin -> handle to the window whose background should be blured
    100. // 1000 -> duration for blending process in ms
    101. // 4 -> depth of bluring
    102. //
    103. GUI_MEMDEV_BlurWinBk(hFrameWin, 1000, 4);
    104. Pressed = 1;
    105. }
    106. if (Pressed) {
    107. //
    108. // Wait 5 sec and restore
    109. //
    110. GUI_Delay(5000);
    111. //
    112. // Delete the popup
    113. //
    114. WM_DeleteWindow(hFrameWin);
    115. //
    116. // To make sure that all buttons get restored, too, we retrieve the area of the BK-window and invalidate it.
    117. //
    118. WM_GetWindowRectEx(WM_HBKWIN, &Rect);
    119. WM_InvalidateArea(&Rect);
    120. Pressed = 0;
    121. }
    122. GUI_Delay(10);
    123. }
    124. }
    Display All


    Best regards,
    Sven
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.