Simple pixel draw outside WM_PAINT???

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

  • Simple pixel draw outside WM_PAINT???

    Dear all

    All I want to do is draw a pixel calling GUI_DrawPixel anywhere in the code. It works only in the window WM_PAINT. However every call outside the WM_PAINT isn't drawing any pixels even though I make sure I call WM_InvalidateWindow.

    Is there some kind a trick I'm misisng?

    Thanks

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

  • Hi,

    When using the Window Manager it might get tricky to draw outside WM_PAINT.

    1.
    The pixel gets drawn but the next time a window gets drawn the pixel gets overwritten.

    2.
    A clip rect is set and the pixel won't get drawn because it is outside the clip rect.

    3.
    If you are using multibuffering and it is not visible because the pixel was drawn into the backbuffer.

    Calling WM_InvalidateWindow() won't make the pixel visible. After calling WM_InvalidateWindow() nothing will happen before you enter GUI_Exec(). And then the drawing operations within WM_PAINT will be executed which will overwrite the pixel.

    It is not recommend to draw outside WM_PAINT if using the Window Manager, because you won't know if it will be visible or not.

    Is there a specific reason why you want to draw the pixel without WM_PAINT?

    If you have created a single window which does not fill the entire screen and want to draw outside this window you have to draw within WM_PAINT of the desktop window (WM_HBKWIN).

    The desktop window will have no callback per default but you can set one with WM_SetCallback(WM_HBKWIN, _cbBk).

    C Source Code

    1. #include "DIALOG.h"
    2. /*********************************************************************
    3. *
    4. * _cbBk
    5. */
    6. static void _cbBk(WM_MESSAGE * pMsg) {
    7. switch (pMsg->MsgId) {
    8. case WM_PAINT:
    9. GUI_SetBkColor(GUI_BLACK);
    10. GUI_Clear();
    11. break;
    12. default:
    13. WM_DefaultProc(pMsg);
    14. break;
    15. }
    16. }
    17. /*********************************************************************
    18. *
    19. * Public code
    20. *
    21. **********************************************************************
    22. */
    23. /*********************************************************************
    24. *
    25. * MainTask
    26. */
    27. void MainTask(void) {
    28. GUI_Init();
    29. WM_SetCallback(WM_HBKWIN, _cbBk);
    30. while (1) {
    31. GUI_Delay(100);
    32. }
    33. }
    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

    Thanks for the quick reply. To answer your question whether there is a specific reason why I want to draw the pixel without WM_PAINT, it is simply because I'd like to draw a simple x-y graph without the overhead of GRAPH widget and to add 'pinch-and-zoom' capability. Hence I created a window in which I drew x-y axes and now I want to start filling the window with x, y data. Simple as that and yet seems not possible?

    Cheers
  • Hi,

    Even if you want to draw your own graph in a window there is no need to draw outside of WM_PAINT.

    Take a look into the example attached. I have created a window and set a custom callback for this window. Inside WM_PAINT of this callback I draw a simplified x- and y-axis and a sine curve using GUI_DrawPoint(). I set the changing values for the graph with WM_SetUserData().

    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.