• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipIsVisiblePathPoint

Started by José Roca, June 22, 2008, 05:56:13 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 narrow black pen. Then the code tests each point in an array to see whether the point lies in the interior of the path. Points that lie in the interior are painted green, and points that do not lie in the interior are painted red.

C++


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

   INT j;
   Pen blackPen(Color(255, 0, 0, 0), 1);
   SolidBrush brush(Color(255, 255, 0, 0));

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

   // Create an array of four 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(50, 100),
      PointF(250, 100),
      PointF(150, 170),
      PointF(180, 60)};

   for(j = 0; j <= 3; ++j)
   {
      if(path.IsVisible(points[j].X, points[j].Y, &graphics))
         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_IsVisiblePoint (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pBlackPen AS DWORD
   LOCAL pBrush AS DWORD
   DIM   pts(3) AS POINTF
   LOCAL result AS LONG
   LOCAL i AS LONG

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 255, 0), 1, %UnitWorld, pBlackPen)
   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, pBlackPen, pPath)

   ' // Create an array of four 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 = 50  : pts(0).y = 100
   pts(1).x = 250 : pts(1).y = 100
   pts(2).x = 150 : pts(2).y = 170
   pts(3).x = 180 : pts(3).y = 60

   FOR i = 0 TO 3
      hStatus = GdipIsVisiblePathPoint(pPath, pts(i).x, pts(i).y, pGraphics, 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 pBlackPen THEN GdipDeletePen(pBlackPen)
   IF pPath THEN GdipDeletePath(pPath)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB