protected override void PaintSquare(Graphics graphics, Rectangle clipRectangle, int pipeWidth, bool isHighlighted, bool isFrozen, bool isFlooded, FloodProgress floodProgress) { /* paint square as usual */ this.PaintSquare(graphics, clipRectangle, pipeWidth, isHighlighted, isFrozen, isFlooded); int x = (clipRectangle.Width - pipeWidth) / 2; int y = clipRectangle.Y; int w = pipeWidth; int h = clipRectangle.Height; /* flooding ? */ if (!isFlooded) { /* calculate height to fill */ int fill = floodProgress.GetRatio(clipRectangle.Height); /* check direction */ if (floodProgress.Direction == Direction.Down) { /* flood rectangle */ Rectangle floodRectangle = new Rectangle(x, y, w, fill); /* fill rectangle */ graphics.FillRectangle(Brushes.Red, floodRectangle); } else if (floodProgress.Direction == Direction.Up) { /* flood rectangle */ Rectangle floodRectangle = new Rectangle(x, h - fill, w, fill); /* fill rectangle */ graphics.FillRectangle(Brushes.Red, floodRectangle); } } }
protected override void PaintSquare(Graphics graphics, Rectangle clipRectangle, int pipeWidth, bool isHighlighted, bool isFrozen, bool isFlooded, FloodProgress floodProgress) { /* paint square as usual */ this.PaintSquare(graphics, clipRectangle, pipeWidth, isHighlighted, isFrozen, isFlooded); /* flooding ? */ if (!isFlooded) { /* calculate height to fill */ int fill = floodProgress.GetRatio(clipRectangle.Height - ((clipRectangle.Height - pipeWidth) / 2)); int x = (clipRectangle.Width - pipeWidth) / 2; int y = clipRectangle.Height - ((clipRectangle.Height - pipeWidth) / 2) - fill; int w = pipeWidth; int h = fill; /* flood rectangle */ Rectangle floodRectangle = new Rectangle(x, y, w, h); /* fill rectangle */ graphics.FillRectangle(Brushes.Red, floodRectangle); } }
protected override void PaintSquare(Graphics graphics, Rectangle clipRectangle, int pipeWidth, bool isHighlighted, bool isFrozen, bool isFlooded, FloodProgress floodProgress) { /* paint square as usual */ this.PaintSquare(graphics, clipRectangle, pipeWidth, isHighlighted, isFrozen, isFlooded); /* flooding ? */ if (!isFlooded) { /* going down */ if (floodProgress.Direction == Direction.Down) { /* water flows from down to left, pipe is edged and not rounded, * therefore calculation is quite easy. the total way to progress is sum of * pipes height and width * (10 down until edge start + 10 down until corner + 10 left until edge end + 10 left until pipe end) * */ int fill = floodProgress.GetRatio(clipRectangle.Height - 10 + clipRectangle.Width - 10); /* strategy to fill pipe is to draw three distinct sections: * first, we fill from up until begin of edging corner * second, we fill edging corner with simple polygon * third, we fill from right to left until end. * */ int rectangleFill = (clipRectangle.Height - pipeWidth) / 2; int firstFill = rectangleFill; int secondFill = rectangleFill + pipeWidth * 2; int thirdFill = rectangleFill * 2 + pipeWidth * 2; if (fill < firstFill) { /* first section */ int x = (clipRectangle.Width - pipeWidth) / 2; int y = clipRectangle.Y; int w = pipeWidth; int h = fill; /* flood rectangle */ Rectangle floodRectangle = new Rectangle(x, y, w, h); /* fill rectangle */ graphics.FillRectangle(Brushes.Red, floodRectangle); } else if (fill < secondFill - pipeWidth) /* +10 to move to corner of edge */ { /* second section from start up to edge */ /* fill first section's rectangle */ int x = (clipRectangle.Width - pipeWidth) / 2; int y = clipRectangle.Y; int w = pipeWidth; int h = clipRectangle.Height - x - pipeWidth; Rectangle floodRectangle = new Rectangle(x, y, w, h); graphics.FillRectangle(Brushes.Red, floodRectangle); /* up to edge, first get edging rectangle */ int px = (clipRectangle.Width - pipeWidth) / 2; int py = (clipRectangle.Height - pipeWidth) / 2; int pw = pipeWidth; int ph = pipeWidth; /* get delta to fill */ int delta = fill - firstFill; /* build poly */ Point point1 = new Point(px, py); Point point2 = new Point(px + pw, py); Point point3 = new Point(px + pw, py + delta); /* fill poly */ graphics.FillPolygon(Brushes.Red, new Point[] { point1, point2, point3 }); } else if (fill < secondFill) /* +10 to move from corner to end of edge */ { /* second section from edge up to end */ /* fill first section's rectangle */ int x = (clipRectangle.Width - pipeWidth) / 2; int y = clipRectangle.Y; int w = pipeWidth; int h = clipRectangle.Height - x - pipeWidth; Rectangle floodRectangle = new Rectangle(x, y, w, h); graphics.FillRectangle(Brushes.Red, floodRectangle); /* up to edge, first get edging rectangle */ int px = (clipRectangle.Width - pipeWidth) / 2; int py = (clipRectangle.Height - pipeWidth) / 2; int pw = pipeWidth; int ph = pipeWidth; /* get delta to fill */ int delta = fill - firstFill - pipeWidth; /* build poly */ Point point1 = new Point(px, py); Point point2 = new Point(px + pw, py); Point point3 = new Point(px + pw, py + ph); Point point4 = new Point(px + pw - delta, py + ph); /* fill poly */ graphics.FillPolygon(Brushes.Red, new Point[] { point1, point2, point3, point4 }); } else { /* third section */ /* fill first and second section's rectangle */ int x = (clipRectangle.Width - pipeWidth) / 2; int y = clipRectangle.Y; int w = pipeWidth; int h = clipRectangle.Height - x; Rectangle floodRectangle = new Rectangle(x, y, w, h); graphics.FillRectangle(Brushes.Red, floodRectangle); /* get delta to fill */ int delta = fill - secondFill; /* fill last section */ x = ((clipRectangle.Width - pipeWidth) / 2) - delta; y = (clipRectangle.Height - pipeWidth) / 2; w = delta; h = pipeWidth; /* flood rectangle */ floodRectangle = new Rectangle(x, y, w, h); /* fill rectangle */ graphics.FillRectangle(Brushes.Red, floodRectangle); } } /* going right */ if (floodProgress.Direction == Direction.Right) { int fill = floodProgress.GetRatio(clipRectangle.Height - 10 + clipRectangle.Width - 10); int rectangleFill = (clipRectangle.Height - pipeWidth) / 2; int firstFill = rectangleFill; int secondFill = rectangleFill + pipeWidth * 2; int thirdFill = rectangleFill * 2 + pipeWidth * 2; if (fill < firstFill) { /* first section */ int x = clipRectangle.X; int y = (clipRectangle.Height - pipeWidth) / 2; int w = fill; int h = pipeWidth; /* flood rectangle */ Rectangle floodRectangle = new Rectangle(x, y, w, h); /* fill rectangle */ graphics.FillRectangle(Brushes.Red, floodRectangle); } else if (fill < secondFill - pipeWidth) /* +10 to move to corner of edge */ { /* second section from start up to edge */ /* fill first section's rectangle */ int x = clipRectangle.X; int y = (clipRectangle.Height - pipeWidth) / 2; int w = (clipRectangle.Width - pipeWidth) / 2; int h = pipeWidth; Rectangle floodRectangle = new Rectangle(x, y, w, h); graphics.FillRectangle(Brushes.Red, floodRectangle); /* up to edge, first get edging rectangle */ int px = (clipRectangle.Width - pipeWidth) / 2; int py = (clipRectangle.Height - pipeWidth) / 2; int pw = pipeWidth; int ph = pipeWidth; /* get delta to fill */ int delta = fill - firstFill; /* build poly */ Point point1 = new Point(px, py); Point point2 = new Point(px, py + ph); Point point3 = new Point(px + delta, py + ph); /* fill poly */ graphics.FillPolygon(Brushes.Red, new Point[] { point1, point2, point3 }); } else if (fill < secondFill) /* +10 to move from corner to end of edge */ { /* second section from edge up to end */ /* fill first section's rectangle */ int x = clipRectangle.X; int y = (clipRectangle.Height - pipeWidth) / 2; int w = (clipRectangle.Width - pipeWidth) / 2; int h = pipeWidth; Rectangle floodRectangle = new Rectangle(x, y, w, h); graphics.FillRectangle(Brushes.Red, floodRectangle); /* up to edge, first get edging rectangle */ int px = (clipRectangle.Width - pipeWidth) / 2; int py = (clipRectangle.Height - pipeWidth) / 2; int pw = pipeWidth; int ph = pipeWidth; /* get delta to fill */ int delta = fill - firstFill - pipeWidth; /* build poly */ Point point1 = new Point(px, py); Point point2 = new Point(px, py + ph); Point point3 = new Point(px + pw, py + ph); Point point4 = new Point(px + pw, py + ph - delta); /* fill poly */ graphics.FillPolygon(Brushes.Red, new Point[] { point1, point2, point3, point4 }); } else { /* third section */ /* fill first and second section's rectangle */ int x = clipRectangle.X; int y = (clipRectangle.Height - pipeWidth) / 2; int w = (clipRectangle.Width - pipeWidth) / 2 + pipeWidth; int h = pipeWidth; Rectangle floodRectangle = new Rectangle(x, y, w, h); graphics.FillRectangle(Brushes.Red, floodRectangle); /* get delta to fill */ int delta = fill - secondFill; /* fill last section */ x = (clipRectangle.Width - pipeWidth) / 2; y = ((clipRectangle.Height - pipeWidth) / 2) - delta; w = pipeWidth; h = delta; /* flood rectangle */ floodRectangle = new Rectangle(x, y, w, h); /* fill rectangle */ graphics.FillRectangle(Brushes.Red, floodRectangle); } } } }
protected abstract void PaintSquare(Graphics graphics, Rectangle clipRectangle, int pipeWidth, bool isHighlighted, bool isFrozen, bool isFlooded, FloodProgress floodProgress);
/// <summary> /// Paints square. /// </summary> /// <param name="graphics">The graphics to paint square on.</param> /// <param name="clipRectangle">The clip rectangle (painting area).</param> /// <param name="pipeWidth">The pipe width to paint on pipe squares.</param> /// <param name="isHighlighted">Indicates whether to paint square highlighted or not.</param> /// <param name="isFrozen">Indicates whether to paint square frozen or not.</param> /// <param name="isFlooded">Indicates whether to paint pipe square flooded or not.</param> /// <param name="floodProgress">The flooding progress.</param> public virtual void Paint(Graphics graphics, Rectangle clipRectangle, int pipeWidth, bool isHighlighted, bool isFrozen, bool isFlooded, FloodProgress floodProgress) { this.PaintBackground(graphics, clipRectangle, pipeWidth, isHighlighted, isFrozen, isFlooded); this.PaintSquare(graphics, clipRectangle, pipeWidth, isHighlighted, isFrozen, isFlooded, floodProgress); this.PaintForeGround(graphics, clipRectangle, pipeWidth, isHighlighted, isFrozen, isFlooded); }
protected override void PaintSquare(Graphics graphics, Rectangle clipRectangle, int pipeWidth, bool isHighlighted, bool isFrozen, bool isFlooded, FloodProgress floodProgress) { /* don't support flood paint */ throw new InvalidOperationException(); }
protected override void OnPaint(PaintEventArgs pe) { /* do we have a painter */ if (this.squarePainter != null) { /* flooding? */ if (this.IsFlooding) { /* yes, let's build a flood progress state and paint */ FloodProgress floodProgress = new FloodProgress((int)Math.Floor(this.floodDuration.TotalMilliseconds), (int)Math.Floor(this.floodElapsed.TotalMilliseconds), this.floodDirection); this.squarePainter.Paint(pe.Graphics, pe.ClipRectangle, this.pipeWidth, this.isHighlighted, this.isFrozen, this.isFlooded, floodProgress); } else { /* paint square the usual way */ this.squarePainter.Paint(pe.Graphics, pe.ClipRectangle, this.pipeWidth, this.isHighlighted, this.isFrozen, this.isFlooded); } } /* call base painter */ base.OnPaint(pe); }