• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipPathIterRewind

Started by José Roca, June 23, 2008, 01:53:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a GraphicsPath object and adds five figures to the path. The code passes the address of that GraphicsPath object to the GdipCreatePathIter function to create an iterator that is associated with the path. The code calls the GdipPathIterNextSubpathPath function twice to retrieve the second figure in the path. The GdipDrawPath function draws that path in blue. Next, the code calls the GdipPathIterRewind function and then calls GdipPathIterNextSubpathPath once to obtain the first figure in the path. The GdipDrawPath function draws that figure in red.

C++


VOID RewindExample(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a graphics path with five figures (subpaths).
   GraphicsPath path;

   path.AddRectangle(Rect(20, 20, 60, 30));   // Subpath count is 1.

   path.AddLine(100, 20, 160, 50);            // Subpath count is 2.
   path.AddArc(180, 20, 60, 30, 0.0f, 180.0f);

   path.AddRectangle(Rect(260, 20, 60, 30));  // Subpath count is 3.

   path.AddLine(340, 20, 400, 50);            // Subpath count is 4.
   path.AddArc(340, 20, 60, 30, 0.0f, 180.0f);
   path.CloseFigure();
 
   path.AddRectangle(Rect(420, 20, 60, 30));  // Subpath count is 5.

   // Create an iterator, and associate it with the path.
   GraphicsPathIterator iterator(&path);

   // Get the second subpath by calling NextSubpath twice.
   GraphicsPath subpath;
   BOOL isClosed;
   INT count;
   count = iterator.NextSubpath(&subpath, &isClosed);
   count = iterator.NextSubpath(&subpath, &isClosed);

   // Draw the second figure in blue.
   Pen bluePen(Color(255, 0, 0, 255));
   graphics.DrawPath(&bluePen, &subpath);

   // Rewind the iterator, and get the first figure in the path.
   iterator.Rewind();
   count = iterator.NextSubpath(&subpath, &isClosed);

   // Draw the first figure in red.
   Pen redPen(Color(255, 255, 0, 0));
   graphics.DrawPath(&redPen, &subpath);
}


PowerBASIC


SUB GDIP_PathIterRewind (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pIterator AS DWORD
   LOCAL pSubPath AS DWORD
   LOCAL pBluePen AS DWORD
   LOCAL pRedPen AS DWORD
   LOCAL count AS LONG
   LOCAL isClosed AS LONG

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a graphics path with five figures (subpaths).
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

   hStatus = GdipAddPathRectangle(pPath, 20, 20, 60, 30)       ' // Subpath count is 1.

   hStatus = GdipAddPathLine(pPath, 100, 20, 160, 50)          ' // Subpath count is 2.
   hStatus = GdipAddPathArc(pPath, 180, 20, 60, 30, 0, 180)

   hStatus = GdipAddPathRectangle(pPath, 260, 20, 60, 30)      ' // Subpath count is 3.

   hStatus = GdipAddPathLine(pPath, 340, 20, 400, 50)          ' // Subpath count is 4.
   hStatus = GdipAddPathArc(pPath, 340, 20, 60, 30, 0, 180)
   hStatus = GdipClosePathFigure(pPath)

   hStatus = GdipAddPathRectangle(pPath, 420, 20, 60, 30)      ' // Subpath count is 5.

   ' // Create an iterator, and associate it with the path.
   hStatus = GdipCreatePathIter(pIterator, pPath)

   ' // Get the second subpath by calling NextSubpath twice.
   hStatus = GdipCreatePath(%FillModeAlternate, pSubPath)
   hStatus = GdipPathIterNextSubpathPath(pIterator, count, pSubPath, isClosed)
   hStatus = GdipPathIterNextSubpathPath(pIterator, count, pSubPath, isClosed)

   ' // Draw the second figure in blue.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 255), 1, %UnitWorld, pBluePen)
   hStatus = GdipDrawPath(pGraphics, pBluePen, pSubPath)

   ' // Rewind the iterator, and get the first figure in the path.
   hStatus = GdipPathIterRewind(pIterator)
   hStatus = GdipPathIterNextSubpathPath(pIterator, count, pSubPath, isClosed)

   ' // Draw the first figure in red.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 1, %UnitWorld, pRedPen)
   hStatus = GdipDrawPath(pGraphics, pRedPen, pSubPath)

   ' // Cleanup
   IF pBluePen THEN GdipDeletePen(pBluePen)
   IF pRedPen THEN GdipDeletePen(pRedPen)
   IF pIterator THEN GdipDeletePathIter(pIterator)
   IF pSubPath THEN GdipDeletePath(pSubPath)
   IF pPath THEN GdipDeletePath(pPath)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB