Using GUI_AA_DrawPolyOutline()/GUI_AA_DrawPolyOutlineEx() functions

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

    • Using GUI_AA_DrawPolyOutline()/GUI_AA_DrawPolyOutlineEx() functions

      Hello to everyone,

      I'm working with the simulation (latest version 5.50) and I'd like to understand using GUI_AA_DrawPolyOutline()/GUI_AA_DrawPolyOutlineEx() functions.

      I want to draw a simple antialiased polygon with a frame filled with inner color.

      Here is the code:

      C Source Code

      1. #include "DIALOG.h"
      2. // Polygon points
      3. GUI_POINT Plgn[] = {{-20, 20},
      4. {-20, -100},
      5. {0, -120},
      6. {20, -100},
      7. {20, 20},
      8. {0, 0}};
      9. void MainTask(void) {
      10. GUI_Init();
      11. // Fill background with the gray color
      12. GUI_SetBkColor(GUI_GRAY);
      13. GUI_Clear();
      14. // Draw polygon filled with the red color
      15. GUI_SetColor(GUI_RED);
      16. GUI_AA_FillPolygon(Plgn, GUI_COUNTOF(Plgn), 160, 160);
      17. // Draw white contour of the polygon
      18. GUI_SetColor(GUI_WHITE);
      19. GUI_AA_DrawPolyOutline(Plgn, GUI_COUNTOF(Plgn), 3, 160, 160);
      20. // The result is the polygon filled with the gray color
      21. while (1);
      22. }
      Display All

      The result is the polygon filled with the gray color instead of the red color. Using GUI_AA_DrawPolyOutlineEx() function ends up with the same result.



      I suggest that GUI_AA_DrawPolyOutline()/GUI_AA_DrawPolyOutlineEx() functions use the backround colour to fill the polygon.


      Then in my case if I want to have a red color I need to set a transparent backround color:

      C Source Code

      1. ...
      2. // Draw white contour of the polygon with settting a transparent background
      3. // Set white contour color
      4. GUI_SetColor(GUI_WHITE);
      5. // Enable considering the alpha channel
      6. GUI_EnableAlpha(1);
      7. // Set transparent backround color
      8. GUI_SetBkColor(GUI_TRANSPARENT);
      9. // Draw contour of the polygon
      10. GUI_AA_DrawPolyOutline(Plgn, GUI_COUNTOF(Plgn), 3, 160, 160);
      11. // Disable alpha
      12. GUI_EnableAlpha(0);
      13. ...
      Display All
      But in this case the result is the polygon filled with the white color.



      What am I doing wrong? I expect to see the following:



      Thanks,
      Alex.
    • Solved with using memore device so far.

      C Source Code

      1. #include "DIALOG.h"
      2. GUI_POINT Plgn[] = { {-20, 20},
      3. {-20, -100},
      4. {0, -120},
      5. {20, -100},
      6. {20, 20},
      7. {0, 0} };
      8. GUI_MEMDEV_Handle hMem;
      9. void MainTask(void) {
      10. GUI_Init();
      11. GUI_SetBkColor(GUI_GRAY);
      12. GUI_Clear();
      13. GUI_SetColor(GUI_RED);
      14. GUI_AA_FillPolygon(Plgn, GUI_COUNTOF(Plgn), 160, 160);
      15. hMem = GUI_MEMDEV_Create(0, 0, 320, 240);
      16. GUI_MEMDEV_Select(hMem);
      17. GUI_SetBkColor(GUI_TRANSPARENT);
      18. GUI_Clear();
      19. GUI_SetColor(GUI_WHITE);
      20. GUI_AA_DrawPolyOutline(Plgn, GUI_COUNTOF(Plgn), 3, 160, 160);
      21. GUI_MEMDEV_Select(0);
      22. GUI_MEMDEV_Write(hMem);
      23. while(1);
      24. }
      Display All
    • Hello,

      thanks for the code, Sven. I realized that the inner color should be the background color.

      Sometimes it needs not to paint over the backround contents behind the polygon like in my case. I'm working on custom widget "gauge meter" that may have only the contour with transparent background so meter contents behind it should be visible. In this case as far as I understand memory device is the best solution.

      Alex.