/* And the real drawing loop: */
void CairoDrawLoop(HWND             hwndClientWindow,
                   int              iWidth,
                   int              iHeight,
                   cairo_surface_t *pCairoSurface,
                   cairo_t         *pCairoHandle)
{
  double dRandMax;
  unsigned int uiLoopCounter = 0;
  NewsItem_p pCurrItem;

  // Initialize random number generator
  srand(clock());
  dRandMax = RAND_MAX;
  // Clear background with black
  cairo_set_source_rgb (pCairoHandle, 0, 0 ,0);
  cairo_rectangle (pCairoHandle,
                   0, 0,
                   iWidth, iHeight);
  cairo_fill(pCairoHandle);

  // Calculate screen aspect ratio
  if (iWidth<iHeight)
  {
    iUniSize = iWidth;
    dYAspect = iHeight;
    dYAspect /= iWidth;
    dXAspect = 1;
  }
  else
  {
    iUniSize = iHeight;
    dXAspect = iWidth;
    dXAspect /= iHeight;
    dYAspect = 1;
  }

  // --------------------------------
  // Show info that we're downloading the feed

  cairo_save(pCairoHandle);
  cairo_scale(pCairoHandle, iUniSize, iUniSize);


  ShowInfo("Downloading",
           achRSSURL,
           hwndClientWindow,
           pCairoSurface, pCairoHandle);

  cairo_restore(pCairoHandle);

  WinInvalidateRect(hwndClientWindow, NULL, TRUE);

  // --------------------------------
  // Download the URL and parse it with libXML
  pNewsListHead = NULL;
  DownloadXML(achRSSURL, &pNewsListHead);
  pCurrItem = pNewsListHead;
  // --------------------------------

  // Do the main drawing loop as long as needed!
  while (!bShutdownDrawing)
  {
    if (bPauseDrawing)
    {
      // Do not draw anything if we're paused!
      DosSleep(250);
    }
    else
    {
      // Otherwise draw something!

      if (!pNewsListHead)
      {
        if (uiLoopCounter==0)
        {
          // Save cairo canvas state
          cairo_save(pCairoHandle);
  
          // Scale canvas so we'll have a
          // normalized coordinate system of (0;0) -> (1;1)
          cairo_scale(pCairoHandle, iUniSize, iUniSize);
  
          // Clear background with black
          cairo_set_source_rgb(pCairoHandle, 0, 0 ,0);
          cairo_rectangle(pCairoHandle,
                          0, 0,
                          dXAspect, dYAspect);
          cairo_fill(pCairoHandle);
  

          ShowInfo("Error downloading",
                   achRSSURL,
                   hwndClientWindow,
                   pCairoSurface, pCairoHandle);

          // Restore canvas state to original one
          cairo_restore(pCairoHandle);
          WinInvalidateRect(hwndClientWindow, NULL, TRUE);
        } else
        if (uiLoopCounter==10)
        {
          // Save cairo canvas state
          cairo_save(pCairoHandle);
  
          // Scale canvas so we'll have a
          // normalized coordinate system of (0;0) -> (1;1)
          cairo_scale(pCairoHandle, iUniSize, iUniSize);
  
          // Clear background with black
          cairo_set_source_rgb(pCairoHandle, 0, 0 ,0);
          cairo_rectangle(pCairoHandle,
                          0, 0,
                          dXAspect, dYAspect);
          cairo_fill(pCairoHandle);

          cairo_os2_surface_paint_window(pCairoSurface,
                                         NULL,
                                         NULL,
                                         1);


          // Restore canvas state to original one
          cairo_restore(pCairoHandle);
          WinInvalidateRect(hwndClientWindow, NULL, TRUE);
        }

        if (uiLoopCounter<20)
          uiLoopCounter++;
        else
          uiLoopCounter = 0;

      } else
      {
        if (uiLoopCounter % 150 == 0)
        {
          // Save cairo canvas state
          cairo_save(pCairoHandle);

          // Scale canvas so we'll have a
          // normalized coordinate system of (0;0) -> (1;1)
          cairo_scale(pCairoHandle, iUniSize, iUniSize);

          // Clear background with black
          cairo_set_source_rgb(pCairoHandle, 0, 0 ,0);
          cairo_rectangle(pCairoHandle,
                          0, 0,
                          dXAspect, dYAspect);
          cairo_fill(pCairoHandle);

          if (pCurrItem)
            VisualizeXML(pCurrItem,
                         pCairoHandle);

          // Restore canvas state to original one
          cairo_restore(pCairoHandle);
          WinInvalidateRect(hwndClientWindow, NULL, TRUE);

          // Go for next news item then.
          if (pCurrItem)
          {
            pCurrItem = pCurrItem->pNext;
            if (!pCurrItem)
              pCurrItem = pNewsListHead;
          }
        }

        uiLoopCounter++;
      }
    }


    DosSleep(30); // Wait some
  }
  // Got shutdown event, so stopped drawing. That's all.

  // Clean up
  FreeNewsData(&pNewsListHead);
}
Esempio n. 2
0
void gfxOS2Surface::Refresh(RECTL *aRect, int aCount, HPS aPS)
{
    if (mSurfType == os2Window)
       cairo_os2_surface_paint_window((cairo_os2_surface_t*)CairoSurface(),
                                       (aPS ? aPS : mPS), aRect, aCount);
}