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);
                }
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
                    }
                }
            }
        }