コード例 #1
0
 /// <summary>
 /// Retuirns the BoundingRectangle of the shape.
 /// This default implementation uses the GetBounds() method provided by the GraphicsPath class.
 /// It is recommended to override this method with more shape specific versions that do not call base.
 /// </summary>
 /// <param name="tight">
 /// If true, a thight fitting x axis aligned bounding rectangle will be returned.
 /// If false, a x axis aligned bounding rectangle also containing all control points will be returned.
 /// </param>
 protected override Rectangle CalculateBoundingRectangle(bool tight)
 {
     if (tight)
     {
         Rectangle result = Rectangle.Empty;
         if (DrawCacheIsInvalid)
         {
             CalculatePath();
             result = Rectangle.Ceiling(Path.GetBounds());
             if (Angle != 0)
             {
                 Point tl, tr, bl, br;
                 Geometry.RotateRectangle(result, Point.Empty, Geometry.TenthsOfDegreeToDegrees(Angle), out tl, out tr, out bl, out br);
                 Geometry.CalcBoundingRectangle(tl, tr, bl, br, out result);
             }
             result.Offset(X, Y);
         }
         else
         {
             result = Rectangle.Ceiling(Path.GetBounds());
         }
         ShapeUtils.InflateBoundingRectangle(ref result, LineStyle);
         return(result);
     }
     else
     {
         Rectangle result = Rectangle.Empty;
         if (DrawCacheIsInvalid)
         {
             CalcControlPoints();
             Point tl = Point.Empty, tr = Point.Empty, bl = Point.Empty, br = Point.Empty;
             for (int i = ControlPoints.Length - 1; i >= 0; --i)
             {
                 Point pt = ControlPoints[i];
                 if (pt.X <= tl.X && pt.Y <= tl.Y)
                 {
                     tl = pt;
                 }
                 if (pt.X >= tr.X && pt.Y <= tr.Y)
                 {
                     tr = pt;
                 }
                 if (pt.X <= bl.X && pt.Y >= bl.Y)
                 {
                     bl = pt;
                 }
                 if (pt.X >= br.X && pt.Y >= br.Y)
                 {
                     br = pt;
                 }
             }
             if (Angle != 0)
             {
                 tl = Geometry.RotatePoint(Point.Empty, Geometry.TenthsOfDegreeToDegrees(Angle), tl);
                 tr = Geometry.RotatePoint(Point.Empty, Geometry.TenthsOfDegreeToDegrees(Angle), tr);
                 bl = Geometry.RotatePoint(Point.Empty, Geometry.TenthsOfDegreeToDegrees(Angle), bl);
                 br = Geometry.RotatePoint(Point.Empty, Geometry.TenthsOfDegreeToDegrees(Angle), br);
             }
             Geometry.CalcBoundingRectangle(tl, tr, bl, br, out result);
             result.Offset(X, Y);
         }
         else
         {
             Geometry.CalcBoundingRectangle(ControlPoints, out result);
         }
         return(result);
     }
 }