There’s probably a lot of ways to do it. Here’s one that clips the drawing as the Paint happens:
public class ClippedPolygon : GoPolygon {
public override void Paint(Graphics g, GoView view) {
RectangleF b = this.Bounds;
RectangleF rect = new RectangleF(b.Left, b.Top+40, b.Width, b.Height-40);
// handle clipping, if bounds is different from actual polygon
bool clipping = true; //this.Clipping;
Region oldClip = null;
Region newClip = null;
if (clipping) {
// intersect text rect with clipping rect
RectangleF cliprect = IntersectionRect(rect, g.ClipBounds);
oldClip = g.Clip;
newClip = new Region(cliprect);
g.Clip = newClip;
}
base.Paint(g, view);
if (clipping && oldClip != null)
g.Clip = oldClip;
if (newClip != null)
newClip.Dispose();
}
internal static RectangleF IntersectionRect(RectangleF a, RectangleF b) {
float maxx = Math.Max(a.X, b.X);
float maxy = Math.Max(a.Y, b.Y);
float minr = Math.Min(a.X + a.Width, b.X + b.Width);
float minb = Math.Min(a.Y + a.Height, b.Y + b.Height);
return new RectangleF(maxx, maxy, Math.Max(0, minr - maxx), Math.Max(0, minb - maxy));
}
}
compare with:
GoPolygon poly = new GoPolygon();
poly.AddPoint(100, 100);
poly.AddPoint(220, 0);
poly.AddPoint(280, 120);
poly.AddPoint(100, 100);
poly.BrushColor = Color.Blue;
doc.Add(poly);
ClippedPolygon poly2 = new ClippedPolygon();
poly2.AddPoint(100, 100);
poly2.AddPoint(220, 0);
poly2.AddPoint(280, 120);
poly2.AddPoint(100, 100);
poly2.BrushColor = Color.Red;
doc.Add(poly2);
note... the "40", that's how much I clip the shape. You'd probably want to parameterize that.
Now... this has some issues. The selection area is still the full shape. But that might not matter if this is the foreground of some full sized object and this object isn't selectable.
You could override ComputeBounds to fix that.