Drawing in a child window using primitive drawing functions (Draw line, Circle, etc...)

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

    • Drawing in a child window using primitive drawing functions (Draw line, Circle, etc...)

      Hi,

      I created a child window:
      WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbBk, 0);

      and I want to draw in this child window using primitive drawing functions (Draw line, Circle, etc...).
      Q1: How can I do that?
      Q2: Will the callback function "cbBk" of my child Window also update the drawings as I change them based on external inputs?

      Thanks
      E4M
    • Hi,

      you can only draw in the WM_PAINT case of the _cbBk callback routine. All of the drawing has to be done there.

      Redrawing windows can be done at any time by simply calling WM_InvalidateWindow().

      Best regards,

      Florian
      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 Florian,

      Thanks for the tips. I tried that but as I drew, within the WM_PAINT case, the vertical line got drawn in the background window (so behind the child window see attached snapshot). I want to draw inside the childwindow and I want the callback of the child window to refresh the dynamic line drawing changes.

      Looking at the attached picture, the line should have been drawn inside the child window (red box) and clipped from the mid-screen to the bottom of the screen since that is outside of the child window.

      But one can see that for y = 10 to y = LCD_GetYSize() >> 1 (=136) the line is "behind" the child window.

      LCD_GetXSize() is 480
      LCD_GetYSize() is 272

      static void _cbBk(WM_MESSAGE * pMsg) {
      ...

      case WM_PAINT:
      GUI_DrawVLine(Value, 10, 272);
      ...
      }

      void MainTask(void) {
      ...
      WM_CreateWindowAsChild(LCD_GetXSize() >> 1, 0, LCD_GetXSize() >> 1, LCD_GetYSize() >> 1, WM_HBKWIN, WM_CF_SHOW, _cbBk, 0);
      ...
      }

      Thanks a bunch!
      E4M
      Images
      • Drawing_in_ChildWindow.PNG

        30.02 kB, 548×422, viewed 346 times

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

    • Hi,

      generally, you should call GUI_Clear() before you draw anything so the window area gets cleared before something is drawn. Otherwise there could remain artifacts on the screen.

      Could you provide me with a little more code so I know what is happening exactly?

      Thanks and best regards,

      Florian
      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 Florian,

      Within the WM_PAINT case statement I do call GUI_Clear() as you will see in the attached code. Notice that when I add the line drawing call, GUI_DrawVLine(Value, 10, 272), in WM_PAIN: the line is not drawn. When I add it to the
      case WM_NOTIFICATION_RELEASED: I see the line but it's drawn in the background window, not in the Child window as I need.

      See code attached.

      Since you now have this code, if you look at the WM_KEY case, where I try to exit using the ESCAPE key press. That does not work either. I sent a question to Sven on it. If you can see why, please let me know as I carbon copied an emWIN example so this should work out of the box...

      The expression : switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) should read the KEY number and case GUI_KEY_ESCAPE should match that. But even when I place a break point on the -> case GUI_KEY_ESCAPE: it never breaks...

      case WM_KEY: // This does not work for now.
      switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) {
      case GUI_KEY_ESCAPE:
      _Break = 1;
      break;
      }
      break;

      Thanks again!
      E4M
      Files
    • Hi,

      it isn't being drawn correctly since you are drawing in the WM_NOTIFY_PARENT case, but you should only draw in WM_PAINT cases!

      WM_KEY messages are sent to the window that has input focus. But by default windows can't receive input focus, so this has to be implemented manually.

      I've attached a sample that does this, you need to copy the cases WM_SET_ID, WM_GET_ID, WM_SET_FOCUS and WM_PID_STATE_CHANGED from _cbWin to your callback.

      Best regards,

      Florian
      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.