• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

GDI+: GdipPathIterNextMarkerPath

Started by José Roca, June 23, 2008, 01:36:41 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 calls to the GdipSetPathMarker function place two markers in the path. The first marker is at the end of a figure, and the second marker is in the middle of a figure. The code passes the address of the GraphicsPath object to the GdipCreatePathIter function to create an iterator that is associated with the path. Then the code calls the GdipPathIterNextMarkerPath function twice to obtain the second marker-delimited section of the path. Finally, the code draws the retrieved section of the path.

C++


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

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

   path.AddRectangle(Rect(20, 20, 60, 30));
   path.SetMarker();                          // first marker

   path.AddLine(100, 20, 160, 50);
   path.AddArc(180, 20, 60, 30, 0.0f, 180.0f);

   path.AddRectangle(Rect(260, 20, 60, 30));

   path.AddLine(340, 20, 400, 50);
   path.SetMarker();                          // second marker
   path.AddArc(340, 20, 60, 30, 0.0f, 180.0f);
   path.CloseFigure();
 
   path.AddRectangle(Rect(420, 20, 60, 30));

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

   // Get the second marker-delimited section by calling NextMarker twice.
   GraphicsPath section;
   INT count;
   count = iterator.NextMarker(&section);
   count = iterator.NextMarker(&section);

   // The variable "count" now holds the number of
   // data points in the second marker-delimited section.

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


PowerBASIC


SUB GDIP_PathIterNextMarkerPath (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pBluePen AS DWORD
   LOCAL pIterator AS DWORD
   LOCAL pSection AS DWORD
   LOCAL count 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)
   hStatus = GdipSetPathMarker(pPath)   ' // first marker
   hStatus = GdipAddPathLine(pPath, 100, 20, 160, 50)
   hStatus = GdipAddPathArc(pPath, 180, 20, 60, 30, 0, 180)
   hStatus = GdipAddPathRectangle(pPath, 260, 20, 60, 30)
   hStatus = GdipAddPathLine(pPath, 340, 20, 400, 50)
   hStatus = GdipSetPathMarker(pPath)   ' // second marker
   hStatus = GdipAddPathArc(pPath, 340, 20, 60, 30, 0, 180)
   hStatus = GdipClosePathFigure(pPath)
   hStatus = GdipAddPathRectangle(pPath, 420, 20, 60, 30)

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

   ' // Get the second marker-delimited section by calling NextMarker twice.
   hStatus = GdipCreatePath(%FillModeAlternate, pSection)
   hStatus = GdipPathIterNextMarkerPath(pIterator, count, pSection)
   hStatus = GdipPathIterNextMarkerPath(pIterator, count, pSection)

   ' // The variable "count" now holds the number of
   ' // data points in the second marker-delimited section.

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

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

END SUB