• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipWindingModeOutline

Started by José Roca, June 22, 2008, 05:58:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a GraphicsPath object and calls the GdiAddPathClosedCurve method to add a closed cardinal spline to the path. The code calls the GdipWidenPath function to widen the path and then draws the path. Next, the code calls the GdipWindingModeOutline function The code calls the GdipTranslateWorldTransform function so that the outlined path drawn by the subsequent call to GdipDrawPath sits to the right of the first path.

C++


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

   Pen bluePen(Color(255, 0, 0, 255));
   Pen greenPen(Color(255, 0, 255,  0), 10);

   PointF points[] = {
      PointF(20.0f, 20.0f),
      PointF(160.0f, 100.0f),
      PointF(140.0f, 60.0f),
      PointF(60.0f, 100.0f)};

   GraphicsPath path;
   path.AddClosedCurve(points, 4);

   path.Widen(&greenPen);
   graphics.DrawPath(&bluePen, &path);

   path.Outline();

   graphics.TranslateTransform(180.0f, 0.0f);
   graphics.DrawPath(&bluePen, &path);
}


PowerBASIC


SUB GDIP_WindingModeOutline (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pBluePen AS DWORD
   LOCAL pGreenPen AS DWORD
   DIM   pts(3) AS POINTF
   LOCAL result AS LONG
   LOCAL i AS LONG

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 255), 1, %UnitWorld, pBluePen)
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 255, 0), 10, %UnitWorld, pGreenPen)

   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

   pts(0).x = 20  : pts(0).y = 20
   pts(1).x = 160 : pts(1).y = 100
   pts(2).x = 140 : pts(2).y = 60
   pts(3).x = 60  : pts(3).y = 100

   hStatus = GdipAddPathClosedCurve(pPath, pts(0), 4)

   hStatus = GdipWidenPath(pPath, pGreenPen, %NULL, FlatnessDefault)
   hStatus = GdipDrawPath(pGraphics, pBluePen, pPath)
   hStatus = GdipWindingModeOutline(pPath, %NULL, FlatnessDefault)
   hStatus = GdipTranslateWorldTransform(pGraphics, 180, 0, %MatrixOrderPrepend)
   hStatus = GdipDrawPath(pGraphics, pBluePen, pPath)

   ' // Cleanup
   IF pBluePen THEN GdipDeletePen(pBluePen)
   IF pGreenPen THEN GdipDeletePen(pGreenPen)
   IF pPath THEN GdipDeletePath(pPath)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB