How to draw a smooth curve by point input

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

    • How to draw a smooth curve by point input

      I need to draw a curve according to the input point. Every time I input a point curve to the left, the GUI_AA_DrawLine method between the point and the point is used to draw a line, so the whole curve is not very smooth, not beautiful enough, I want to ask you There is no better way to handle it and achieve a smooth curve.
    • Hi,

      Since version 5.44 of emWin it is possible to draw splines resulting in smooth curves.

      Here is a short example:

      C Source Code

      1. #include "GUI.h"
      2. /*********************************************************************
      3. *
      4. * Defines
      5. *
      6. **********************************************************************
      7. */
      8. #define TEMP_MULTIPLY 5
      9. /*********************************************************************
      10. *
      11. * Static data
      12. *
      13. **********************************************************************
      14. */
      15. static const int _axi[] = {
      16. 0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240
      17. };
      18. static const int _ayi[3][13] = {
      19. { 8, 7, 6, 7, 8, 11, 14, 16, 18, 16, 13, 9, 7 },
      20. { 7, 7, 6, 6, 8, 11, 14, 15, 15, 14, 13, 8, 7 },
      21. { 7, 6, 5, 4, 5, 8, 9, 12, 14, 12, 11, 8, 6 }
      22. };
      23. static GUI_COLOR _aColor[] = {
      24. GUI_RED, GUI_GREEN, GUI_LIGHTBLUE
      25. };
      26. /*********************************************************************
      27. *
      28. * Static code
      29. *
      30. **********************************************************************
      31. */
      32. /*********************************************************************
      33. *
      34. * _DrawSplines
      35. */
      36. static void _DrawSplines(void) {
      37. GUI_HMEM hSpline;
      38. U32 NumPoints;
      39. int aTemp[3][13];
      40. int i, j;
      41. for (i = 0; i < GUI_COUNTOF(_ayi); i++) {
      42. for (j = 0; j < GUI_COUNTOF(_ayi[i]); j++) {
      43. aTemp[i][j] = _ayi[i][j] * TEMP_MULTIPLY * -1;
      44. }
      45. NumPoints = GUI_COUNTOF(_axi);
      46. hSpline = GUI_SPLINE_Create(_axi, aTemp[i], NumPoints);
      47. GUI_SetColor(_aColor[i]);
      48. GUI_SetDrawMode(GUI_DM_TRANS);
      49. GUI_SPLINE_DrawAA(hSpline, 20, 100, 0);
      50. GUI_SPLINE_DrawAA(hSpline, 20, 150, 3);
      51. GUI_SetDrawMode(GUI_DM_NORMAL);
      52. GUI_SPLINE_DrawAA(hSpline, 20, 200, 0);
      53. GUI_SPLINE_DrawAA(hSpline, 20, 250, 3);
      54. GUI_SPLINE_Delete(hSpline);
      55. }
      56. }
      57. /*********************************************************************
      58. *
      59. * Public code
      60. *
      61. **********************************************************************
      62. */
      63. /*********************************************************************
      64. *
      65. * MainTask
      66. */
      67. void MainTask(void) {
      68. GUI_Init();
      69. _DrawSplines();
      70. while (1) {
      71. GUI_Delay(100);
      72. }
      73. }
      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.
    • SEGGER - Schoenen wrote:

      Hi,

      Since version 5.44 of emWin it is possible to draw splines resulting in smooth curves.

      Here is a short example:

      C Source Code

      1. #include "GUI.h"
      2. /*********************************************************************
      3. *
      4. * Defines
      5. *
      6. **********************************************************************
      7. */
      8. #define TEMP_MULTIPLY 5
      9. /*********************************************************************
      10. *
      11. * Static data
      12. *
      13. **********************************************************************
      14. */
      15. static const int _axi[] = {
      16. 0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240
      17. };
      18. static const int _ayi[3][13] = {
      19. { 8, 7, 6, 7, 8, 11, 14, 16, 18, 16, 13, 9, 7 },
      20. { 7, 7, 6, 6, 8, 11, 14, 15, 15, 14, 13, 8, 7 },
      21. { 7, 6, 5, 4, 5, 8, 9, 12, 14, 12, 11, 8, 6 }
      22. };
      23. static GUI_COLOR _aColor[] = {
      24. GUI_RED, GUI_GREEN, GUI_LIGHTBLUE
      25. };
      26. /*********************************************************************
      27. *
      28. * Static code
      29. *
      30. **********************************************************************
      31. */
      32. /*********************************************************************
      33. *
      34. * _DrawSplines
      35. */
      36. static void _DrawSplines(void) {
      37. GUI_HMEM hSpline;
      38. U32 NumPoints;
      39. int aTemp[3][13];
      40. int i, j;
      41. for (i = 0; i < GUI_COUNTOF(_ayi); i++) {
      42. for (j = 0; j < GUI_COUNTOF(_ayi[i]); j++) {
      43. aTemp[i][j] = _ayi[i][j] * TEMP_MULTIPLY * -1;
      44. }
      45. NumPoints = GUI_COUNTOF(_axi);
      46. hSpline = GUI_SPLINE_Create(_axi, aTemp[i], NumPoints);
      47. GUI_SetColor(_aColor[i]);
      48. GUI_SetDrawMode(GUI_DM_TRANS);
      49. GUI_SPLINE_DrawAA(hSpline, 20, 100, 0);
      50. GUI_SPLINE_DrawAA(hSpline, 20, 150, 3);
      51. GUI_SetDrawMode(GUI_DM_NORMAL);
      52. GUI_SPLINE_DrawAA(hSpline, 20, 200, 0);
      53. GUI_SPLINE_DrawAA(hSpline, 20, 250, 3);
      54. GUI_SPLINE_Delete(hSpline);
      55. }
      56. }
      57. /*********************************************************************
      58. *
      59. * Public code
      60. *
      61. **********************************************************************
      62. */
      63. /*********************************************************************
      64. *
      65. * MainTask
      66. */
      67. void MainTask(void) {
      68. GUI_Init();
      69. _DrawSplines();
      70. while (1) {
      71. GUI_Delay(100);
      72. }
      73. }
      Display All
      Regards,
      Sven
      Thank you. It solved my problem.
    • SEGGER - Schoenen wrote:

      Hi,

      Since version 5.44 of emWin it is possible to draw splines resulting in smooth curves.

      Here is a short example:

      C Source Code

      1. #include "GUI.h"
      2. /*********************************************************************
      3. *
      4. * Defines
      5. *
      6. **********************************************************************
      7. */
      8. #define TEMP_MULTIPLY 5
      9. /*********************************************************************
      10. *
      11. * Static data
      12. *
      13. **********************************************************************
      14. */
      15. static const int _axi[] = {
      16. 0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240
      17. };
      18. static const int _ayi[3][13] = {
      19. { 8, 7, 6, 7, 8, 11, 14, 16, 18, 16, 13, 9, 7 },
      20. { 7, 7, 6, 6, 8, 11, 14, 15, 15, 14, 13, 8, 7 },
      21. { 7, 6, 5, 4, 5, 8, 9, 12, 14, 12, 11, 8, 6 }
      22. };
      23. static GUI_COLOR _aColor[] = {
      24. GUI_RED, GUI_GREEN, GUI_LIGHTBLUE
      25. };
      26. /*********************************************************************
      27. *
      28. * Static code
      29. *
      30. **********************************************************************
      31. */
      32. /*********************************************************************
      33. *
      34. * _DrawSplines
      35. */
      36. static void _DrawSplines(void) {
      37. GUI_HMEM hSpline;
      38. U32 NumPoints;
      39. int aTemp[3][13];
      40. int i, j;
      41. for (i = 0; i < GUI_COUNTOF(_ayi); i++) {
      42. for (j = 0; j < GUI_COUNTOF(_ayi[i]); j++) {
      43. aTemp[i][j] = _ayi[i][j] * TEMP_MULTIPLY * -1;
      44. }
      45. NumPoints = GUI_COUNTOF(_axi);
      46. hSpline = GUI_SPLINE_Create(_axi, aTemp[i], NumPoints);
      47. GUI_SetColor(_aColor[i]);
      48. GUI_SetDrawMode(GUI_DM_TRANS);
      49. GUI_SPLINE_DrawAA(hSpline, 20, 100, 0);
      50. GUI_SPLINE_DrawAA(hSpline, 20, 150, 3);
      51. GUI_SetDrawMode(GUI_DM_NORMAL);
      52. GUI_SPLINE_DrawAA(hSpline, 20, 200, 0);
      53. GUI_SPLINE_DrawAA(hSpline, 20, 250, 3);
      54. GUI_SPLINE_Delete(hSpline);
      55. }
      56. }
      57. /*********************************************************************
      58. *
      59. * Public code
      60. *
      61. **********************************************************************
      62. */
      63. /*********************************************************************
      64. *
      65. * MainTask
      66. */
      67. void MainTask(void) {
      68. GUI_Init();
      69. _DrawSplines();
      70. while (1) {
      71. GUI_Delay(100);
      72. }
      73. }
      Display All
      Regards,
      Sven
      Hello Sven,

      I will like to use the spline features and I tried your example on both custom hardware and an STM32 Demoboard (STM32F46G-DISCO) and in both cases it gives me a linker errors:


      Source Code

      1. compiling splines_app.c...
      2. linking...
      3. STM32746G_DISCOVERY\Exe\Project.axf: Error: L6218E: Undefined symbol GUI_SPLINE_Create (referred from splines_app.o).
      4. STM32746G_DISCOVERY\Exe\Project.axf: Error: L6218E: Undefined symbol GUI_SPLINE_Delete (referred from splines_app.o).
      5. STM32746G_DISCOVERY\Exe\Project.axf: Error: L6218E: Undefined symbol GUI_SPLINE_DrawAA (referred from splines_app.o).
      6. Not enough information to list image symbols.
      7. Not enough information to list load addresses in the image map.
      Display All

      Emwin version is GUI_VERSION 54401.

      Am I missing anything?

      Thank you.
      Mark
    • Hi Mark,

      That's interesting, I have checked V5.44a but the spline related functions are present.

      Did you updated from an older version to 5.44a?
      Maybe something went wrong in this process.

      If can get hands on a newer version you should give that a try.

      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.
    • SEGGER - Schoenen wrote:

      Hi Mark,

      That's interesting, I have checked V5.44a but the spline related functions are present.

      Did you updated from an older version to 5.44a?
      Maybe something went wrong in this process.

      If can get hands on a newer version you should give that a try.

      Regards,
      Sven
      Hi Sven, thank you for your answer.

      First I've tried updating an older library version (5.40) to the last present on the STM32Cube_FW_F7_V1.15.0 which is the 5.44 mentioned before.
      The result was I got those linker errors.

      Then I've tried using your example on the "Animation example" on the same package STM32Cube_FW_F7_V1.15.0 on the STM32 Demoboard mentioned before.
      The result was the same.

      On the GUI.h file the prototype functions are present though.

      I'll try downloading a newer version from emWin website then.

      Regards,
      Mark
    • I have the same issue. I need to use this feature on STM32F469iDiscovery. I´m using STM32Cube_FW_V1.24.2.

      In the GUI.h i see the prototypes like this:

      C Source Code

      1. /*********************************************************************
      2. *
      3. * Splines
      4. */
      5. GUI_HMEM GUI_SPLINE_Create (const int * px, const int * py, unsigned NumPoints);
      6. void GUI_SPLINE_Draw (GUI_HMEM hSpline, int x, int y);
      7. void GUI_SPLINE_Delete (GUI_HMEM hSpline);
      8. I16 GUI_SPLINE_GetY (GUI_HMEM hSpline, unsigned Index, float * py);
      9. unsigned GUI_SPLINE_GetXSize(GUI_HMEM hSpline);
      10. void GUI_SPLINE_DrawAA (GUI_HMEM hSpline, int x, int y, unsigned Width);
      11. /*********************************************************************
      Display All
      But when building i get following Error message:


      rm-none-eabi-gcc -o "Display.elf" @"objects.list" -l:STemWin_CM4_OS_wc32_ot_ARGB.a -mcpu=cortex-m4 -T"../STM32F469NIHx_FLASH.ld" --specs=nosys.specs -Wl,-Map="Display.map" -Wl,--gc-sections -static -L../Middlewares/ST/STemWin/Lib --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
      STemWin/App/MainWindow.o: In function `_cbDialog':
      /Users/christiansager/klanghabitat_quantum/firmware/firmware quantum/Display/Debug/../STemWin/App/MainWindow.c:121: undefined reference to `GUI_SPLINE_Create'
      collect2: error: ld returned 1 exit status
      make: *** [makefile:61: Display.elf] Error 1

      Question:
      1. How can i identify the exact version of the "STemWIN_CM4_OS_wc32_ot_ARGB.a"?
      2. Is there a way to solve this issue?
      3. Can i upgrade somehow the lib?

      THX