Rotating image over a dialog

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

  • Rotating image over a dialog

    Hi!

    I'm trying to have an image to rotate over a dialog. In order to do so, I tried the following example (which is not an image I concede):

    // ****************************************
    // Function
    //****************************************
    void DrawRotatingIcon(void)
    {
    GUI_MEMDEV_Handle hMemSource = 0;
    GUI_MEMDEV_Handle hMemDest = 0;
    GUI_RECT RectSource = { 0, 0, 69, 39 };
    GUI_RECT RectDest = { 0, 0, 79, 79 };


    hMemSource = GUI_MEMDEV_CreateFixed(RectSource.x0,
    RectSource.y0,
    RectSource.x1 - RectSource.x0 + 1,
    RectSource.y1 - RectSource.y0 + 1,
    GUI_MEMDEV_NOTRANS,
    GUI_MEMDEV_APILIST_32,
    GUI_COLOR_CONV_888);

    hMemDest = GUI_MEMDEV_CreateFixed(RectDest.x0,
    RectDest.y0,
    RectDest.x1 - RectDest.x0 + 1,
    RectDest.y1 - RectDest.y0 + 1,
    GUI_MEMDEV_NOTRANS,
    GUI_MEMDEV_APILIST_32,
    GUI_COLOR_CONV_888);

    if (0 != hMemSource && 0 != hMemDest)
    {
    GUI_MEMDEV_Select(hMemSource);
    GUI_DrawGradientV(RectSource.x0,
    RectSource.y0,
    RectSource.x1,
    RectSource.y1,
    GUI_WHITE,
    GUI_DARKGREEN);
    GUI_SetColor(GUI_BLUE);
    GUI_SetFont(&GUI_Font20B_ASCII);
    GUI_SetTextMode(GUI_TM_TRANS);
    GUI_DispStringInRect("emWin", &RectSource, GUI_TA_HCENTER | GUI_TA_VCENTER);
    GUI_DrawRect(0, 0, RectSource.x1, RectSource.y1);

    static int rotation = 0;

    GUI_MEMDEV_Select(hMemDest);
    GUI_Clear();

    GUI_MEMDEV_Select(0);

    GUI_MEMDEV_RotateHQ(hMemSource,
    hMemDest,
    (RectDest.x1 - RectSource.x1) / 2,
    (RectDest.y1 - RectSource.y1) / 2,
    rotation * 1000,
    1 * 1000);

    //GUI_MEMDEV_CopyToLCDAt(hMemSource, 10, (RectDest.y1 - RectSource.y1) / 2 + 100);
    GUI_MEMDEV_CopyToLCDAt(hMemDest, 100, 100);

    if (rotation < 350)
    {
    rotation = rotation + 10;
    }
    else
    {
    rotation = 0;
    }
    }

    if(0 != hMemSource)
    {
    GUI_MEMDEV_Delete(hMemSource);
    }

    if(0 != hMemDest)
    {
    GUI_MEMDEV_Delete(hMemDest);
    }
    }
    // ****************************************
    // End of Function
    //****************************************


    I call this function periodically while the dialog window is being displayed. Note that this rotating icon is displayed over the dialog. Since I am not using double buffering, the first problem I encountered was that at some point, when the dialog was being repainted, I lost my rotating icon until it was redrawn.

    In order to eliminated that problem, I though about redrawing this icon both: periodically and whenever the dialog is repainted. In order to do so, I added a call to this same funtion on a WM_PAINT or WM_POSTPAINT callback. However, now the other widgets on the dialog do not get displayed corrected even though they do not physically overlap with the MEMDEV area. For example, if I press on a button, it will disappear.

    What am I doing wrong? How would you recommand to implement a rotating image over a dialog? Can I rotate an Image widget and make it part of the dialog? I have not found how to do that.

    Any thoughts?

    Thanks!
    Mathieu

    The post was edited 5 times, last by mmassic ().

  • Hi,

    Painting outside of WM_PAINT events is not a good idea. That causes the problem. My recommendation is invalidating the area of the rotating image by a timer and drawing of the image within WM_PAINT.

    Regards...
  • The thing is, the rotating image is not part of the dialog. It's not a widget. I cannot invalidate it. Plus I already tried to draw the rotating image within a WM_PAINT. Actually, that is when the problem happens: button widget will disappear when pressed.

    There seems to be a conflict with using MEMDEV within a WM_PAINT. I have no idea what to do to solve this.

    Mathieu

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