Draw a line above a text

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

    • Draw a line above a text

      Hello.

      I need to draw a line above a text.

      The text is created using a dialog box

      Whne I try to draw the line in WM_PAINT message, the line is drawn bellow the text.

      Note that the text has a background collor.




      Here is the example code:


      Source Code

      1. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      2. #define ID_TEXT_0 (GUI_ID_USER + 0x02)
      3. // USER START (Optionally insert additional defines)
      4. // USER END
      5. /*********************************************************************
      6. *
      7. * Static data
      8. *
      9. **********************************************************************
      10. */
      11. // USER START (Optionally insert additional static data)
      12. // USER END
      13. /*********************************************************************
      14. *
      15. * _aDialogCreate
      16. */
      17. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      18. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0 },
      19. { TEXT_CreateIndirect, "Text", ID_TEXT_0, 50, 130, 320, 82, 0, 0x0, 0 },
      20. // USER START (Optionally insert additional widgets)
      21. // USER END
      22. };
      23. /*********************************************************************
      24. *
      25. * Static code
      26. *
      27. **********************************************************************
      28. */
      29. // USER START (Optionally insert additional static code)
      30. // USER END
      31. /*********************************************************************
      32. *
      33. * _cbDialog
      34. */
      35. static void _cbDialog(WM_MESSAGE * pMsg) {
      36. // USER START (Optionally insert additional variables)
      37. // USER END
      38. WM_HWIN hItem;
      39. switch (pMsg->MsgId) {
      40. // USER START (Optionally insert additional message handling)
      41. // USER END
      42. case WM_INIT_DIALOG:
      43. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
      44. TEXT_SetText(hItem, "Text");
      45. TEXT_SetBkColor(hItem, GUI_YELLOW);
      46. case WM_PAINT :
      47. GUI_SetColor(GUI_BLACK);
      48. GUI_SetPenSize(1);
      49. GUI_DrawLine(0, 0, 320, 240);
      50. break;
      51. default:
      52. WM_DefaultProc(pMsg);
      53. break;
      54. }
      55. }
      56. WM_HWIN CreateWindow22(void)
      57. {
      58. WM_HWIN hWin;
      59. hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      60. return hWin;
      61. }
      62. void MainTask(void) {
      63. GUI_Init();
      64. CreateWindow22();
      65. while (1)
      66. {
      67. GUI_Exec();
      68. }
      69. }
      Display All

      The result is :
      Images
      • image.png

        16.17 kB, 428×708, viewed 294 times
    • Hi,

      you can simply create another window over the existing one to draw over the rest.

      Try this:

      C Source Code

      1. #include "DIALOG.h"
      2. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      3. #define ID_TEXT_0 (GUI_ID_USER + 0x02)
      4. // USER START (Optionally insert additional defines)
      5. // USER END
      6. /*********************************************************************
      7. *
      8. * Static data
      9. *
      10. **********************************************************************
      11. */
      12. // USER START (Optionally insert additional static data)
      13. // USER END
      14. /*********************************************************************
      15. *
      16. * _aDialogCreate
      17. */
      18. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      19. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0 },
      20. { TEXT_CreateIndirect, "Text", ID_TEXT_0, 50, 130, 320, 82, 0, 0x0, 0 },
      21. // USER START (Optionally insert additional widgets)
      22. // USER END
      23. };
      24. /*********************************************************************
      25. *
      26. * Static code
      27. *
      28. **********************************************************************
      29. */
      30. // USER START (Optionally insert additional static code)
      31. // USER END
      32. static void _cbDrawingWindow(WM_MESSAGE * pMsg) {
      33. switch (pMsg->MsgId) {
      34. case WM_PAINT:
      35. GUI_SetColor(GUI_BLACK);
      36. GUI_SetPenSize(1);
      37. GUI_DrawLine(0, 0, 320, 240);
      38. break;
      39. default:
      40. WM_DefaultProc(pMsg);
      41. break;
      42. }
      43. }
      44. /*********************************************************************
      45. *
      46. * _cbDialog
      47. */
      48. static void _cbDialog(WM_MESSAGE * pMsg) {
      49. // USER START (Optionally insert additional variables)
      50. int xSize;
      51. int ySize;
      52. // USER END
      53. WM_HWIN hItem;
      54. switch (pMsg->MsgId) {
      55. // USER START (Optionally insert additional message handling)
      56. // USER END
      57. case WM_INIT_DIALOG:
      58. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
      59. TEXT_SetText(hItem, "Text");
      60. TEXT_SetBkColor(hItem, GUI_YELLOW);
      61. xSize = WM_GetWindowSizeX(pMsg->hWin);
      62. ySize = WM_GetWindowSizeY(pMsg->hWin);
      63. WM_CreateWindowAsChild(0, 0, xSize, ySize, pMsg->hWin, WM_CF_SHOW | WM_CF_HASTRANS, _cbDrawingWindow, 0);
      64. //case WM_PAINT :
      65. // GUI_SetColor(GUI_BLACK);
      66. // GUI_SetPenSize(1);
      67. // GUI_DrawLine(0, 0, 320, 240);
      68. // break;
      69. default:
      70. WM_DefaultProc(pMsg);
      71. break;
      72. }
      73. }
      74. WM_HWIN CreateWindow22(void)
      75. {
      76. WM_HWIN hWin;
      77. hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      78. return hWin;
      79. }
      80. void MainTask(void) {
      81. GUI_Init();
      82. CreateWindow22();
      83. while (1)
      84. {
      85. GUI_Exec();
      86. }
      87. }
      88. /*************************** End of file ****************************/
      Display All
      Please note that any underlaying windows/widget will no longer receive touch input with the window in the foreground.

      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.