private void DrawRegion(Graphics graphics, Color color, bool drawPoints, bool fill, BTBLib.Region region)
{
Pen pen = new Pen(color, _regionPenWidth / _zoom);
Brush brush = new SolidBrush(color);
Point[] points = null;
bool shouldFill = fill && region.IsClosed;
if (shouldFill)
{
points = new Point[region.Lines.Count];
}
for (int i = 0; i < region.Lines.Count; ++i)
{
var segment = region.Lines[i];
int startX = segment.StartX / 8;
int startY = (_battle.Height - segment.StartY) / 8;
int endX = segment.EndX / 8;
int endY = (_battle.Height - segment.EndY) / 8;
graphics.DrawLine(pen, startX, startY, endX, endY);
if (drawPoints)
{
graphics.FillRectangle(brush, startX - _regionPointSize / 2, startY - _regionPointSize / 2, _regionPointSize, _regionPointSize);
}
if (shouldFill)
{
points[i] = new Point(startX, startY);
}
}
if (drawPoints)
{
if (!region.IsClosed && region.Lines.Count > 0)
{
BTBLib.Region.LineSegment segment = region.Lines[region.Lines.Count - 1];
int endX = segment.EndX / 8;
int endY = (_battle.Height - segment.EndY) / 8;
graphics.FillRectangle(brush, endX - _regionPointSize / 2, endY - _regionPointSize / 2, _regionPointSize, _regionPointSize);
}
}
if (shouldFill)
{
Brush regionBrush = new SolidBrush(Color.FromArgb(128, color.R, color.G, color.B));
if (region.IsBoundaryInversed)
{
System.Drawing.Region graphicsRegion = new System.Drawing.Region();
graphicsRegion.MakeInfinite();
GraphicsPath path = new GraphicsPath();
path.AddPolygon(points);
graphicsRegion.Exclude(path);
graphics.FillRegion(regionBrush, graphicsRegion);
}
else
{
graphics.FillPolygon(regionBrush, points);
}
}
}