How to rotate a text insode a window?

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

  • How to rotate a text insode a window?

    I am Windows Manager and I have a window fully populated.
    I would like to rotate some text boxes widgets. I believe they do not support the rotation method.

    I saw at the manual that we can use "rotated" texts, as follows:
    GUI_RECT Rect = {166+(18)*1, 72, 40, 80};
    char acText[] = "Rotated\ntext";
    GUI_SetTextMode(GUI_TM_XOR);
    GUI_FillRectEx(&Rect);
    GUI_DispStringInRectEx(acText, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER, strlen(acText), GUI_ROTATE_CCW);

    However, this piece of code is not working at my window: it does not shows up. Is it incompatible with WM?

    Any hint of how to solve this issue?

    Thanks.
  • Hello Ajax,

    I have written a small sample which shows how to draw rotated text and how to overwrite a callback.

    C Source Code

    1. #include <string.h>
    2. #include "DIALOG.h"
    3. /*********************************************************************
    4. *
    5. * Static code
    6. *
    7. **********************************************************************
    8. */
    9. /*********************************************************************
    10. *
    11. * _cbWin
    12. */
    13. static void _cbText(WM_MESSAGE * pMsg) {
    14. GUI_RECT Rect;
    15. char aBuffer[255];
    16. switch (pMsg->MsgId) {
    17. case WM_PAINT:
    18. //
    19. // Fill window with fancy red
    20. //
    21. GUI_SetBkColor(GUI_RED);
    22. GUI_Clear();
    23. //
    24. // Get the area of the client, in this case the text widget
    25. //
    26. WM_GetClientRect(&Rect);
    27. //
    28. // Receive the text previously set while creating the widget
    29. //
    30. TEXT_GetText(pMsg->hWin, aBuffer, sizeof(aBuffer));
    31. //
    32. // Display rotated text inside a rectangle (the client one)
    33. //
    34. GUI_DispStringInRectEx(aBuffer, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER,
    35. strlen(aBuffer), GUI_ROTATE_CCW);
    36. break;
    37. default:
    38. //
    39. // Call the default callback just in case something else has to be done
    40. //
    41. TEXT_Callback(pMsg);
    42. }
    43. }
    44. /*********************************************************************
    45. *
    46. * Public code
    47. *
    48. **********************************************************************
    49. */
    50. /*********************************************************************
    51. *
    52. * MainTask
    53. */
    54. void MainTask(void) {
    55. WM_HWIN hItem;
    56. GUI_RECT Rect;
    57. char acText[] = "Text";
    58. GUI_Init();
    59. //
    60. // Define rectangle to draw text in
    61. //
    62. Rect.x0 = 0;
    63. Rect.y0 = 0;
    64. Rect.x1 = 100;
    65. Rect.y1 = 100;
    66. //
    67. // Draw a back ground
    68. //
    69. GUI_DrawGradientH(0, 0, LCD_GetXSize(), LCD_GetYSize(), GUI_DARKGRAY, GUI_GRAY);
    70. //
    71. // Set Text and set text mode to transparent
    72. //
    73. GUI_SetFont(&GUI_Font32B_1);
    74. GUI_SetTextMode(GUI_TM_TRANS);
    75. //
    76. // Dispplay a string inside a rectangle, rotated 90 degrees ccw
    77. //
    78. GUI_DispStringInRectEx(acText, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER, strlen(acText), GUI_ROTATE_CCW);
    79. //
    80. // Create a TEXT widget and overwrite its callback
    81. //
    82. hItem = TEXT_Create(100, 0, 100, 100, 0, WM_CF_SHOW, acText, GUI_TA_HCENTER | GUI_TA_VCENTER);
    83. WM_SetCallback(hItem, _cbText);
    84. while (1) {
    85. GUI_Delay(100);
    86. }
    87. }
    Display All


    For further information on how to overwrite a callback please refer to the emWin user manual (UM03001_emWin5.pdf) chapter 18.2.3 "Overwriting callback functions".

    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.