Emulate a 'DRAW' widget? (ie user freehand in a window)

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

    • Emulate a 'DRAW' widget? (ie user freehand in a window)

      Hi All,

      Does anyone know the simplest way to design/emulate something like a 'paint' window? i.e. what you could probably call a 'DRAW' widget, where say you define a blank window, and you capture and display all PID inputs in that window.

      for example, my display is 800x480, touch screen.

      1) I want to make a window of say 400x400, and allow the user to actually 'draw' in the window with their finger?


      2) and just display a dot or pixel at each touch point?


      Only thing I can think of is to just setup a background fast polling timer (as my touch interrupt is already feeding in touch StoreState() points), and poll the GUI_Touch_GetState() function to get points touched, and plot them manually if the co-ordinates are within the gui rectangle?

      Does that make sense?


      Thanks so much,

      - Mike
    • Hi,

      Here is a very basic drawing window. It collects all positions of the PID input when its pressed and invalidates the window. The window itterates over the collected points and connects them with lines.
      Of course, it needs some work to behave like drawing tool but it should give you a point to start with.

      C Source Code

      1. #include "DIALOG.h"
      2. #include <string.h>
      3. /*********************************************************************
      4. *
      5. * Externals
      6. *
      7. **********************************************************************
      8. */
      9. /*********************************************************************
      10. *
      11. * Types
      12. *
      13. **********************************************************************
      14. */
      15. /*********************************************************************
      16. *
      17. * Defines
      18. *
      19. **********************************************************************
      20. */
      21. #define MAX_NUM_POINTS 2048
      22. /*********************************************************************
      23. *
      24. * Static data
      25. *
      26. **********************************************************************
      27. */
      28. static GUI_POINT _aPoints[MAX_NUM_POINTS];
      29. /*********************************************************************
      30. *
      31. * Static code
      32. *
      33. **********************************************************************
      34. */
      35. /*********************************************************************
      36. *
      37. * _cbBk
      38. */
      39. static void _cbDrawingWin(WM_MESSAGE * pMsg) {
      40. GUI_PID_STATE * pState;
      41. static int Index;
      42. int i;
      43. switch (pMsg->MsgId) {
      44. case WM_PAINT:
      45. GUI_SetBkColor(GUI_WHITE);
      46. GUI_Clear();
      47. if (Index > 1) {
      48. GUI_SetColor(GUI_RED);
      49. for (i = 1; i < Index; i++) {
      50. GUI_DrawLine(_aPoints[i - 1].x, _aPoints[i - 1].y, _aPoints[i].x, _aPoints[i].y);
      51. }
      52. }
      53. break;
      54. case WM_TOUCH:
      55. pState = (GUI_PID_STATE *)pMsg->Data.p;
      56. if (pState) {
      57. if (pState->Pressed) {
      58. _aPoints[Index].x = pState->x;
      59. _aPoints[Index].y = pState->y;
      60. Index++;
      61. Index = (Index == (int)GUI_COUNTOF(_aPoints)) ? 0 : Index;
      62. if (Index == 0) {
      63. memset(_aPoints, 0, sizeof(GUI_POINT) * MAX_NUM_POINTS);
      64. }
      65. WM_InvalidateWindow(pMsg->hWin);
      66. }
      67. }
      68. break;
      69. default:
      70. WM_DefaultProc(pMsg);
      71. break;
      72. }
      73. }
      74. /*********************************************************************
      75. *
      76. * _cbBk
      77. */
      78. static void _cbBk(WM_MESSAGE * pMsg) {
      79. switch (pMsg->MsgId) {
      80. case WM_PAINT:
      81. GUI_SetBkColor(GUI_BLACK);
      82. GUI_Clear();
      83. break;
      84. default:
      85. WM_DefaultProc(pMsg);
      86. break;
      87. }
      88. }
      89. /*********************************************************************
      90. *
      91. * Public code
      92. *
      93. **********************************************************************
      94. */
      95. /*********************************************************************
      96. *
      97. * MainTask
      98. */
      99. void MainTask(void) {
      100. GUI_Init();
      101. WM_MULTIBUF_Enable(1);
      102. WM_SetCallback(WM_HBKWIN, _cbBk);
      103. WM_CreateWindowAsChild(100, 20, 400, 400, WM_HBKWIN, WM_CF_SHOW, _cbDrawingWin, 0);
      104. while (1) {
      105. GUI_Delay(100);
      106. }
      107. }
      108. /*************************** End of file ****************************/
      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.