コード例 #1
0
ファイル: LineTool.cs プロジェクト: herbqiao/paint.net
        protected override PdnGraphicsPath CreateShapePath(PointF[] points)
        {
            if (points.Length >= 4)
            {
                PdnGraphicsPath path = new PdnGraphicsPath();

                switch (this.curveType)
                {
                    default:
                    case CurveType.Spline:
                        path.AddCurve(points);
                        break;

                    case CurveType.Bezier:
                        path.AddBezier(points[0], points[1], points[2], points[3]);
                        break;
                }

                path.Flatten(Utility.IdentityMatrix, flattenConstant);
                return path;
            }
            else //if (points.Length <= 2)
            {
                PointF a = points[0];
                PointF b = points[points.Length - 1];
            
                if (0 != (ModifierKeys & Keys.Shift) && a != b)
                {
                    ConstrainPoints(ref a, ref b);
                }

                double angle = -180.0 * Math.Atan2(b.Y - a.Y, b.X - a.X) / Math.PI;
                MeasurementUnit units = AppWorkspace.Units;
                double offsetXPhysical = Document.PixelToPhysicalX(b.X - a.X, units);
                double offsetYPhysical = Document.PixelToPhysicalY(b.Y - a.Y, units);
                double offsetLengthPhysical = Math.Sqrt(offsetXPhysical * offsetXPhysical + offsetYPhysical * offsetYPhysical);

                string numberFormat;
                string unitsAbbreviation;

                if (units != MeasurementUnit.Pixel)
                {
                    string unitsAbbreviationName = "MeasurementUnit." + units.ToString() + ".Abbreviation";
                    unitsAbbreviation = PdnResources.GetString(unitsAbbreviationName);
                    numberFormat = "F2";
                }
                else
                {
                    unitsAbbreviation = string.Empty;
                    numberFormat = "F0";
                }

                string unitsString = PdnResources.GetString("MeasurementUnit." + units.ToString() + ".Plural");

                string statusText = string.Format(
                    this.statusTextFormat,
                    offsetXPhysical.ToString(numberFormat),
                    unitsAbbreviation,
                    offsetYPhysical.ToString(numberFormat),
                    unitsAbbreviation,
                    offsetLengthPhysical.ToString("F2"),
                    unitsString,
                    angle.ToString("F2"));

                SetStatus(this.lineToolIcon, statusText);

                if (a == b)
                {
                    return null;
                }
                else
                {
                    PdnGraphicsPath path = new PdnGraphicsPath();
                    PointF[] spline = LineToSpline(a, b, controlPointCount);
                    path.AddCurve(spline);
                    path.Flatten(Utility.IdentityMatrix, flattenConstant);
                    return path;
                }
            }
        }
コード例 #2
0
        protected override PdnGraphicsPath CreateShapePath(PointF[] points)
        {
            if (points.Length >= 4)
            {
                PdnGraphicsPath path = new PdnGraphicsPath();

                switch (this.curveType)
                {
                default:
                case CurveType.Spline:
                    path.AddCurve(points);
                    break;

                case CurveType.Bezier:
                    path.AddBezier(points[0], points[1], points[2], points[3]);
                    break;
                }

                path.Flatten(Utility.IdentityMatrix, flattenConstant);
                return(path);
            }
            else //if (points.Length <= 2)
            {
                PointF a = points[0];
                PointF b = points[points.Length - 1];

                if (0 != (ModifierKeys & Keys.Shift) && a != b)
                {
                    ConstrainPoints(ref a, ref b);
                }

                double          angle                = -180.0 * Math.Atan2(b.Y - a.Y, b.X - a.X) / Math.PI;
                MeasurementUnit units                = AppWorkspace.Units;
                double          offsetXPhysical      = Document.PixelToPhysicalX(b.X - a.X, units);
                double          offsetYPhysical      = Document.PixelToPhysicalY(b.Y - a.Y, units);
                double          offsetLengthPhysical = Math.Sqrt(offsetXPhysical * offsetXPhysical + offsetYPhysical * offsetYPhysical);

                string numberFormat;
                string unitsAbbreviation;

                if (units != MeasurementUnit.Pixel)
                {
                    string unitsAbbreviationName = "MeasurementUnit." + units.ToString() + ".Abbreviation";
                    unitsAbbreviation = PdnResources.GetString(unitsAbbreviationName);
                    numberFormat      = "F2";
                }
                else
                {
                    unitsAbbreviation = string.Empty;
                    numberFormat      = "F0";
                }

                string unitsString = PdnResources.GetString("MeasurementUnit." + units.ToString() + ".Plural");

                string statusText = string.Format(
                    this.statusTextFormat,
                    offsetXPhysical.ToString(numberFormat),
                    unitsAbbreviation,
                    offsetYPhysical.ToString(numberFormat),
                    unitsAbbreviation,
                    offsetLengthPhysical.ToString("F2"),
                    unitsString,
                    angle.ToString("F2"));

                SetStatus(this.lineToolIcon, statusText);

                if (a == b)
                {
                    return(null);
                }
                else
                {
                    PdnGraphicsPath path   = new PdnGraphicsPath();
                    PointF[]        spline = LineToSpline(a, b, controlPointCount);
                    path.AddCurve(spline);
                    path.Flatten(Utility.IdentityMatrix, flattenConstant);
                    return(path);
                }
            }
        }