• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

GDI+: GdipPathIterNextSubpathPath

Started by José Roca, June 23, 2008, 01:48:20 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 (also called subpaths) to the path. The code passes the address of the 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 (subpath) from the path. Then the code calls the GdipDrawPath method of a Graphics object to draw that individual subpath.

C++


VOID NextSubpathExample(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);

   // The variable "count" now holds the number of
   // data points in the second subpath.

   // Draw the retrieved subpath.
   Pen bluePen(Color(255, 0, 0, 255));
   graphics.DrawPath(&bluePen, &subpath);
}


PowerBASIC


SUB GDIP_PathIterNextSubpathPath (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pSubPath AS DWORD
   LOCAL pIterator AS DWORD
   LOCAL pBluePen 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)

   ' // The variable "count" now holds the number of
   ' // data points in the second subpath.

   ' // Draw the retrieved subpath.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 255), 1, %UnitWorld, pBluePen)
   hStatus = GdipDrawPath(pGraphics, pBluePen, pSubPath)

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

END SUB