Memory Devices and the Window Manager

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

  • Memory Devices and the Window Manager

    Dear emWin-users,

    once again I would like to ask you for some help.
    Let's ignore the issues, caused by lack of allocated memory, hardware problems etc. My question only refers to the way I use Memory Device (to display a .gif on the LCD) with Window Manager (some buttons here). So I have 3 main steps:


    1: Let`s call this function _DemoMemDev:

    static void _DemoMemDev(void) {


    GUI_MEMDEV_Handle hMem;



    //
    // Create the memory device
    //
    hMem = GUI_MEMDEV_Create(0,0,800,480);
    // // Activate it //
    GUI_MEMDEV_Select(hMem);


    //
    // Drawing operations to the memory device
    //

    GUI_GIF_DrawEx(APP_GetData, &fil8, 0, 0); // (APP_GetData and fil8 defined, everything works fine ( from an external SD-card))


    //
    // Routes the drawing operations to the LCD
    //
    GUI_MEMDEV_CopyToLCDAt(hMem,0,0);


    2: Lets call this function _cbMenuDialog:
    I will suppress it a little bit, no big deal here:

    static void _cbMenuDialog(WM_MESSAGE * pMsg) {

    ......
    case WM_PAINT:

    break;
    case WM_INIT_DIALOG:
    break;...... default: WM_DefaultProc(pMsg); break;
    }

    3. Last function CreateMenuWindow:


    void CreateMenuWindow(void) {



    WM_HWIN welcome_menu_screen;

    welcome_menu_screen = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbMenuDialog, WM_HBKWIN, 0, 0); //_aDialogCreate with WINDOW_CreateIndirect & some BUTTON_CreateIndirect...
    }


    I need your advice how to order the function and where to call them respectively? The .gif file should be redrawn only once, and not every time (like in WM_PAINT). But the buttons on the screen should remain and change after pressing on them etc. Can you help me with this ?


    Many thanks
    Ivo
  • Hi,

    If I get you right you don't want the whole dialog getting redrawn if a button gets pressed.

    Try to create the buttons with the flag WM_CF_CONST_OUTLINE or, if the buttons are getting created through a dialog, use WM_SetTransState(WM_CF_CONST_OUTLINE). This will prevent the background from being redrawn.

    Please give the code below a try to see the difference. Each time the back ground (or a part of it) gets redrawn it changes the color. Set '#if 0' to 1 to see the difference.

    C Source Code

    1. #include "DIALOG.h"
    2. /*********************************************************************
    3. *
    4. * Defines
    5. *
    6. **********************************************************************
    7. */
    8. /*********************************************************************
    9. *
    10. * Static data
    11. *
    12. **********************************************************************
    13. */
    14. /*********************************************************************
    15. *
    16. * Static code
    17. *
    18. **********************************************************************
    19. */
    20. /*********************************************************************
    21. *
    22. * _cbBk
    23. */
    24. static void _cbBk(WM_MESSAGE * pMsg) {
    25. int NCode;
    26. int Id;
    27. static int Index;
    28. WM_HWIN hItem;
    29. GUI_COLOR aColor[] = {GUI_RED, GUI_GREEN, GUI_BLUE};
    30. switch (pMsg->MsgId) {
    31. case WM_CREATE:
    32. #if 0
    33. BUTTON_CreateAsChild( 10, 10, 80, 20, pMsg->hWin, GUI_ID_BUTTON0, WM_CF_SHOW | WM_CF_CONST_OUTLINE);
    34. BUTTON_CreateAsChild(200, 10, 80, 20, pMsg->hWin, GUI_ID_BUTTON0, WM_CF_SHOW | WM_CF_CONST_OUTLINE);
    35. BUTTON_CreateAsChild(200, 200, 80, 20, pMsg->hWin, GUI_ID_BUTTON0, WM_CF_SHOW | WM_CF_CONST_OUTLINE);
    36. #else
    37. BUTTON_CreateAsChild( 10, 10, 80, 20, pMsg->hWin, GUI_ID_BUTTON0, WM_CF_SHOW);
    38. BUTTON_CreateAsChild(200, 10, 80, 20, pMsg->hWin, GUI_ID_BUTTON0, WM_CF_SHOW);
    39. BUTTON_CreateAsChild(200, 200, 80, 20, pMsg->hWin, GUI_ID_BUTTON0, WM_CF_SHOW);
    40. #endif
    41. break;
    42. case WM_PAINT:
    43. GUI_SetBkColor(aColor[Index++]);
    44. Index = (Index == GUI_COUNTOF(aColor)) ? 0 : Index;
    45. GUI_Clear();
    46. break;
    47. default:
    48. WM_DefaultProc(pMsg);
    49. break;
    50. }
    51. }
    52. /*********************************************************************
    53. *
    54. * Public code
    55. *
    56. **********************************************************************
    57. */
    58. /*********************************************************************
    59. *
    60. * MainTask
    61. */
    62. void MainTask(void) {
    63. WM_HWIN hButton;
    64. GUI_Init();
    65. WM_CreateWindowAsChild(0, 0, 480, 272, WM_HBKWIN, WM_CF_SHOW, _cbBk, 0);
    66. while (1) {
    67. GUI_Delay(100);
    68. }
    69. }
    70. /*************************** End of file ****************************/
    Display All


    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.
  • Hi Sven,

    Thank you so much for your continuous support. The drawing performance increased significantly by adding "WM_SetTransState".

    May I use the opportunity to ask you one further thing: is this order correct , when I am trying to combine WM_SetTransState with transparent Button_Widged ? I am creating the buttons through a dialog. Making them Transparent worked till now OK, but since I added WM_SetTransState(hItem, WM_CF_CONST_OUTLINE) the transparency behavior changed.

    in:
    case WM_INIT_DIALOG:

    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
    WM_SetHasTrans(hItem);
    WM_SetTransState(hItem, WM_CF_CONST_OUTLINE);
    WM_SetCallback(hItem, _cbButton_1);// _cbButton_1 is an additional function , nothing in WM_PAINT, nothing in WM_INIT_DIALOG
    break;
  • Hi,

    Try to use only WM_SetTransState(hItem, WM_CF_HASTRANS | WM_CF_CONST_OUTLINE). Also there is no need for WM_SetHasTrans() any longer.

    With WM_SetHasTrans(hItem) the transparency flag gets set. But by a call of WM_SetTransState(hItem, WM_CF_CONST_OUTLINE) the transparency flag gets overwritten and only WM_CF_CONST_OUTLINE will be left.

    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.
  • Dear Sven,

    unfortunately WM_SetTransState(hItem, WM_CF_HASTRANS | WM_CF_CONST_OUTLINE) does not make the button transparent.






    static void _cbButton1(WM_MESSAGE * pMsg) {
    WM_HWIN hItem;
    switch (pMsg->MsgId) {
    case WM_PAINT:
    break;

    case WM_INIT_DIALOG:
    break;
    default:
    BUTTON_Callback(pMsg);
    break;
    }
    }


    ......................in the cbDialog after that :




    case WM_INIT_DIALOG:



    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
    WM_SetTransState(hItem, WM_CF_CONST_OUTLINE | WM_CF_HASTRANS);
    WM_SetCallback(hItem, _cbButton1);


    Is it something wrong hier ?
    Thanks
  • Hi,

    I did a test and the buttons are getting invisible. I did it the same way as you. Attached is the code I used for this. The button in the middle will be transparent.

    Regards,
    Sven
    Files
    • ButtonTrans.zip

      (1.1 kB, downloaded 326 times, last: )
    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.
  • Dear Sven,

    with the risk of being annoying I really do not understand the behavior of the WM_CF_CONST_OUTLINE and need your continuous help here.
    I asked you all this questions because I just wanted to have my application to operate a bit faster ( like for example when you press on a button that the button reacts faster and respectively goes faster in the another menu (for example)).
    The slow process was caused as you explained to me because all the windows had to be redrawn in WM_PAINT after some action occurs. But after you told me to use WM_CF_CONST_OUTLINE everything works much faster. I observed it mostly there, where I have a button, after which an invisible window is refreshed (WM_Invalidate(hwin)), so a value which is normally shown on this place is changing. So I press the button, hwin = WM_CreateWindowAsChild is invalidated.
    ( WM_Invalidate(hwin)). See pictures...


    But now:

    I just tried to put a global WM_SetCreateFlags(WM_CF_CONST_OUTLINE) before GUI_Init(). So in main.c I have:

    ....
    WM_SetCreateFlags(WM_CF_MEMDEV | WM_CF_CONST_OUTLINE);
    GUI_Init();
    GUI_Initialized = 1;
    ....


    I assume it means the flag is now set for all windows in my application. And in my application I have Buttons ( what we already discussed) and some Windows ( some of them are invisible as I said).
    Here an example:

    ...........
    main_screen = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbMainDialog, WM_HBKWIN, 0, 0);

    values_main_screen = WM_CreateWindowAsChild(0, 0, 50, 50, main_screen, WM_CF_SHOW | WM_CF_MEMDEV | WM_CF_HASTRANS, _cbMainWindowValues, 0); --> // here values are displayed and respectively changing, so I need to refresh this invisible window when a change occurs, for example when I press on a button.

    .............

    After starting the application everything runs normally. But after pressing on a button, it really reacts super fast, but look how it stays, like it is refreshed but not transparent anymore...

    Do u have an example with Windows, Childwindows (transparent) and buttons, where this WM_CF_CONST_OUTLINE for all the widgets is used. I cannot reproduce this behavior!


    Thank you a lot!



    Images
    • 1.jpg

      141.97 kB, 1,024×355, viewed 465 times
    • 2.jpg

      119.31 kB, 1,024×522, viewed 460 times
  • Hi,

    I guess you are using WM_CF_MEMDEV to avoid flickering. Unfortunately, this is not the best way since it might slow down the application and requires some memory.

    Depending on the driver there are other options.
    If you use the GUIDRV_Lin driver I would recommend to use multibuffering instead of the flag WM_CF_MEMDEV. This will speed up the application, too.
    If you use GUIDRV_FlexColor try using a cached version of the driver.

    Use WM_CF_CONST_OUTLINE carefully. Do not use it global. If you use you better set it manually. This will make sure that a widget/windows has this flag not set accidentally.

    Maybe you can update the values without a transparent window. Depending on the background (it doesn't change and no fancy gradients) it can make more sense to have an opaque window. This will save further resources and takes less time when it gets updated.

    You application seems that there is no real need for transparency.

    Attached is an example which should show something like you want (of course in a pretty simple way) might be achieved.

    Regards,
    Sven
    Files
    • Sample.zip

      (1.53 kB, downloaded 360 times, last: )
    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.