Пример #1
0
        private void LineCapToLineCap2(LineCap2 cap2, out LineCap capResult, out CustomLineCap customCapResult)
        {
            switch (cap2)
            {
            case LineCap2.Flat:
                capResult       = LineCap.Flat;
                customCapResult = null;
                break;

            case LineCap2.Arrow:
                capResult       = LineCap.ArrowAnchor;
                customCapResult = new AdjustableArrowCap(5.0f * this.capScale, 5.0f * this.capScale, false);
                break;

            case LineCap2.ArrowFilled:
                capResult       = LineCap.ArrowAnchor;
                customCapResult = new AdjustableArrowCap(5.0f * this.capScale, 5.0f * this.capScale, true);
                break;

            case LineCap2.Rounded:
                capResult       = LineCap.Round;
                customCapResult = null;
                break;

            default:
                throw new InvalidEnumArgumentException();
            }
        }
Пример #2
0
        private static void LineCapToLineCap2(LineCap2 cap2, out LineCap capResult, out CustomLineCap customCapResult)
        {
            switch (cap2)
            {
            case LineCap2.Flat:
                capResult       = LineCap.Flat;
                customCapResult = null;
                return;

            case LineCap2.Arrow:
                capResult       = LineCap.ArrowAnchor;
                customCapResult = new AdjustableArrowCap(5f, 5f, false);
                return;

            case LineCap2.ArrowFilled:
                capResult       = LineCap.ArrowAnchor;
                customCapResult = new AdjustableArrowCap(5f, 5f, true);
                return;

            case LineCap2.Rounded:
                capResult       = LineCap.Round;
                customCapResult = null;
                return;
            }
            throw ExceptionUtil.InvalidEnumArgumentException <LineCap2>(cap2, "cap2");
        }
Пример #3
0
 public PenInfo(DashStyle dashStyle, float width, LineCap2 startCap, LineCap2 endCap, float capScale)
 {
     this.dashStyle = dashStyle;
     this.width     = width;
     this.capScale  = capScale;
     this.startCap  = startCap;
     this.endCap    = endCap;
 }
Пример #4
0
        public static System.Drawing.Pen CreatePen(this AppSettings.ToolsSection toolSettings, ColorBgra32 foreColor, ColorBgra32 backColor)
        {
            System.Drawing.Pen pen;
            LineCap            cap3;
            CustomLineCap      cap4;
            LineCap            cap5;
            CustomLineCap      cap6;
            float    width = toolSettings.Pen.Width.Value;
            LineCap2 cap   = toolSettings.Pen.StartCap.Value;
            LineCap2 cap2  = toolSettings.Pen.EndCap.Value;

            System.Drawing.Drawing2D.DashStyle style = toolSettings.Pen.DashStyle.Value;
            if (((PaintDotNet.BrushType)toolSettings.Brush.Type.Value) == PaintDotNet.BrushType.None)
            {
                pen = new System.Drawing.Pen((Color)foreColor, width);
            }
            else
            {
                pen = new System.Drawing.Pen(toolSettings.CreateGdipBrush(foreColor, backColor), width);
            }
            LineCapToLineCap2(cap, out cap3, out cap4);
            if (cap4 != null)
            {
                pen.CustomStartCap = cap4;
            }
            else
            {
                pen.StartCap = cap3;
            }
            LineCapToLineCap2(cap2, out cap5, out cap6);
            if (cap6 != null)
            {
                pen.CustomEndCap = cap6;
            }
            else
            {
                pen.EndCap = cap5;
            }
            pen.DashStyle = style;
            return(pen);
        }
Пример #5
0
        private PenInfo(SerializationInfo info, StreamingContext context)
        {
            this.dashStyle = (DashStyle)info.GetValue("dashStyle", typeof(DashStyle));
            this.width     = info.GetSingle("width");

            // Save the caps as integers because we want to change the "LineCap2" name.
            // Just not feeling very creative right now I guess.
            try
            {
                this.startCap = (LineCap2)info.GetInt32("startCap");
            }

            catch (SerializationException)
            {
                this.startCap = DefaultLineCap;
            }

            try
            {
                this.endCap = (LineCap2)info.GetInt32("endCap");
            }

            catch (SerializationException)
            {
                this.endCap = DefaultLineCap;
            }

            try
            {
                float loadedCapScale = info.GetSingle("capScale");
                this.capScale = Utility.Clamp(loadedCapScale, MinCapScale, MaxCapScale);
            }

            catch (SerializationException)
            {
                this.capScale = DefaultCapScale;
            }
        }
Пример #6
0
        private static Geometry CreateStrokedLineGeometry(Geometry lineGeometry, double strokeWidth, LineCap2 startCap, LineCap2 endCap, PaintDotNet.UI.Media.DashStyle dashStyle)
        {
            Geometry    geometry;
            Geometry    geometry2;
            Geometry    geometry3;
            Geometry    geometry4;
            Geometry    geometry5;
            double      length      = lineGeometry.GetLength(flatteningTolerance);
            StrokeStyle strokeStyle = new StrokeStyle {
                DashStyle = dashStyle,
                LineJoin  = PenLineJoin.Round
            };
            double num2 = 0.0;

            switch (startCap)
            {
            case LineCap2.Flat:
                geometry = null;
                break;

            case LineCap2.Arrow:
                geometry = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, false, false).EnsureFrozen <Geometry>();
                num2     = 0.5;
                break;

            case LineCap2.ArrowFilled:
                geometry = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, true, true).EnsureFrozen <Geometry>();
                num2     = 1.5;
                break;

            case LineCap2.Rounded:
                strokeStyle.StartLineCap = PenLineCap.Round;
                geometry = null;
                break;

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <LineCap2>(startCap, "startCap");
            }
            double num3 = 0.0;

            switch (endCap)
            {
            case LineCap2.Flat:
                geometry2 = null;
                break;

            case LineCap2.Arrow:
                geometry2 = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, false, false).EnsureFrozen <Geometry>();
                num3      = 0.5;
                break;

            case LineCap2.ArrowFilled:
                geometry2 = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, true, true).EnsureFrozen <Geometry>();
                num3      = 1.5;
                break;

            case LineCap2.Rounded:
                strokeStyle.EndLineCap = PenLineCap.Round;
                geometry2 = null;
                break;

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <LineCap2>(endCap, "endCap");
            }
            strokeStyle.Freeze();
            if (geometry == null)
            {
                geometry3 = null;
            }
            else
            {
                PointAndTangentDouble pointAtLength = lineGeometry.GetPointAtLength(0.0, flatteningTolerance);
                double          radians             = Math.Atan2(pointAtLength.Tangent.Y, pointAtLength.Tangent.X) + 3.1415926535897931;
                Matrix3x2Double num9   = Matrix3x2Double.RotationByRadians(radians);
                Matrix3x2Double num10  = Matrix3x2Double.Translation(pointAtLength.Point.X, pointAtLength.Point.Y);
                Matrix3x2Double matrix = num9 * num10;
                geometry3 = geometry.GetTransformedGeometry(matrix).EnsureFrozen <Geometry>();
            }
            if (geometry2 == null)
            {
                geometry4 = null;
            }
            else
            {
                double num14 = lineGeometry.GetLength(flatteningTolerance);
                PointAndTangentDouble num15 = lineGeometry.GetPointAtLength(num14, flatteningTolerance);
                Matrix3x2Double       num18 = Matrix3x2Double.RotationByRadians(Math.Atan2(num15.Tangent.Y, num15.Tangent.X));
                Matrix3x2Double       num19 = Matrix3x2Double.Translation(num15.Point.X, num15.Point.Y);
                Matrix3x2Double       num20 = num18 * num19;
                geometry4 = geometry2.GetTransformedGeometry(num20).EnsureFrozen <Geometry>();
            }
            double startLength = 0.0;
            double endLength   = length;

            if (num2 != 0.0)
            {
                startLength = strokeWidth * num2;
            }
            if (num3 != 0.0)
            {
                endLength = length - (strokeWidth * num3);
            }
            if ((startLength != 0.0) || (endLength != length))
            {
                geometry5 = GetTrimmedGeometry(lineGeometry, startLength, endLength).EnsureFrozen <Geometry>();
            }
            else
            {
                geometry5 = lineGeometry;
            }
            Geometry item = new WidenedGeometry(geometry5, strokeWidth, strokeStyle)
            {
                FlatteningTolerance = flatteningTolerance
            }.EnsureFrozen <WidenedGeometry>();
            GeometryGroup group = new GeometryGroup {
                FillRule = FillRule.Nonzero
            };

            group.Children.Add(item);
            if (geometry3 != null)
            {
                group.Children.Add(geometry3);
            }
            if (geometry4 != null)
            {
                group.Children.Add(geometry4);
            }
            group.Freeze();
            return(group);
        }
Пример #7
0
        private PenInfo(SerializationInfo info, StreamingContext context)
        {
            this.dashStyle = (DashStyle)info.GetValue("dashStyle", typeof(DashStyle));
            this.width = info.GetSingle("width");

            // Save the caps as integers because we want to change the "LineCap2" name.
            // Just not feeling very creative right now I guess.
            try
            {
                this.startCap = (LineCap2)info.GetInt32("startCap");
            }

            catch (SerializationException)
            {
                this.startCap = DefaultLineCap;
            }

            try
            {
                this.endCap = (LineCap2)info.GetInt32("endCap");
            }

            catch (SerializationException)
            {
                this.endCap = DefaultLineCap;
            }

            try
            {
                float loadedCapScale = info.GetSingle("capScale");
                this.capScale = Utility.Clamp(loadedCapScale, MinCapScale, MaxCapScale);
            }

            catch (SerializationException)
            {
                this.capScale = DefaultCapScale;
            }
        }
Пример #8
0
 public PenInfo(DashStyle dashStyle, float width, LineCap2 startCap, LineCap2 endCap, float capScale)
 {
     this.dashStyle = dashStyle;
     this.width = width;
     this.capScale = capScale;
     this.startCap = startCap;
     this.endCap = endCap;
 }
Пример #9
0
        private void LineCapToLineCap2(LineCap2 cap2, out LineCap capResult, out CustomLineCap customCapResult)
        {
            switch (cap2)
            {
                case LineCap2.Flat:
                    capResult = LineCap.Flat;
                    customCapResult = null;
                    break;

                case LineCap2.Arrow:
                    capResult = LineCap.ArrowAnchor;
                    customCapResult = new AdjustableArrowCap(5.0f * this.capScale, 5.0f * this.capScale, false);
                    break;

                case LineCap2.ArrowFilled:
                    capResult = LineCap.ArrowAnchor;
                    customCapResult = new AdjustableArrowCap(5.0f * this.capScale, 5.0f * this.capScale, true);
                    break;

                case LineCap2.Rounded:
                    capResult = LineCap.Round;
                    customCapResult = null;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
            }
        }
Пример #10
0
 private ImageResource GetLineCapImage(LineCap2 lineCap, bool isStartCap)
 {
     string nameFormat = "Images.LineCapButton.{0}.{1}.png";
     string name = string.Format(nameFormat, lineCap.ToString(), isStartCap ? "Start" : "End");
     ImageResource imageResource = PdnResources.GetImageResource(name);
     return imageResource;
 }
Пример #11
0
 private LineCap2 NextLineCap(LineCap2 oldCap)
 {
     int capIndex = Array.IndexOf<LineCap2>(this.lineCaps, oldCap);
     int newCapIndex = (capIndex + 1) % this.lineCaps.Length;
     return this.lineCaps[newCapIndex];
 }