Creating Graph on Memory Device

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

  • Creating Graph on Memory Device

    Hi, is possible to create a graph using GRAPH_CreateEx into a memory device instead of a window?
    I'd like to use it for redirect the graph image to the printer without display it on tft.
    I tried with something like ::

    ----------------

    hMem = GUI_MEMDEV_CreateFixed(0, 0, 100, 100, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUICC_888);
    GUI_MEMDEV_Select(hMem);


    GUI_SetBkColor(GUI_WHITE);
    GUI_Clear();


    hgraph = GRAPH_CreateEx(0, 0, 100, 100, WM_UNATTACHED, WM_CF_SHOW | WM_CF_STAYONTOP, 0, ID_GRAPH_0);

    ...(hgraph setting)


    PrintImageBMP(hDest, ..);

    --------------------

    but i can not see anything in the memory device.
    If i draw simple 2D graphics it works well!
    Have You any suggestions?

    Thank You so much
    Simone ?(
  • Hi Simone,

    Creating the GRAPH widget in a memory device is not possible. But you can redirect the drawing operations, which draw the graph, into a memory device. To achieve this, simply overwrite the GRAPH callback by a call of WM_SetCallback().

    Inside the callback react on WM_PAINT and redirect the drawing operations into a memory device. This is done by GUI_MEMDEV_Select(hMem). After the function GUI_MEMDEV_Select() just call the default graph callback (GRAPH_Callback(pMsg)) which will draw the graph. After the default callback call GUI_MEMDEV_Select(0) which de-selects the memory device again.

    Now you can use the memory device to fill a bitmap or do anything else with it. The GRAPH itself won't be visible.

    Here is an example, since code says more than thousand words:

    C Source Code

    1. #include "DIALOG.h"
    2. /*********************************************************************
    3. *
    4. * Defines
    5. *
    6. **********************************************************************
    7. */
    8. /*********************************************************************
    9. *
    10. * Static data
    11. *
    12. **********************************************************************
    13. */
    14. static I16 _aData[] = {
    15. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    16. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    17. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    18. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    19. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    20. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    21. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    22. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    23. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    24. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    25. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    26. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    27. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    28. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    29. 0, 15, 20, 23, 24, 25, 24, 23, 20, 15,
    30. };
    31. static GUI_MEMDEV_Handle _hMem;
    32. /*********************************************************************
    33. *
    34. * Static code
    35. *
    36. **********************************************************************
    37. */
    38. static void _cbGraph(WM_MESSAGE * pMsg) {
    39. switch (pMsg->MsgId) {
    40. case WM_PAINT:
    41. //
    42. // Select the memory device. Any drawing operations will be performed into the selected device.
    43. //
    44. GUI_MEMDEV_Select(_hMem);
    45. //
    46. // Call the default graph callback
    47. //
    48. GRAPH_Callback(pMsg);
    49. //
    50. // De-select the device
    51. //
    52. GUI_MEMDEV_Select(0);
    53. break;
    54. default:
    55. GRAPH_Callback(pMsg);
    56. break;
    57. }
    58. }
    59. /*********************************************************************
    60. *
    61. * Public code
    62. *
    63. **********************************************************************
    64. */
    65. /*********************************************************************
    66. *
    67. * MainTask
    68. */
    69. void MainTask(void) {
    70. int i;
    71. int xSize;
    72. int ySize;
    73. WM_HWIN hGraph;
    74. GRAPH_DATA_Handle hData;
    75. //
    76. // Init emWin and clear back ground with white
    77. //
    78. GUI_Init();
    79. GUI_SetBkColor(GUI_WHITE);
    80. GUI_Clear();
    81. xSize = GUI_COUNTOF(_aData);
    82. ySize = 60;
    83. //
    84. // Create a memory device
    85. //
    86. _hMem = GUI_MEMDEV_CreateFixed32(0, 0, xSize, ySize);
    87. //
    88. // Create the GRAPH widget and configure it
    89. //
    90. hGraph = GRAPH_CreateEx(0, 0, xSize, ySize, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_GRAPH0);
    91. GRAPH_SetColor(hGraph, GUI_WHITE, GRAPH_CI_BK);
    92. GRAPH_SetColor(hGraph, GUI_LIGHTGRAY, GRAPH_CI_GRID);
    93. GRAPH_SetGridVis(hGraph, 1),
    94. GRAPH_SetGridDistX(hGraph, 10);
    95. GRAPH_SetGridDistY(hGraph, 10);
    96. //
    97. // Create GRAPH data and attach it to the widget
    98. //
    99. hData = GRAPH_DATA_YT_Create(GUI_RED, GUI_COUNTOF(_aData), _aData, GUI_COUNTOF(_aData));
    100. GRAPH_AttachData(hGraph, hData);
    101. //
    102. // Important, overwrite the callback
    103. //
    104. WM_SetCallback(hGraph, _cbGraph);
    105. //
    106. // Make sure the graph has been drawn at least once before drawing the memory device.
    107. //
    108. WM_Exec();
    109. //
    110. // Write the memory device. IT gets filled in the graph callback.
    111. //
    112. GUI_MEMDEV_WriteAt(_hMem, 160, 160);
    113. while (1) {
    114. GUI_Delay(100);
    115. }
    116. }
    117. /*************************** 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.