• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipIsOutlineVisiblePathPoint

Started by José Roca, June 22, 2008, 05:53:21 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates an elliptical path and draws that path with a wide yellow pen. Then the code tests each point in an array to see whether the point touches the outline (as it would be drawn by the wide yellow pen) of the path. Points that touch the outline are painted green, and points that don't touch the outline are painted red.

C++


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

   INT j;
   Pen yellowPen(Color(255, 255, 255, 0), 20);
   SolidBrush brush(Color(255, 255, 0,  0));

   // Create and draw a path.
   GraphicsPath path;
   path.AddEllipse(50, 50, 200, 100);
   graphics.DrawPath(&yellowPen, &path);

   // Create an array of three points, and determine whether each
   // point in the array touches the outline of the path.
   // If a point touches the outline, paint it green.
   // If a point does not touch the outline, paint it red.
   PointF[] = {
      PointF(230, 138),
      PointF(100, 120),
      PointF(150, 170)};

   for(j = 0; j <= 2; ++j)
   {
      if(path.IsOutlineVisible(points[j].X, points[j].Y, &yellowPen, NULL))
         brush.SetColor(Color(255, 0, 255,  0));
      else
         brush.SetColor(Color(255, 255, 0,  0));
   
      graphics.FillEllipse(&brush, points[j].X - 3.0f, points[j].Y - 3.0f, 6.0f, 6.0f);
   }
}


PowerBASIC


SUB GDIP_IsOutlineVisible (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pYellowPen AS DWORD
   LOCAL pBrush AS DWORD
   DIM   pts(2) AS POINTF
   LOCAL result AS LONG
   LOCAL i AS LONG

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 255, 0), 20, %UnitWorld, pYellowPen)
   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pBrush)

   ' // Create and draw a path.
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)
   hStatus = GdipAddPathEllipse(pPath, 50, 50, 200, 100)
   hStatus = GdipDrawPath(pGraphics, pYellowPen, pPath)

   ' // Create an array of three points, and determine whether each
   ' // point in the array touches the outline of the path.
   ' // If a point touches the outline, paint it green.
   ' // If a point does not touch the outline, paint it red.

   pts(0).x = 230 : pts(0).y = 138
   pts(1).x = 100 : pts(1).y = 120
   pts(2).x = 150 : pts(2).y = 170

   FOR i = 0 TO 2
      hStatus = GdipIsOutlineVisiblePathPoint(pPath, pts(i).x, pts(i).y, pYellowPen, %NULL, result)
      IF result THEN
         hStatus = GdipSetSolidFillColor(pBrush, GDIP_ARGB(255, 0, 255, 0))
      ELSE
         hStatus = GdipSetSolidFillColor(pBrush, GDIP_ARGB(255, 255, 0, 0))
      END IF
      hStatus = GdipFillEllipse(pGraphics, pBrush, pts(i).x - 3, pts(i).y - 3, 6, 6)
   NEXT

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

END SUB