ProgBar - Fill bar

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

    • ProgBar - Fill bar

      Hi,

      My progress bar is filling strange ..
      You can see the progress bar running in the movie (uploaded via YouTube): ProgBar Movie
      or check the image (progab_filling_strange.png) below


      C Source Code

      1. case WIDGET_ITEM_DRAW_BACKGROUND:
      2. {
      3. // Receive the area of the PROGBAR widget
      4. WM_GetClientRectEx(pDrawItemInfo->hWin, &Rect);
      5. // Draw a white rounded rect over the whole PROGBAR area, but the drawing will be visible only in the area of the cliprect.
      6. GUI_SetColor(FIT_COLOR_1_BLACK);
      7. GUI_FillRoundedRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1, 0);
      8. // Draw a green rounded rect over the complete area, this gets (partially) overwritten by a white one
      9. GUI_SetColor(FIT_COLOR_7_GREEN);
      10. int blocks = PROGBAR_GetValue(hProg) / 10 * 2; // need to show block per 5 %
      11. int x0, x1 = 0;
      12. for (int k = 0; k < blocks; k++)
      13. {
      14. x0 = x1;
      15. if (k != 0) { x0 += 3; } // per green block, 3 px in between
      16. x1 = 8 + x0; // block is 8 px wide
      17. GUI_FillRoundedRect(x0, Rect.y0, x1, Rect.y1, 0);
      18. // Set a user cliprect
      19. UserRect.x0 = x0;
      20. UserRect.y0 = pDrawItemInfo->y0;
      21. UserRect.x1 = x1;
      22. UserRect.y1 = pDrawItemInfo->y1;
      23. WM_SetUserClipRect(&UserRect);
      24. //GUI_FillRoundedRect(x0, Rect.y0, x1, Rect.y1, 0);
      25. GUI_FillRoundedRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1, 0);
      26. }
      27. // Very important, restore the the clipping area
      28. WM_SetUserClipRect(NULL);
      29. l_return = 0;
      30. } break;
      Display All

      In my Paint function of the active Window, I loop over 0 - 100% to set the progress bar as demo.

      Source Code

      1. if (l_vsd_speed == 100)
      2. {
      3. l_vsd_speed = 0;
      4. }
      5. else {
      6. l_vsd_speed += 1;
      7. }
      8. PROGBAR_SetValue(hProg, l_vsd_speed);


      Any idea why the progress bar is filling to strangly? At 50% it fills OK ..

      When I set it on a fixed value, it can draw the progress bar OK. See image (progbar.png)below. what is strange aswell is that instead of drawing per 5 % block it is drawing per 10% (so alwayas adding per 2 green blocks)
      Images
      • progbar_filling_strange.PNG

        4.87 kB, 338×252, viewed 21 times
      • progbar.PNG

        4.65 kB, 336×257, viewed 11 times

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

    • Hi Pieter,

      the clipping rectangle you set doesn't work, because of that most of the blocks don't get drawn. It worked for me when I called WM_InvalidateWindow() after each loop that increases the progbar value. Also, try this to draw your blocks:

      C Source Code

      1. Rect.x0 = 0;
      2. Rect.x1 = 8;
      3. for (k = 0; k < Blocks; k++) {
      4. GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
      5. Rect.x0 += 11;
      6. Rect.x1 = Rect.x0 + 8;
      7. }

      The problem with the two blocks being drawn at once lies within your calculation of blocks. Just do: Blocks = PROGBAR_GetValue(hProg) / 5;

      Best regards,

      Florian