Example #1
0
        public virtual void AddDefaultStyles()
        {
            var freePointStyle     = new PointStyle();
            var pointOnFigureStyle = new PointStyle()
            {
                Fill = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0))
            };
            var dependentPointStyle = new PointStyle()
            {
                Fill = new SolidColorBrush(Color.FromArgb(255, 192, 192, 192))
            };
            var lineStyle          = new LineStyle();
            var shapeWithLineStyle = new ShapeStyle();
            var shapeStyle         = new ShapeStyle()
            {
                Color = Colors.Transparent
            };
            var hyperLinkStyle = new TextStyle()
            {
                FontSize   = 18,
                FontFamily = new FontFamily("Segoe UI")
            };
            var textStyle = new TextStyle()
            {
                FontSize   = 18,
                FontFamily = new FontFamily("Segoe UI")
            };
            var headerStyle = new TextStyle()
            {
                FontSize   = 40,
                FontFamily = new FontFamily("Segoe UI")
            };

            (new IFigureStyle[]
            {
                freePointStyle,
                pointOnFigureStyle,
                dependentPointStyle,
                lineStyle,
                shapeStyle,
                shapeWithLineStyle,
                textStyle,
                headerStyle,
                hyperLinkStyle,
            }).ForEach(list.Add);
            numDefaultStyles = 9;
        }
Example #2
0
        public override IFigure HitTest(Point point)
        {
            // Curve HitTest
            var projection = Info.GetProjection(point);

            if (projection.DistanceToLine < ToLogical(Shape.StrokeThickness / 2 + Math.CursorTolerance))
            {
                return(this);
            }

            // Fill HitTest
            ShapeStyle shapeStyle = Style as ShapeStyle;

            if (shapeStyle != null)
            {
                if (shapeStyle.IsFilled)
                {
                    return(HitTestShape(point));
                }
            }
            return(null);
        }
Example #3
0
        public override void UpdateVisual()
        {
            var p0 = Point(0);
            var p1 = Point(1);
            var p2 = Point(2);
            var p3 = Point(3);

            Figure.StartPoint  = ToPhysical(p0);
            BezierShape.Point1 = ToPhysical(p1);
            BezierShape.Point2 = ToPhysical(p2);
            BezierShape.Point3 = ToPhysical(p3);

            ShapeStyle shapeStyle = Style as ShapeStyle;

            if (shapeStyle != null)
            {
                Figure.IsFilled = shapeStyle.IsFilled;
            }
            else
            {
                Figure.IsFilled = false;
            }
        }
Example #4
0
        public override IFigure HitTest(Point point)
        {
            // HitTest for the fill.
            ShapeStyle shapeStyle = Style as ShapeStyle;

            if (shapeStyle != null)
            {
                if (shapeStyle.IsFilled)
                {
                    var fillResult = HitTestShape(point);
                    if (fillResult != null)
                    {
                        return(fillResult);
                    }
                }
            }

            // HitTest for the edge
            var  width        = LogicalWidth();
            var  r            = Math.Distance(Center, point);
            var  angleToPoint = Math.GetAngle(Center, point);
            bool between      = Math.IsAngleBetweenAngles(angleToPoint, StartAngle, EndAngle, Clockwise);

            if (between)
            {
                // Find the point relative to the ellipse in canonical form(unrotated).
                var canonicalPoint = Math.RotatePoint(Center, r, angleToPoint - Inclination).Minus(Center);
                var equationLeft   = canonicalPoint.X.Sqr() / SemiMajor.Sqr() + canonicalPoint.Y.Sqr() / SemiMinor.Sqr();

                // A cheap way to deal with small arcs.
                var tolerance = CursorTolerance + width / 2;
                if (SemiMajor < 1 || SemiMinor < 1)
                {
                    tolerance += .25;
                }

                if ((equationLeft - 1).Abs() < tolerance)
                {
                    return(this);
                }
            }

            // HitTest for the chord (if necessary).
            if (this is EllipseSegment || this is CircleSegment)
            {
                var epsilon = ToLogical(this.Shape.StrokeThickness) / 2 + CursorTolerance;
                if (Math.IsPointOnSegment(new PointPair(BeginLocation, EndLocation), point, epsilon))
                {
                    return(this);
                }
            }

            // HitTest for the radii (if necessary).
            if (this is EllipseSector || this is CircleSector)
            {
                var epsilon = ToLogical(this.Shape.StrokeThickness) / 2 + CursorTolerance;
                if (Math.IsPointOnSegment(new PointPair(Center, BeginLocation), point, epsilon) ||
                    Math.IsPointOnSegment(new PointPair(Center, EndLocation), point, epsilon))
                {
                    return(this);
                }
            }

            return(null);
        }
Example #5
0
        void SetFigureStyle(IniFile.Section section, IFigure figure)
        {
            figure.Visible = !section.ReadBool("Hide", false) && section.ReadBool("Visible", true);

            var    fillColor = section.ReadColor("FillColor");
            var    foreColor = section.ReadColor("ForeColor");
            double drawWidth = section.TryReadDouble("DrawWidth") ?? 1.0;

            if (drawWidth < 0.1)
            {
                drawWidth = 0.1;
            }
            int?drawStyle = section.TryReadInt("DrawStyle");
            int?fillStyle = section.TryReadInt("FillStyle");
            int?drawMode  = section.TryReadInt("DrawMode");

            if (fillStyle == null || fillStyle == 6)
            {
                fillColor = Colors.Transparent;
            }
            DoubleCollection strokeDashArray = null;

            if (drawStyle != null && drawStyle != 0)
            {
                strokeDashArray = new DoubleCollection();
                switch (drawStyle)
                {
                case 1:
                    strokeDashArray.Add(15 / drawWidth, 6 / drawWidth);
                    break;

                case 2:
                    strokeDashArray.Add(3 / drawWidth, 3 / drawWidth);
                    break;

                case 3:
                    strokeDashArray.Add(10 / drawWidth, 4 / drawWidth, 2 / drawWidth, 4 / drawWidth);
                    break;

                case 4:
                    strokeDashArray.Add(10 / drawWidth, 4 / drawWidth, 2 / drawWidth, 4 / drawWidth, 2 / drawWidth, 4 / drawWidth);
                    break;

                default:
                    break;
                }
            }

            IFigureStyle style;

            if (figure is IShapeWithInterior)
            {
                if (fillColor != Colors.Transparent && drawMode != 13)
                {
                    fillColor.A = 128;
                }
                style = new ShapeStyle()
                {
                    Fill            = new SolidColorBrush(fillColor),
                    Color           = foreColor,
                    StrokeWidth     = drawWidth,
                    StrokeDashArray = strokeDashArray
                };
            }
            else
            {
                if (foreColor == Colors.Transparent)
                {
                    System.Diagnostics.Debugger.Break();
                }
                style = new LineStyle()
                {
                    Color           = foreColor,
                    StrokeWidth     = drawWidth,
                    StrokeDashArray = strokeDashArray
                };
            }

            figure.Style = drawing.StyleManager.FindExistingOrAddNew(style);
        }
Example #6
0
        void SetFigureStyle(IniFile.Section section, IFigure figure)
        {
            figure.Visible = !section.ReadBool("Hide", false) && section.ReadBool("Visible", true);

            var fillColor = section.ReadColor("FillColor");
            var foreColor = section.ReadColor("ForeColor");
            double drawWidth = section.TryReadDouble("DrawWidth") ?? 1.0;
            if (drawWidth < 0.1)
            {
                drawWidth = 0.1;
            }
            int? drawStyle = section.TryReadInt("DrawStyle");
            int? fillStyle = section.TryReadInt("FillStyle");
            int? drawMode = section.TryReadInt("DrawMode");
            if (fillStyle == null || fillStyle == 6)
            {
                fillColor = Colors.Transparent;
            }
            DoubleCollection strokeDashArray = null;
            if (drawStyle != null && drawStyle != 0)
            {
                strokeDashArray = new DoubleCollection();
                switch (drawStyle)
                {
                    case 1:
                        strokeDashArray.Add(15 / drawWidth, 6 / drawWidth);
                        break;
                    case 2:
                        strokeDashArray.Add(3 / drawWidth, 3 / drawWidth);
                        break;
                    case 3:
                        strokeDashArray.Add(10 / drawWidth, 4 / drawWidth, 2 / drawWidth, 4 / drawWidth);
                        break;
                    case 4:
                        strokeDashArray.Add(10 / drawWidth, 4 / drawWidth, 2 / drawWidth, 4 / drawWidth, 2 / drawWidth, 4 / drawWidth);
                        break;
                    default:
                        break;
                }
            }

            IFigureStyle style;

            if (figure is IShapeWithInterior)
            {
                if (fillColor != Colors.Transparent && drawMode != 13)
                {
                    fillColor.A = 128;
                }
                style = new ShapeStyle()
                {
                    Fill = new SolidColorBrush(fillColor),
                    Color = foreColor,
                    StrokeWidth = drawWidth,
                    StrokeDashArray = strokeDashArray
                };
            }
            else
            {
                if (foreColor == Colors.Transparent)
                {
                    System.Diagnostics.Debugger.Break();
                }
                style = new LineStyle()
                {
                    Color = foreColor,
                    StrokeWidth = drawWidth,
                    StrokeDashArray = strokeDashArray
                };
            }

            figure.Style = drawing.StyleManager.FindExistingOrAddNew(style);
        }
Example #7
0
        public virtual void AddDefaultStyles()
        {
            var freePointStyle = new PointStyle()
            {
                Fill = new SolidColorBrush(Color.FromArgb(255, 255, 255, 100))
            };
            var pointOnFigureStyle = new PointStyle()
            {
                Fill = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0))
            };
            var dependentPointStyle = new PointStyle()
            {
                Name = "DependentPointStyle",
                Fill = new SolidColorBrush(Color.FromArgb(200, 192, 192, 192))
            };
            var lineStyle  = new LineStyle();
            var lineStyle2 = new LineStyle()
            {
                Name  = "OtherLine",
                Color = Color.FromArgb(200, 0, 0, 255)
            };
            var shapeWithLineStyle = new ShapeStyle();
            var shapeStyle         = new ShapeStyle()
            {
                Color = Colors.Transparent
            };
            var shapeStyle2 = new ShapeStyle()
            {
                Name  = "OtherShape",
                Color = Colors.Transparent,
                Fill  = new SolidColorBrush(Color.FromArgb(100, 200, 255, 200))
            };
            var hyperLinkStyle = new TextStyle()
            {
                FontSize   = 18,
                FontFamily = new FontFamily("Segoe UI")
            };
            var textStyle = new TextStyle()
            {
                FontSize   = 18,
                FontFamily = new FontFamily("Segoe UI")
            };
            var headerStyle = new TextStyle()
            {
                FontSize   = 40,
                FontFamily = new FontFamily("Segoe UI")
            };

            var newStyles = new IFigureStyle[]
            {
                freePointStyle,
                pointOnFigureStyle,
                dependentPointStyle,
                lineStyle,
                lineStyle2,
                shapeStyle,
                shapeStyle2,
                shapeWithLineStyle,
                textStyle,
                headerStyle,
                hyperLinkStyle,
            };

            list.AddRange(newStyles);

            numDefaultStyles = newStyles.Length;
        }