Shifting window content and adding new lines

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

    • Shifting window content and adding new lines

      Hello,

      I would like to ask you for ideas. My task is drawing a spectrogram in a window. The attached picture shows an example spectrogram. Such spectrograms are used for visualizing FFT spectra over time. It has a vertical time axis and a horizontal frequency axis. The amplitudes of the spectra are color-coded. Each horizontal dot line corresponds to one FFT. From the bottom of the window newly calculated spectra are shifted in while the oldest spectra on top are shifted out. I already have a solution for drawing a line of colored dots. My question is: How can I manage the FIFO-like vertical shift of the window content?
      I cannot recalculate the complete spectrogram each second because of computing power and, mainly, because I can only save the input data of the last row. The previous dot lines can only be held in the frame buffer.

      Best regards
      Jan

      P.S.: I was thinking of something like:
      1. Drawing one row of dots at the bottom of the window
      2. Shifting the window 1 row up (e.g. WM_SetWindowPos)
      3. Removing 1 row at the top
      4. Attaching 1 row at the bottom (e.g. WM_SetYSize)
      5. Drawing one row of dots at the new bottom of the window ...


      Step 3 seems to be the problem here. I don't know how to cut off the upper row. Vertical resizing only affects the bottom side of a window.
      Images
      • spectrogram.jpg

        26.08 kB, 260×194, viewed 271 times

      The post was edited 4 times, last by JanBurg ().

    • For those looking for a solution:
      I used a window with callback for PAINT. The window is invalidated regularly for redrawing.

      C Source Code

      1. case WM_INIT_DIALOG:
      2. hItem5 = WM_CreateWindow(0, 95, XSIZE_PHYS, 350, WM_CF_SHOW, _cbWinSpectrogr, 0); /*create spectrogram window with callback*/
      3. WM_CreateTimer(pMsg->hWin, 0, 50, 0); /*timer for periodic refresh*/
      4. break;
      5. case WM_TIMER:
      6. GUI_RECT Rect = {0, 0, XSIZE_PHYS, 350};
      7. WM_InvalidateRect(hItem5, &Rect); /*trigger redrawing of the spectrogram*/
      8. WM_RestartTimer(pMsg->Data.v, 200);
      9. break;
      In the callback the window content is shifted 1 pixel up by GUI_CopyRect() and a new spectrogram line is added at the bottom.

      C Source Code

      1. /*callback for the spectrogram window*/
      2. static void _cbWinSpectrogr(WM_MESSAGE * pMsg)
      3. {
      4. switch (pMsg->MsgId)
      5. {
      6. case WM_PAINT:
      7. {
      8. GUI_CopyRect(0, 1, 0, 0, XSIZE_PHYS, 350); /*copy the previous window content and insert it 1 row up*/
      9. for (uint16_t n = 0; n < XSIZE_PHYS; n++)
      10. {
      11. GUI_SetColor(FFT_SpectrogrColor[(GraphOut[FFT_WaterfallCh][n]) * 70 / (uint16_t)FFTVerSize]);
      12. GUI_DrawPixel(n, 349); /*draw a new spectrogram row at the bottom of the window*/
      13. }
      14. }
      15. break;
      16. default:
      17. WM_DefaultProc(pMsg);
      18. break;
      19. }
      20. }
      Display All