コード例 #1
0
ファイル: Flag.cs プロジェクト: charlierix/AsteroidMiner
        private static void DrawOverlay(DrawingContext dc, Size size, FlagOverlay overlay)
        {
            double halfWidth = size.Width / 2d;
            double halfHeight = size.Height / 2d;
            double halfStripe = (Math.Min(size.Width, size.Height) * .15) / 2d;
            double smallCircleRadius = Math.Min(size.Width, size.Height) / 5;
            double smallCircleX = size.Width / 4;

            Geometry geometry;

            switch (overlay.Type)
            {
                case FlagOverlayType.Border:
                    #region Border

                    double borderSize = Math.Min(size.Width, size.Height) * .075;

                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, 0, size.Width, borderSize));
                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, size.Height - borderSize, size.Width, borderSize));

                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, borderSize, borderSize, size.Height - (borderSize * 2)));
                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(size.Width - borderSize, borderSize, borderSize, size.Height - (borderSize * 2)));

                    #endregion
                    break;

                case FlagOverlayType.Horizontal_One:
                    #region Horizontal_One

                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, halfHeight - halfStripe, size.Width, halfStripe * 2));

                    #endregion
                    break;

                case FlagOverlayType.Horizontal_Two:
                    #region Horizontal_Two

                    double startY = size.Height - (halfStripe * 4);     // remaining height
                    startY /= 3;        // remaining split in 3
                    startY += halfStripe;

                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, startY - halfStripe, size.Width, halfStripe * 2));
                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, size.Height - startY - halfStripe, size.Width, halfStripe * 2));

                    #endregion
                    break;

                case FlagOverlayType.Vertical_One:
                    #region Vertical

                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(halfWidth - halfStripe, 0, halfStripe * 2, size.Height));

                    #endregion
                    break;

                case FlagOverlayType.Vertical_Two:
                    #region Vertical

                    double startX = size.Width - (halfStripe * 4);     // remaining width
                    startX /= 3;        // remaining split in 3
                    startX += halfStripe;

                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(startX - halfStripe, 0, halfStripe * 2, size.Height));
                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(size.Width - startX - halfStripe, 0, halfStripe * 2, size.Height));

                    #endregion
                    break;

                case FlagOverlayType.Cross:
                    #region Cross

                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, halfHeight - halfStripe, size.Width, halfStripe * 2));
                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(halfWidth - halfStripe, 0, halfStripe * 2, size.Height));

                    #endregion
                    break;

                case FlagOverlayType.Diagonal_Down:
                    #region Diagonal_Down

                    Vector intersects1 = GetStipeIntersect(size, halfStripe);

                    geometry = GetClosedGeometry(new[] 
                        {
                            new Point(0, 0),
                            new Point(intersects1.X, 0),
                            new Point(size.Width, size.Height - intersects1.Y),
                            new Point(size.Width, size.Height),
                            new Point(size.Width - intersects1.X, size.Height),
                            new Point(0, intersects1.Y),
                        });

                    dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                    #endregion
                    break;

                case FlagOverlayType.Diagonal_Up:
                    #region Diagonal_Up

                    Vector intersects2 = GetStipeIntersect(size, halfStripe);

                    geometry = GetClosedGeometry(new[] 
                        {
                            new Point(0, size.Height),
                            new Point(intersects2.X, size.Height),
                            new Point(size.Width, intersects2.Y),
                            new Point(size.Width, 0),
                            new Point(size.Width - intersects2.X, 0),
                            new Point(0, size.Height - intersects2.Y),
                        });

                    dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                    #endregion
                    break;

                case FlagOverlayType.X:
                    #region X

                    Vector intersects3 = GetStipeIntersect(size, halfStripe);

                    geometry = GetClosedGeometry(new[] 
                        {
                            // TL
                            new Point(0, intersects3.Y),
                            new Point(0, 0),
                            new Point(intersects3.X, 0),

                            new Point(halfWidth, halfHeight - intersects3.Y),

                            // TR
                            new Point(size.Width - intersects3.X, 0),
                            new Point(size.Width, 0),
                            new Point(size.Width, intersects3.Y),

                            new Point(halfWidth + intersects3.X, halfHeight),

                            // BR
                            new Point(size.Width, size.Height - intersects3.Y),
                            new Point(size.Width, size.Height),
                            new Point(size.Width - intersects3.X, size.Height),

                            new Point(halfWidth, halfHeight + intersects3.Y),

                            // BL
                            new Point(intersects3.X, size.Height),
                            new Point(0, size.Height),
                            new Point(0, size.Height - intersects3.Y),

                            new Point(halfWidth - intersects3.X, halfHeight),
                        });

                    dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                    #endregion
                    break;

                case FlagOverlayType.Triangle_Left:
                    #region Triangle_Left

                    geometry = GetClosedGeometry(new[] 
                        {
                            new Point(0, 0),
                            new Point(halfWidth, halfHeight),
                            new Point(0, size.Height),
                        });

                    dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                    #endregion
                    break;

                case FlagOverlayType.Triangle_Top:
                    #region Triangle_Top

                    geometry = GetClosedGeometry(new[] 
                        {
                            new Point(0, 0),
                            new Point(halfWidth, halfHeight),
                            new Point(size.Width, 0),
                        });

                    dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                    #endregion
                    break;

                case FlagOverlayType.Triangle_Right:
                    #region Triangle_Right

                    geometry = GetClosedGeometry(new[] 
                        {
                            new Point(size.Width, 0),
                            new Point(halfWidth, halfHeight),
                            new Point(size.Width, size.Height),
                        });

                    dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                    #endregion
                    break;

                case FlagOverlayType.Triangle_Bottom:
                    #region Triangle_Bottom

                    geometry = GetClosedGeometry(new[] 
                        {
                            new Point(0, size.Height),
                            new Point(halfWidth, halfHeight),
                            new Point(size.Width, size.Height),
                        });

                    dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                    #endregion
                    break;

                case FlagOverlayType.Circle_Large:
                    #region Circle_Large

                    double radius1 = Math.Min(size.Width, size.Height) / 3;

                    dc.DrawEllipse(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Point(halfWidth, halfHeight), radius1, radius1);

                    #endregion
                    break;

                case FlagOverlayType.Circle_Small_Left:
                    #region Circle_Small_Left

                    dc.DrawEllipse(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Point(smallCircleX, halfHeight), smallCircleRadius, smallCircleRadius);

                    #endregion
                    break;

                case FlagOverlayType.Circle_Small_Right:
                    #region Circle_Small_Right

                    dc.DrawEllipse(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Point(size.Width - smallCircleX, halfHeight), smallCircleRadius, smallCircleRadius);

                    #endregion
                    break;

                case FlagOverlayType.Circle_Small_Two:
                    #region Circle_Small_Two

                    dc.DrawEllipse(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Point(smallCircleX, halfHeight), smallCircleRadius, smallCircleRadius);
                    dc.DrawEllipse(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Point(size.Width - smallCircleX, halfHeight), smallCircleRadius, smallCircleRadius);

                    #endregion
                    break;

                case FlagOverlayType.Diamond:
                    #region Diamond

                    geometry = GetClosedGeometry(new[] 
                        {
                            new Point(0, halfHeight),
                            new Point(halfWidth, 0),
                            new Point(size.Width, halfHeight),
                            new Point(halfWidth, size.Height),
                        });

                    dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                    #endregion
                    break;

                case FlagOverlayType.CornerRect:
                    #region CornerRect

                    dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, 0, halfWidth, halfHeight));

                    #endregion
                    break;

                default:
                    throw new ApplicationException("Unknown FlagOverlayType: " + overlay.Type.ToString());
            }
        }
コード例 #2
0
        private static void DrawOverlay(DrawingContext dc, Size size, FlagOverlay overlay)
        {
            double halfWidth         = size.Width / 2d;
            double halfHeight        = size.Height / 2d;
            double halfStripe        = (Math.Min(size.Width, size.Height) * .15) / 2d;
            double smallCircleRadius = Math.Min(size.Width, size.Height) / 5;
            double smallCircleX      = size.Width / 4;

            Geometry geometry;

            switch (overlay.Type)
            {
            case FlagOverlayType.Border:
                #region Border

                double borderSize = Math.Min(size.Width, size.Height) * .075;

                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, 0, size.Width, borderSize));
                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, size.Height - borderSize, size.Width, borderSize));

                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, borderSize, borderSize, size.Height - (borderSize * 2)));
                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(size.Width - borderSize, borderSize, borderSize, size.Height - (borderSize * 2)));

                #endregion
                break;

            case FlagOverlayType.Horizontal_One:
                #region Horizontal_One

                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, halfHeight - halfStripe, size.Width, halfStripe * 2));

                #endregion
                break;

            case FlagOverlayType.Horizontal_Two:
                #region Horizontal_Two

                double startY = size.Height - (halfStripe * 4); // remaining height
                startY /= 3;                                    // remaining split in 3
                startY += halfStripe;

                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, startY - halfStripe, size.Width, halfStripe * 2));
                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, size.Height - startY - halfStripe, size.Width, halfStripe * 2));

                #endregion
                break;

            case FlagOverlayType.Vertical_One:
                #region Vertical

                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(halfWidth - halfStripe, 0, halfStripe * 2, size.Height));

                #endregion
                break;

            case FlagOverlayType.Vertical_Two:
                #region Vertical

                double startX = size.Width - (halfStripe * 4); // remaining width
                startX /= 3;                                   // remaining split in 3
                startX += halfStripe;

                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(startX - halfStripe, 0, halfStripe * 2, size.Height));
                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(size.Width - startX - halfStripe, 0, halfStripe * 2, size.Height));

                #endregion
                break;

            case FlagOverlayType.Cross:
                #region Cross

                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, halfHeight - halfStripe, size.Width, halfStripe * 2));
                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(halfWidth - halfStripe, 0, halfStripe * 2, size.Height));

                #endregion
                break;

            case FlagOverlayType.Diagonal_Down:
                #region Diagonal_Down

                Vector intersects1 = GetStipeIntersect(size, halfStripe);

                geometry = GetClosedGeometry(new[]
                {
                    new Point(0, 0),
                    new Point(intersects1.X, 0),
                    new Point(size.Width, size.Height - intersects1.Y),
                    new Point(size.Width, size.Height),
                    new Point(size.Width - intersects1.X, size.Height),
                    new Point(0, intersects1.Y),
                });

                dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                #endregion
                break;

            case FlagOverlayType.Diagonal_Up:
                #region Diagonal_Up

                Vector intersects2 = GetStipeIntersect(size, halfStripe);

                geometry = GetClosedGeometry(new[]
                {
                    new Point(0, size.Height),
                    new Point(intersects2.X, size.Height),
                    new Point(size.Width, intersects2.Y),
                    new Point(size.Width, 0),
                    new Point(size.Width - intersects2.X, 0),
                    new Point(0, size.Height - intersects2.Y),
                });

                dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                #endregion
                break;

            case FlagOverlayType.X:
                #region X

                Vector intersects3 = GetStipeIntersect(size, halfStripe);

                geometry = GetClosedGeometry(new[]
                {
                    // TL
                    new Point(0, intersects3.Y),
                    new Point(0, 0),
                    new Point(intersects3.X, 0),

                    new Point(halfWidth, halfHeight - intersects3.Y),

                    // TR
                    new Point(size.Width - intersects3.X, 0),
                    new Point(size.Width, 0),
                    new Point(size.Width, intersects3.Y),

                    new Point(halfWidth + intersects3.X, halfHeight),

                    // BR
                    new Point(size.Width, size.Height - intersects3.Y),
                    new Point(size.Width, size.Height),
                    new Point(size.Width - intersects3.X, size.Height),

                    new Point(halfWidth, halfHeight + intersects3.Y),

                    // BL
                    new Point(intersects3.X, size.Height),
                    new Point(0, size.Height),
                    new Point(0, size.Height - intersects3.Y),

                    new Point(halfWidth - intersects3.X, halfHeight),
                });

                dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                #endregion
                break;

            case FlagOverlayType.Triangle_Left:
                #region Triangle_Left

                geometry = GetClosedGeometry(new[]
                {
                    new Point(0, 0),
                    new Point(halfWidth, halfHeight),
                    new Point(0, size.Height),
                });

                dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                #endregion
                break;

            case FlagOverlayType.Triangle_Top:
                #region Triangle_Top

                geometry = GetClosedGeometry(new[]
                {
                    new Point(0, 0),
                    new Point(halfWidth, halfHeight),
                    new Point(size.Width, 0),
                });

                dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                #endregion
                break;

            case FlagOverlayType.Triangle_Right:
                #region Triangle_Right

                geometry = GetClosedGeometry(new[]
                {
                    new Point(size.Width, 0),
                    new Point(halfWidth, halfHeight),
                    new Point(size.Width, size.Height),
                });

                dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                #endregion
                break;

            case FlagOverlayType.Triangle_Bottom:
                #region Triangle_Bottom

                geometry = GetClosedGeometry(new[]
                {
                    new Point(0, size.Height),
                    new Point(halfWidth, halfHeight),
                    new Point(size.Width, size.Height),
                });

                dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                #endregion
                break;

            case FlagOverlayType.Circle_Large:
                #region Circle_Large

                double radius1 = Math.Min(size.Width, size.Height) / 3;

                dc.DrawEllipse(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Point(halfWidth, halfHeight), radius1, radius1);

                #endregion
                break;

            case FlagOverlayType.Circle_Small_Left:
                #region Circle_Small_Left

                dc.DrawEllipse(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Point(smallCircleX, halfHeight), smallCircleRadius, smallCircleRadius);

                #endregion
                break;

            case FlagOverlayType.Circle_Small_Right:
                #region Circle_Small_Right

                dc.DrawEllipse(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Point(size.Width - smallCircleX, halfHeight), smallCircleRadius, smallCircleRadius);

                #endregion
                break;

            case FlagOverlayType.Circle_Small_Two:
                #region Circle_Small_Two

                dc.DrawEllipse(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Point(smallCircleX, halfHeight), smallCircleRadius, smallCircleRadius);
                dc.DrawEllipse(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Point(size.Width - smallCircleX, halfHeight), smallCircleRadius, smallCircleRadius);

                #endregion
                break;

            case FlagOverlayType.Diamond:
                #region Diamond

                geometry = GetClosedGeometry(new[]
                {
                    new Point(0, halfHeight),
                    new Point(halfWidth, 0),
                    new Point(size.Width, halfHeight),
                    new Point(halfWidth, size.Height),
                });

                dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, geometry);

                #endregion
                break;

            case FlagOverlayType.CornerRect:
                #region CornerRect

                dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(overlay.Color)), null, new Rect(0, 0, halfWidth, halfHeight));

                #endregion
                break;

            default:
                throw new ApplicationException("Unknown FlagOverlayType: " + overlay.Type.ToString());
            }
        }