Exemplo n.º 1
0
        protected override PdnGraphicsPath CreateShapePath(PointF[] points)
        {
            PointF     a = points[0];
            PointF     b = points[points.Length - 1];
            RectangleF rect;

            if ((ModifierKeys & Keys.Shift) != 0)
            {
                rect = Utility.PointsToConstrainedRectangle(a, b);
            }
            else
            {
                rect = Utility.PointsToRectangle(a, b);
            }

            PdnGraphicsPath path = new PdnGraphicsPath();

            path.AddRectangle(rect);
            path.CloseFigure();
            path.Reverse();

            MeasurementUnit units          = AppWorkspace.Units;
            double          widthPhysical  = Math.Abs(Document.PixelToPhysicalX(rect.Width, units));
            double          heightPhysical = Math.Abs(Document.PixelToPhysicalY(rect.Height, units));
            double          areaPhysical   = widthPhysical * heightPhysical;

            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,
                widthPhysical.ToString(numberFormat),
                unitsAbbreviation,
                heightPhysical.ToString(numberFormat),
                unitsAbbreviation,
                areaPhysical.ToString(numberFormat),
                unitsString);

            this.SetStatus(this.rectangleToolIcon, statusText);
            return(path);
        }
Exemplo n.º 2
0
        protected override PdnGraphicsPath CreateShapePath(PointF[] points)
        {
            PointF a = points[0];
            PointF b = points[points.Length - 1];
            RectangleF rect;

            if ((ModifierKeys & Keys.Shift) != 0)
            {
                rect = Utility.PointsToConstrainedRectangle(a, b);
            }
            else
            {
                rect = Utility.PointsToRectangle(a, b);
            }

            PdnGraphicsPath path = new PdnGraphicsPath();
            path.AddRectangle(rect);
            path.CloseFigure();
            path.Reverse();

            MeasurementUnit units = AppWorkspace.Units;
            double widthPhysical = Math.Abs(Document.PixelToPhysicalX(rect.Width, units));
            double heightPhysical = Math.Abs(Document.PixelToPhysicalY(rect.Height, units));
            double areaPhysical = widthPhysical * heightPhysical;
            
            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,
                widthPhysical.ToString(numberFormat),
                unitsAbbreviation,
                heightPhysical.ToString(numberFormat),
                unitsAbbreviation,
                areaPhysical.ToString(numberFormat),
                unitsString);

            this.SetStatus(this.rectangleToolIcon, statusText);
            return path;
        }
Exemplo n.º 3
0
        // credit for the this function is given to Aaron Reginald http://www.codeproject.com/cs/media/ExtendedGraphics.asp
        protected PdnGraphicsPath GetRoundedRect(RectangleF baseRect, float radius)
        {
            // if corner radius is less than or equal to zero,
            // return the original rectangle
            if (radius <= 0.0f)
            {
                PdnGraphicsPath mPath = new PdnGraphicsPath();
                mPath.AddRectangle(baseRect);
                mPath.CloseFigure();
                return(mPath);
            }

            // if the corner radius is greater than or equal to
            // half the width, or height (whichever is shorter)
            // then return a capsule instead of a lozenge
            if (radius >= (Math.Min(baseRect.Width, baseRect.Height)) / 2.0)
            {
                return(GetCapsule(baseRect));
            }

            // create the arc for the rectangle sides and declare
            // a graphics path object for the drawing
            float           diameter = radius * 2.0f;
            SizeF           sizeF    = new SizeF(diameter, diameter);
            RectangleF      arc      = new RectangleF(baseRect.Location, sizeF);
            PdnGraphicsPath path     = new PdnGraphicsPath();

            // top left arc
            path.AddArc(arc, 180, 90);

            // top right arc
            arc.X = baseRect.Right - diameter;
            path.AddArc(arc, 270, 90);

            // bottom right arc
            arc.Y = baseRect.Bottom - diameter;
            path.AddArc(arc, 0, 90);

            // bottom left arc
            arc.X = baseRect.Left;
            path.AddArc(arc, 90, 90);

            path.CloseFigure();
            return(path);
        }
Exemplo n.º 4
0
        protected override PdnGraphicsPath CreateShapePath(PointF[] points)
        {
            PointF     a = points[0];
            PointF     b = points[points.Length - 1];
            RectangleF rect;

            if ((ModifierKeys & Keys.Shift) != 0)
            {
                rect = Utility.PointsToConstrainedRectangle(a, b);
            }
            else
            {
                rect = Utility.PointsToRectangle(a, b);
            }

            PdnGraphicsPath path = new PdnGraphicsPath();

            path.AddRectangle(rect);
            path.CloseFigure();
            path.Reverse();

            string numberFormat;
            string unitsAbbreviation;

            {
                unitsAbbreviation = string.Empty;
                numberFormat      = "F0";
            }

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

            string statusText = string.Format(
                this.statusTextFormat,
                rect.Width,
                unitsAbbreviation,
                rect.Height,
                unitsAbbreviation,
                "0",
                unitsString);

            this.SetStatus(this.rectangleToolIcon, statusText);
            return(path);
        }
Exemplo n.º 5
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (historyWorkspace.Selection.IsEmpty)
            {
                return(null);
            }
            else
            {
                SelectionHistoryMemento sha = new SelectionHistoryMemento(
                    StaticName,
                    StaticImage,
                    historyWorkspace);

                //PdnGraphicsPath selectedPath = historyWorkspace.Selection.GetPathReadOnly();
                PdnGraphicsPath selectedPath = historyWorkspace.Selection.CreatePath();

                PdnGraphicsPath boundsOutline = new PdnGraphicsPath();
                boundsOutline.AddRectangle(historyWorkspace.Document.Bounds);

                PdnGraphicsPath clippedPath  = PdnGraphicsPath.Combine(selectedPath, CombineMode.Intersect, boundsOutline);
                PdnGraphicsPath invertedPath = PdnGraphicsPath.Combine(clippedPath, CombineMode.Xor, boundsOutline);

                selectedPath.Dispose();
                selectedPath = null;

                clippedPath.Dispose();
                clippedPath = null;

                EnterCriticalRegion();
                historyWorkspace.Selection.PerformChanging();
                historyWorkspace.Selection.Reset();
                historyWorkspace.Selection.SetContinuation(invertedPath, CombineMode.Replace, true);
                historyWorkspace.Selection.CommitContinuation();
                historyWorkspace.Selection.PerformChanged();

                boundsOutline.Dispose();
                boundsOutline = null;

                return(sha);
            }
        }
Exemplo n.º 6
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (historyWorkspace.Selection.IsEmpty)
            {
                return null;
            }
            else
            {
                SelectionHistoryMemento sha = new SelectionHistoryMemento(
                    StaticName,
                    StaticImage,
                    historyWorkspace);

                //PdnGraphicsPath selectedPath = historyWorkspace.Selection.GetPathReadOnly();
                PdnGraphicsPath selectedPath = historyWorkspace.Selection.CreatePath();

                PdnGraphicsPath boundsOutline = new PdnGraphicsPath();
                boundsOutline.AddRectangle(historyWorkspace.Document.Bounds);

                PdnGraphicsPath clippedPath = PdnGraphicsPath.Combine(selectedPath, CombineMode.Intersect, boundsOutline);
                PdnGraphicsPath invertedPath = PdnGraphicsPath.Combine(clippedPath, CombineMode.Xor, boundsOutline);

                selectedPath.Dispose();
                selectedPath = null;

                clippedPath.Dispose();
                clippedPath = null;

                EnterCriticalRegion();
                historyWorkspace.Selection.PerformChanging();
                historyWorkspace.Selection.Reset();
                historyWorkspace.Selection.SetContinuation(invertedPath, CombineMode.Replace, true);
                historyWorkspace.Selection.CommitContinuation();
                historyWorkspace.Selection.PerformChanged();

                boundsOutline.Dispose();
                boundsOutline = null;

                return sha;
            }
        }
Exemplo n.º 7
0
        // credit for the this function is given to Aaron Reginald http://www.codeproject.com/cs/media/ExtendedGraphics.asp
        protected PdnGraphicsPath GetRoundedRect(RectangleF baseRect, float radius)
        {
            // if corner radius is less than or equal to zero,
            // return the original rectangle
            if (radius <= 0.0f)
            {
                PdnGraphicsPath mPath = new PdnGraphicsPath();
                mPath.AddRectangle(baseRect);
                mPath.CloseFigure();
                return mPath;
            }

            // if the corner radius is greater than or equal to
            // half the width, or height (whichever is shorter)
            // then return a capsule instead of a lozenge
            if (radius >= (Math.Min(baseRect.Width, baseRect.Height)) / 2.0)
            {
                return GetCapsule(baseRect);
            }

            // create the arc for the rectangle sides and declare
            // a graphics path object for the drawing
            float diameter = radius * 2.0f;
            SizeF sizeF = new SizeF(diameter, diameter);
            RectangleF arc = new RectangleF(baseRect.Location, sizeF);
            PdnGraphicsPath path = new PdnGraphicsPath();

            // top left arc
            path.AddArc (arc, 180, 90);

            // top right arc
            arc.X = baseRect.Right - diameter;
            path.AddArc (arc, 270, 90);

            // bottom right arc
            arc.Y = baseRect.Bottom - diameter;
            path.AddArc (arc, 0, 90);

            // bottom left arc
            arc.X = baseRect.Left;
            path.AddArc (arc, 90, 90);

            path.CloseFigure();
            return path;
        }