Drawing in Windows / Widget

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

  • Drawing in Windows / Widget

    I've been trying to understand how to draw something in a window. I have a STM32F746G-Disco board and started with the STemWin Hello World example. Currently I have used the GUIBuilder to create a Window and inside that window are some images. Which creates this:

    C Source Code

    1. WM_HWIN CreateWindow(void);
    2. WM_HWIN CreateWindow(void) {
    3. WM_HWIN hWin;
    4. hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    5. return hWin;
    6. }


    Along with the associated callback function _cbDialog to initiate and "set" the images, which displays correctly.

    I have also implemented touch and would like for some actions to happen when they are pressed, so I have added

    C Source Code

    1. case WM_NOTIFICATION_CLICKED:


    in my switch case statement for the callback _cbDialog, similar to how a button works. This works for manipulating the images that already exists in the window (redrawing them, set to top, etc).

    I now would like to draw a line, or display text. This is where it gets fuzzy for me. Looking at the manual and searches on the forum, it seems I should add the WM_PAINT case to the callback and call a draw function in there. So I try

    C Source Code

    1. case WM_PAINT:
    2. GUI_DispStringAt("Hello world",0,0);
    3. break;
    4. default:
    5. ...

    but it does not get displayed.

    I have looked at: Drawing over widgets , Paint text on top of all existing dialog windows , and Cannot execute line drawing functions in any other window other than the Desktop Window. . I have read through the manual and have not been able to find my answer.

    When debugging, I see that it is getting to the WM_NOTIFICATION_CLICKED and WM_PAINT, so they are being reached.

    Is there any examples that show how to properly implement this?

    Thank you,
    amorgan
  • From my testing and reading through of the manual I have found that there is one primary window and then any other window created after that summarized (by me) here:

    Possible Windows:
    1. Background / Desktop Window (WM_HBKWIN)
    • a. This is where any text or 2D graphics draw functions will be normally drawn
    • b. The z-position of this window cannot be changed
    2. Any Window / Widget created
    • a. All Windows have a z-position that is stacked in the order of creation
    • b. All Windows can have children, which also are given a z-position stacked in the order of creation
    • c. The z-position can be manipulated by WM_* functions, such as WM_BringToTop()
    • d. The GUIBuilder uses a Dialog Box for a Window that has Widget(s) as children

    Therefore what that means is that any draw functions that want to be used with a Widget / Window, needs to be called inside the case WM_PAINT of a widgets callback function (Note 1), which will be clipped by the window's / widget's defined area, otherwise it will get drawn on the Background / Desktop Window and has a change to be drawn over top of.

    Can you verify if these assumption / findings are correct?

    It then seems to be possible to create a transparent Window that has been brought to the front in order to draw on the most top layer, but I will need to verify this.

    Note1: Refer to STemwin528, page 435 17.8 example for assigning a callback function

    The post was edited 3 times, last by amorganPD ().

  • Hi amorgan,

    Your assumptions are correct.

    I have attached a quick sample which should show how to draw in a window.
    Drawing into the 'main window' of the dialog and into a window created as child of this dialog.

    Regards,
    Sven
    Files
    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.