protected override HistoryMemento OnUndo()
        {
            SelectionHistoryMemento sha = new SelectionHistoryMemento(Name, Image, this.historyWorkspace);

            this.historyWorkspace.Selection.Restore(this.savedSelectionData);
            return(sha);
        }
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (historyWorkspace.Selection.IsEmpty)
            {
                return null;
            }
            else
            {
                SelectionHistoryMemento sha = new SelectionHistoryMemento(
                    StaticName,
                    StaticImage,
                    historyWorkspace);

                PdnRegion selectedRegion = historyWorkspace.Selection.CreateRegion();
                selectedRegion.Xor(historyWorkspace.Document.Bounds);

                PdnGraphicsPath invertedSelection = PdnGraphicsPath.FromRegion(selectedRegion);
                selectedRegion.Dispose();

                EnterCriticalRegion();
                historyWorkspace.Selection.PerformChanging();
                historyWorkspace.Selection.Reset();
                historyWorkspace.Selection.SetContinuation(invertedSelection, CombineMode.Xor, true);
                historyWorkspace.Selection.CommitContinuation();
                historyWorkspace.Selection.PerformChanged();

                return sha;
            }
        }
Example #3
0
        protected override HistoryMemento OnUndo(ProgressEventHandler progressCallback)
        {
            SelectionHistoryMemento     memento = new SelectionHistoryMemento(base.Name, base.Image, this.historyWorkspace);
            SelectionHistoryMementoData data    = (SelectionHistoryMementoData)base.Data;
            SelectionData savedSelectionData    = data.SavedSelectionData;

            this.historyWorkspace.Selection.Restore(savedSelectionData);
            return(memento);
        }
Example #4
0
        protected override void OnFillRegionComputed(Point[][] polygonSet)
        {
            SelectionHistoryMemento undoAction = new SelectionHistoryMemento(this.Name, this.Image, this.DocumentWorkspace);

            Selection.PerformChanging();
            Selection.SetContinuation(polygonSet, this.combineMode);
            Selection.CommitContinuation();
            Selection.PerformChanged();

            HistoryStack.PushNewMemento(undoAction);
        }
Example #5
0
        protected override void Drop()
        {
            ContextHistoryMemento cha = new ContextHistoryMemento(this.DocumentWorkspace, this.context, this.Name, this.Image);
            this.currentHistoryMementos.Add(cha);

            SelectionHistoryMemento sha = new SelectionHistoryMemento(this.Name, this.Image, this.DocumentWorkspace);
            this.currentHistoryMementos.Add(sha);

            this.context.Dispose();
            this.context = new Context();

            this.FlushHistoryMementos(PdnResources.GetString("MoveSelectionTool.HistoryMemento.DropSelection"));
        }
Example #6
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (historyWorkspace.Selection.IsEmpty)
            {
                return null;
            }
            else
            {
                SelectionHistoryMemento sha = new SelectionHistoryMemento(StaticName, StaticImage, historyWorkspace);

                EnterCriticalRegion();
                historyWorkspace.Selection.Reset();

                return sha;
            }
        }
Example #7
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            SelectionHistoryMemento sha = new SelectionHistoryMemento(
                StaticName, 
                PdnResources.GetImageResource("Icons.MenuEditSelectAllIcon.png"),
                historyWorkspace);

            EnterCriticalRegion();
            historyWorkspace.Selection.PerformChanging();
            historyWorkspace.Selection.Reset();
            historyWorkspace.Selection.SetContinuation(historyWorkspace.Document.Bounds, CombineMode.Replace);
            historyWorkspace.Selection.CommitContinuation();
            historyWorkspace.Selection.PerformChanged();

            return sha;
        }
        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;
            }
        }
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (historyWorkspace.Selection.IsEmpty)
            {
                return null;
            }

            SelectionHistoryMemento shm = new SelectionHistoryMemento(string.Empty, null, historyWorkspace);

            PdnRegion region = historyWorkspace.Selection.CreateRegion();

            BitmapLayer layer = ((BitmapLayer)historyWorkspace.ActiveLayer);
            PdnRegion simplifiedRegion = Utility.SimplifyAndInflateRegion(region);

            HistoryMemento hm = new BitmapHistoryMemento(
                null,
                null,
                historyWorkspace,
                historyWorkspace.ActiveLayerIndex,
                simplifiedRegion);

            HistoryMemento chm = new CompoundHistoryMemento(
                StaticName,
                StaticImage,
                new HistoryMemento[] { shm, hm });

            EnterCriticalRegion();

            layer.Surface.Clear(region, ColorBgra.FromBgra(255, 255, 255, 0));

            layer.Invalidate(simplifiedRegion);
            historyWorkspace.Document.Invalidate(simplifiedRegion);
            simplifiedRegion.Dispose();
            region.Dispose();
            historyWorkspace.Selection.Reset();

            return chm;
        }
Example #10
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            object savedSelection = null;
            List<HistoryMemento> actions = new List<HistoryMemento>();

            if (!historyWorkspace.Selection.IsEmpty)
            {
                savedSelection = historyWorkspace.Selection.Save();
                DeselectFunction da = new DeselectFunction();
                HistoryMemento hm = da.Execute(historyWorkspace);
                actions.Add(hm);
            }

            ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);
            actions.Add(rdha);

            CompoundHistoryMemento chm = new CompoundHistoryMemento(
                StaticName,
                PdnResources.GetImageResource("Icons.MenuImageFlattenIcon.png"),
                actions);

            // TODO: we can save memory here by serializing, then flattening on to an existing layer
            Document flat = historyWorkspace.Document.Flatten();

            EnterCriticalRegion();
            historyWorkspace.Document = flat;

            if (savedSelection != null)
            {
                SelectionHistoryMemento shm = new SelectionHistoryMemento(null, null, historyWorkspace);
                historyWorkspace.Selection.Restore(savedSelection);
                chm.PushNewAction(shm);
            }

            return chm;
        }
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (historyWorkspace.Selection.IsEmpty)
            {
                return null;
            }
            else
            {
                PdnRegion selectionRegion = historyWorkspace.Selection.CreateRegion();

                if (selectionRegion.GetArea() == 0)
                {
                    selectionRegion.Dispose();
                    return null;
                }

                SelectionHistoryMemento sha = new SelectionHistoryMemento(StaticName, null, historyWorkspace);
                ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(StaticName, null, historyWorkspace);
                Rectangle boundingBox;
                Rectangle[] inverseRegionRects = null;

                boundingBox = Utility.GetRegionBounds(selectionRegion);

                using (PdnRegion inverseRegion = new PdnRegion(boundingBox))
                {
                    inverseRegion.Exclude(selectionRegion);

                    inverseRegionRects = Utility.TranslateRectangles(
                        inverseRegion.GetRegionScansReadOnlyInt(),
                        -boundingBox.X,
                        -boundingBox.Y);
                }

                selectionRegion.Dispose();
                selectionRegion = null;

                Document oldDocument = historyWorkspace.Document; // TODO: serialize this to disk so we don't *have* to store the full thing
                Document newDocument = new Document(boundingBox.Width, boundingBox.Height);

                // copy the document's meta data over
                newDocument.ReplaceMetaDataFrom(oldDocument);

                foreach (Layer layer in oldDocument.Layers)
                {
                    if (layer is BitmapLayer)
                    {
                        BitmapLayer oldLayer = (BitmapLayer)layer;
                        Surface croppedSurface = oldLayer.Surface.CreateWindow(boundingBox);
                        BitmapLayer newLayer = new BitmapLayer(croppedSurface);

                        ColorBgra clearWhite = ColorBgra.White.NewAlpha(0);

                        foreach (Rectangle rect in inverseRegionRects)
                        {
                            newLayer.Surface.Clear(rect, clearWhite);
                        }

                        newLayer.LoadProperties(oldLayer.SaveProperties());
                        newDocument.Layers.Add(newLayer);
                    }
                    else
                    {
                        throw new InvalidOperationException("Crop does not support Layers that are not BitmapLayers");
                    }
                }

                CompoundHistoryMemento cha = new CompoundHistoryMemento(
                    StaticName,
                    PdnResources.GetImageResource("Icons.MenuImageCropIcon.png"),
                    new HistoryMemento[] { sha, rdha });

                EnterCriticalRegion();
                historyWorkspace.Document = newDocument;

                return cha;
            }
        }
Example #12
0
        protected override void Drop()
        {
            RestoreSavedRegion();

            PdnRegion regionCopy = Selection.CreateRegion();

            using (PdnRegion simplifiedRegion = Utility.SimplifyAndInflateRegion(regionCopy, 
                       Utility.DefaultSimplificationFactor, 2))
            {
                HistoryMemento bitmapAction2 = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, 
                    ActiveLayerIndex, simplifiedRegion);

                bool oldHQ = this.fullQuality;
                this.fullQuality = true;
                Render(this.context.offset, true);
                this.fullQuality = oldHQ;
                this.currentHistoryMementos.Add(bitmapAction2);

                activeLayer.Invalidate(simplifiedRegion);
                Update();
            }

            regionCopy.Dispose();
            regionCopy = null;

            ContextHistoryMemento cha = new ContextHistoryMemento(this.DocumentWorkspace, this.ourContext, this.Name, this.Image);
            this.currentHistoryMementos.Add(cha);

            string name;
            ImageResource image;

            if (didPaste)
            {
                name = EnumLocalizer.EnumValueToLocalizedName(typeof(CommonAction), CommonAction.Paste);
                image = PdnResources.GetImageResource("Icons.MenuEditPasteIcon.png");
            }
            else
            {
                name = this.Name;
                image = this.Image;
            }

            didPaste = false;

            SelectionHistoryMemento sha = new SelectionHistoryMemento(this.Name, this.Image, this.DocumentWorkspace);
            this.currentHistoryMementos.Add(sha);

            this.context.Dispose();
            this.context = new MoveToolContext();

            this.FlushHistoryMementos(PdnResources.GetString("MoveTool.HistoryMemento.DropPixels"));
        }
Example #13
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            this.Cursor = GetCursor();

            if (tracking)
            {
                moveOriginMode = true;
                lastXY = new Point(e.X, e.Y);
                OnMouseMove(e);
            }
            else if ((e.Button & MouseButtons.Left) == MouseButtons.Left ||
                (e.Button & MouseButtons.Right) == MouseButtons.Right)
            {
                tracking = true;
                hasMoved = false;
                startTime = DateTime.Now;

                tracePoints = new List<Point>();
                tracePoints.Add(new Point(e.X, e.Y));

                undoAction = new SelectionHistoryMemento("sentinel", this.Image, DocumentWorkspace);

                wasNotEmpty = !Selection.IsEmpty;

                // Determine this.combineMode

                if ((ModifierKeys & Keys.Control) != 0 && e.Button == MouseButtons.Left)
                {
                    this.combineMode = CombineMode.Union;
                }
                else if ((ModifierKeys & Keys.Alt) != 0 && e.Button == MouseButtons.Left)
                {
                    this.combineMode = CombineMode.Exclude;
                }
                else if ((ModifierKeys & Keys.Control) != 0 && e.Button == MouseButtons.Right)
                {
                    this.combineMode = CombineMode.Xor;
                }
                else if ((ModifierKeys & Keys.Alt) != 0 && e.Button == MouseButtons.Right)
                {
                    this.combineMode = CombineMode.Intersect;
                }
                else
                {
                    this.combineMode = AppEnvironment.SelectionCombineMode;
                }


                DocumentWorkspace.EnableSelectionOutline = false;

                this.newSelection.Reset();
                PdnGraphicsPath basePath = Selection.CreatePath();
                this.newSelection.SetContinuation(basePath, CombineMode.Replace, true);
                this.newSelection.CommitContinuation();

                bool newSelectionRendererVisible = true;

                // Act on this.combineMode
                switch (this.combineMode)
                {
                    case CombineMode.Xor:
                        append = true;
                        Selection.ResetContinuation();
                        break;

                    case CombineMode.Union:
                        append = true;
                        Selection.ResetContinuation();
                        break;

                    case CombineMode.Exclude:
                        append = true;
                        Selection.ResetContinuation();
                        break;

                    case CombineMode.Replace:
                        append = false;
                        Selection.Reset();
                        break;

                    case CombineMode.Intersect:
                        append = true;
                        Selection.ResetContinuation();
                        break;

                    default:
                        throw new InvalidEnumArgumentException();
                }

                this.newSelectionRenderer.Visible = newSelectionRendererVisible;
            }
        }
Example #14
0
        /// <summary>
        /// Provided as a special entry point so that Paste can work well.
        /// </summary>
        /// <param name="surface">What you want to paste.</param>
        /// <param name="offset">Where you want to paste it.</param>
        public void PasteMouseDown(SurfaceForClipboard sfc, Point offset)
        {
            if (this.context.lifted)
            {
                Drop();
            }

            MaskedSurface pixels = sfc.MaskedSurface;
            PdnGraphicsPath pastePath = pixels.CreatePath();

            PdnRegion pasteRegion = new PdnRegion(pastePath);

            PdnRegion simplifiedPasteRegion = Utility.SimplifyAndInflateRegion(pasteRegion);

            HistoryMemento bitmapAction = new BitmapHistoryMemento(Name, Image, 
                DocumentWorkspace, ActiveLayerIndex, simplifiedPasteRegion); // SLOW (110ms)

            this.currentHistoryMementos.Add(bitmapAction);

            PushContextHistoryMemento();

            this.context.seriesGuid = Guid.NewGuid();
            this.context.currentMode = Mode.Translate;
            this.context.startEdge = Edge.None;
            this.context.startAngle = 0.0f;

            this.ourContext.LiftedPixels = pixels;
            this.context.lifted = true;
            this.context.liftTransform = new Matrix();
            this.context.liftTransform.Reset();
            this.context.deltaTransform = new Matrix();
            this.context.deltaTransform.Reset();
            this.context.offset = new Point(0, 0);

            bool oldDD = this.dontDrop;
            this.dontDrop = true;

            SelectionHistoryMemento sha = new SelectionHistoryMemento(null, null, DocumentWorkspace);
            this.currentHistoryMementos.Add(sha);

            Selection.PerformChanging();
            Selection.Reset();
            Selection.SetContinuation(pastePath, CombineMode.Replace, true);
            pastePath = null;
            Selection.CommitContinuation();
            Selection.PerformChanged();

            PushContextHistoryMemento();

            this.context.liftedBounds = Selection.GetBoundsF(false);
            this.context.startBounds = this.context.liftedBounds;
            this.context.baseTransform = new Matrix();
            this.context.baseTransform.Reset();
            this.tracking = true;

            this.dontDrop = oldDD;
            this.didPaste = true;

            this.tracking = true;

            DestroyNubs();
            PositionNubs(this.context.currentMode);

            // we use the value 70,000 to simulate mouse input because that's guaranteed to be out of bounds of where
            // the mouse can actually be -- PDN is limited to 65536 x 65536 images by design
            MouseEventArgs mea1 = new MouseEventArgs(MouseButtons.Left, 0, 70000, 70000, 0);
            MouseEventArgs mea2 = new MouseEventArgs(MouseButtons.Left, 0, 70000 + offset.X, 70000 + offset.Y, 0);
            this.context.startMouseXY = new Point(70000, 70000);

            OnMouseDown(mea1);
            OnMouseMove(mea2); // SLOW (200ms)
            OnMouseUp(mea2);
        }
        public HistoryMemento ImportMultipleFiles(DocumentWorkspace documentWorkspace, string[] fileNames)
        {
            HistoryMemento retHA = null;
            List<HistoryMemento> historyMementos = new List<HistoryMemento>();
            Rectangle lastLayerBounds = Rectangle.Empty;

            foreach (string fileName in fileNames)
            {
                HistoryMemento ha = ImportOneFile(documentWorkspace, fileName, out lastLayerBounds);

                if (ha != null)
                {
                    historyMementos.Add(ha);
                }
                else
                {
                    Rollback(historyMementos);
                    historyMementos.Clear();
                    break;
                }
            }

            if (lastLayerBounds.Width > 0 && lastLayerBounds.Height > 0)
            {
                SelectionHistoryMemento sha = new SelectionHistoryMemento(null, null, documentWorkspace);
                historyMementos.Add(sha);
                documentWorkspace.Selection.PerformChanging();
                documentWorkspace.Selection.Reset();
                documentWorkspace.Selection.SetContinuation(lastLayerBounds, System.Drawing.Drawing2D.CombineMode.Replace);
                documentWorkspace.Selection.CommitContinuation();
                documentWorkspace.Selection.PerformChanged();
            }

            if (historyMementos.Count > 0)
            {
                HistoryMemento[] haArray = historyMementos.ToArray();
                retHA = new CompoundHistoryMemento(StaticName, StaticImage, haArray);
            }

            return retHA;
        }
Example #16
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (tracking)
            {
                return;
            }

            bool determinedMoveMode = false;
            Mode newMode = Mode.Translate;
            Edge newEdge = Edge.None;

            if (Selection.IsEmpty)
            {
                SelectionHistoryMemento shm = new SelectionHistoryMemento(
                    HistoryFunctions.SelectAllFunction.StaticName,
                    ImageResource.Get("Icons.MenuEditSelectAllIcon.png"),
                    DocumentWorkspace);

                DocumentWorkspace.History.PushNewMemento(shm);

                DocumentWorkspace.Selection.PerformChanging();
                DocumentWorkspace.Selection.Reset();
                DocumentWorkspace.Selection.SetContinuation(Document.Bounds, CombineMode.Replace);
                DocumentWorkspace.Selection.CommitContinuation();
                DocumentWorkspace.Selection.PerformChanged();

                if (e.Button == MouseButtons.Right)
                {
                    newMode = Mode.Rotate;
                }
                else
                {
                    newMode = Mode.Translate;
                }

                newEdge = Edge.None;

                determinedMoveMode = true;
            }

            DocumentWorkspace.EnableSelectionOutline = this.enableOutline;

            if (!context.lifted)
            {
                Lift(e);
            }

            PushContextHistoryMemento();

            if (!determinedMoveMode)
            {
                DetermineMoveMode(e, out newMode, out newEdge);
                determinedMoveMode = true;
            }

            if (this.context.deltaTransform != null)
            {
                this.context.deltaTransform.Dispose();
                this.context.deltaTransform = null;
            }

            this.context.deltaTransform = new Matrix();
            this.context.deltaTransform.Reset();

            if (newMode == Mode.Translate ||
                newMode == Mode.Scale ||
                newMode != this.context.currentMode ||
                newMode == Mode.Rotate)
            {
                this.context.startBounds = Selection.GetBoundsF();
                this.context.startMouseXY = new Point(e.X, e.Y);
                this.context.offset = new Point(0, 0);

                if (this.context.baseTransform != null)
                {
                    this.context.baseTransform.Dispose();
                    this.context.baseTransform = null;
                }

                this.context.baseTransform = Selection.GetInterimTransformCopy();
            }

            this.context.startEdge = newEdge;
            this.context.currentMode = newMode;
            PositionNubs(this.context.currentMode);

            tracking = true;
            this.rotateNub.Visible = (this.context.currentMode == Mode.Rotate);

            if (this.context.startPath != null)
            {
                this.context.startPath.Dispose();
                this.context.startPath = null;
            }

            this.context.startPath = Selection.CreatePath();
            this.context.startAngle = Utility.GetAngleOfTransform(Selection.GetInterimTransformReadOnly());

            SelectionHistoryMemento sha1 = new SelectionHistoryMemento(this.Name, this.Image, this.DocumentWorkspace);
            this.currentHistoryMementos.Add(sha1);

            OnMouseMove(e);

            if (this.enableOutline)
            {
                DocumentWorkspace.ResetOutlineWhiteOpacity();
            }
        }
Example #17
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (tracking)
            {
                moveOriginMode = true;
                lastXY = new Point(e.X, e.Y);
                OnMouseMove(e);
            }
            else if ((e.Button & MouseButtons.Left) == MouseButtons.Left ||
                (e.Button & MouseButtons.Right) == MouseButtons.Right)
            {
                tracking = true;
                hasMoved = false;
                startTime = DateTime.Now;

                tracePoints = new List<Point>();
                tracePoints.Add(new Point(e.X, e.Y));

                undoAction = new SelectionHistoryMemento("sentinel", this.Image, DocumentWorkspace);

                wasNotEmpty = !Selection.IsEmpty;

                // if the user is holding down the control key then we don't want to reset the path, merely append to it
                if ((ModifierKeys & Keys.Control) == Keys.Control)
                {
                    append = true;

                    if ((e.Button & MouseButtons.Right) == MouseButtons.Right)
                    {
                        this.combineMode = CombineMode.Xor;
                    }
                    else
                    {
                        this.combineMode = CombineMode.Union;
                    }

                    Selection.ResetContinuation();
                }
                else if ((e.Button & MouseButtons.Right) == MouseButtons.Right)
                {
                    append = true;
                    this.combineMode = CombineMode.Exclude;
                    Selection.ResetContinuation();
                }
                else
                {
                    append = false;
                    this.combineMode = CombineMode.Replace;
                    Selection.Reset();
                }
            }
        }
 protected override HistoryMemento OnUndo()
 {
     SelectionHistoryMemento sha = new SelectionHistoryMemento(Name, Image, this.historyWorkspace);
     this.historyWorkspace.Selection.Restore(this.savedSelectionData);
     return sha;
 }