Beispiel #1
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            CompoundHistoryMemento chm = new CompoundHistoryMemento(this.historyName, this.undoImage);

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction df = new DeselectFunction();
                EnterCriticalRegion();
                HistoryMemento hm = df.Execute(historyWorkspace);
                chm.PushNewAction(hm);
            }

            FlipLayerHistoryMemento flha = new FlipLayerHistoryMemento(
                null,
                null,
                historyWorkspace,
                this.layerIndex,
                this.flipType);

            EnterCriticalRegion();
            HistoryMemento flha2 = flha.PerformUndo();

            chm.PushNewAction(flha);

            return(chm);
        }
Beispiel #2
0
        protected override void OnStylusUp(StylusEventArgs e)
        {
            base.OnStylusUp(e);

            Cursor = cursorMouseUp;

            if (moveOriginMode)
            {
                moveOriginMode = false;
            }
            else if (mouseDown)
            {
                bool doCommit = OnShapeEnd();

                if (doCommit)
                {
                    CommitShape();
                }
                else
                {
                    // place a 'sentinel' history action on the stack that will be filled in later
                    CompoundHistoryMemento cha = new CompoundHistoryMemento(Name, Image, new List <HistoryMemento>());
                    HistoryStack.PushNewMemento(cha);
                    this.chaAlreadyOnStack = cha;
                }
            }
        }
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            string[]       fileNames;
            string         startingDir = Path.GetDirectoryName(documentWorkspace.FilePath);
            DialogResult   result      = DocumentWorkspace.ChooseFiles(documentWorkspace, out fileNames, true, startingDir);
            HistoryMemento retHA       = null;

            if (result == DialogResult.OK)
            {
                Type oldToolType = documentWorkspace.GetToolType();
                documentWorkspace.SetTool(null);

                retHA = ImportMultipleFiles(documentWorkspace, fileNames);

                Type newToolType;
                if (retHA != null)
                {
                    CompoundHistoryMemento cha = new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { retHA });
                    retHA       = cha;
                    newToolType = typeof(Tools.MoveTool);
                }
                else
                {
                    newToolType = oldToolType;
                }

                documentWorkspace.SetToolFromType(newToolType);
            }

            return(retHA);
        }
Beispiel #4
0
        private void CommitGradient()
        {
            if (!this.gradientActive)
            {
                throw new InvalidOperationException("CommitGradient() called when a gradient was not active");
            }

            RenderGradient();

            using (PdnRegion clipRegion = DocumentWorkspace.Selection.CreateRegion())
            {
                BitmapHistoryMemento bhm = new BitmapHistoryMemento(
                    StaticName,
                    StaticImage,
                    DocumentWorkspace,
                    DocumentWorkspace.ActiveLayerIndex,
                    clipRegion,
                    this.ScratchSurface);

                this.historyMemento.PushNewAction(bhm);

                // We assume this.historyMemento has already been pushed on to the HistoryStack

                this.historyMemento = null;
            }

            this.startNub.Visible = false;
            this.endNub.Visible   = false;

            ClearSavedRegion();
            ClearSavedMemory();
            this.gradientActive = false;

            SetStatus(this.toolIcon, this.helpTextInitial);
        }
Beispiel #5
0
            protected override HistoryMemento OnToolUndo()
            {
                CompoundHistoryMemento     chm  = (CompoundHistoryMemento)this.CompoundHistoryMemento.PerformUndo();
                CompoundToolHistoryMemento cthm = new CompoundToolHistoryMemento(chm, DocumentWorkspace, this.Name, this.Image);

                return(cthm);
            }
Beispiel #6
0
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            string[]       strArray;
            string         directoryName = Path.GetDirectoryName(documentWorkspace.FilePath);
            DialogResult   result        = DocumentWorkspace.ChooseFiles(documentWorkspace, out strArray, true, directoryName);
            HistoryMemento memento       = null;

            if (result == DialogResult.OK)
            {
                System.Type type2;
                System.Type toolType = documentWorkspace.GetToolType();
                documentWorkspace.ClearTool();
                memento = this.ImportMultipleFiles(documentWorkspace, strArray);
                if (memento != null)
                {
                    HistoryMemento[]       actions  = new HistoryMemento[] { memento };
                    CompoundHistoryMemento memento2 = new CompoundHistoryMemento(StaticName, StaticImage, actions);
                    memento = memento2;
                    type2   = typeof(MoveSelectedPixelsTool);
                }
                else
                {
                    type2 = toolType;
                }
                documentWorkspace.SetToolFromType(type2);
            }
            return(memento);
        }
        private void FlushHistoryMementos(string name)
        {
            if (this.currentHistoryMementos.Count > 0)
            {
                CompoundHistoryMemento cha = new CompoundHistoryMemento(null, null,
                                                                        this.currentHistoryMementos.ToArray());

                string haName;

                if (name == null)
                {
                    haName = this.Name;
                }
                else
                {
                    haName = name;
                }

                ImageResource image = this.Image;

                CompoundToolHistoryMemento ctha = new CompoundToolHistoryMemento(cha, DocumentWorkspace, haName, image);

                ctha.SeriesGuid = context.seriesGuid;
                HistoryStack.PushNewMemento(ctha);

                this.currentHistoryMementos.Clear();
            }
        }
Beispiel #8
0
        public void PerformAction(DocumentWorkspace documentWorkspace)
        {
            HistoryMemento memento;

            if (documentWorkspace.Selection.IsEmpty)
            {
                memento = null;
            }
            else
            {
                CopyToClipboardAction action = new CopyToClipboardAction(documentWorkspace);
                if (!action.PerformAction())
                {
                    memento = null;
                }
                else
                {
                    using (new PushNullToolMode(documentWorkspace))
                    {
                        HistoryMemento         memento2 = new EraseSelectionFunction().Execute(documentWorkspace);
                        HistoryMemento[]       actions  = new HistoryMemento[] { memento2 };
                        CompoundHistoryMemento memento3 = new CompoundHistoryMemento(StaticName, StaticImage, actions);
                        memento = memento3;
                    }
                }
            }
            if (memento != null)
            {
                documentWorkspace.History.PushNewMemento(memento);
            }
        }
Beispiel #9
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            SelectionData state = null;
            SegmentedList <HistoryMemento> actions = new SegmentedList <HistoryMemento>();

            if (!historyWorkspace.Selection.IsEmpty)
            {
                state = historyWorkspace.Selection.Save();
                HistoryMemento memento3 = new DeselectFunction().Execute(historyWorkspace);
                actions.Add(memento3);
            }
            ReplaceDocumentHistoryMemento item = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);

            actions.Add(item);
            CompoundHistoryMemento memento2 = new CompoundHistoryMemento(StaticName, PdnResources.GetImageResource("Icons.MenuImageFlattenIcon.png"), actions);
            Document document = RetryManager.RunMemorySensitiveOperation <Document>(() => historyWorkspace.Document.Flatten());

            base.EnterCriticalRegion();
            historyWorkspace.Document = document;
            if (state != null)
            {
                SelectionHistoryMemento newHA = new SelectionHistoryMemento(null, null, historyWorkspace);
                historyWorkspace.Selection.Restore(state);
                memento2.AddMemento(newHA);
            }
            return(memento2);
        }
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            HistoryMemento memento          = null;
            int            activeLayerIndex = documentWorkspace.ActiveLayerIndex;

            if (activeLayerIndex != (documentWorkspace.Document.Layers.Count - 1))
            {
                HistoryMemento   memento2 = new SwapLayerFunction(activeLayerIndex, activeLayerIndex + 1).Execute(documentWorkspace);
                HistoryMemento[] actions  = new HistoryMemento[] { memento2 };
                memento = new CompoundHistoryMemento(StaticName, StaticImage, actions);
                documentWorkspace.ActiveLayer = (Layer)documentWorkspace.Document.Layers[activeLayerIndex + 1];
            }
            return(memento);
        }
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            CompoundHistoryMemento memento = new CompoundHistoryMemento(this.historyMementoName, this.historyMementoImage);

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction function = new DeselectFunction();
                base.EnterCriticalRegion();
                HistoryMemento memento4 = function.Execute(historyWorkspace);
                memento.AddMemento(memento4);
            }
            FlipLayerHistoryMemento newHA = new FlipLayerHistoryMemento(null, null, historyWorkspace, this.layerIndex, this.flipType);

            base.EnterCriticalRegion();
            HistoryMemento memento3 = newHA.PerformUndo(null);

            memento.AddMemento(newHA);
            return(memento);
        }
Beispiel #12
0
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            HistoryMemento hm    = null;
            int            index = documentWorkspace.ActiveLayerIndex;

            if (index != documentWorkspace.Document.Layers.Count - 1)
            {
                SwapLayerFunction slf   = new SwapLayerFunction(index, index + 1);
                HistoryMemento    slfhm = slf.Execute(documentWorkspace);

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

                documentWorkspace.ActiveLayer = (Layer)documentWorkspace.Document.Layers[index + 1];
            }

            return(hm);
        }
        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);
        }
Beispiel #14
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (this.layerIndex < 1 || this.layerIndex >= historyWorkspace.Document.Layers.Count)
            {
                throw new ArgumentException("layerIndex must be greater than or equal to 1, and a valid layer index. layerIndex=" +
                                            layerIndex + ", allowableRange=[0," + historyWorkspace.Document.Layers.Count + ")");
            }

            int       bottomLayerIndex = this.layerIndex - 1;
            Rectangle bounds           = historyWorkspace.Document.Bounds;
            PdnRegion region           = new PdnRegion(bounds);

            BitmapHistoryMemento bhm = new BitmapHistoryMemento(
                null,
                null,
                historyWorkspace,
                bottomLayerIndex,
                region);

            BitmapLayer topLayer    = (BitmapLayer)historyWorkspace.Document.Layers[this.layerIndex];
            BitmapLayer bottomLayer = (BitmapLayer)historyWorkspace.Document.Layers[bottomLayerIndex];
            RenderArgs  bottomRA    = new RenderArgs(bottomLayer.Surface);

            EnterCriticalRegion();

            topLayer.Render(bottomRA, region);
            bottomLayer.Invalidate();

            bottomRA.Dispose();
            bottomRA = null;

            region.Dispose();
            region = null;

            DeleteLayerFunction dlf  = new DeleteLayerFunction(this.layerIndex);
            HistoryMemento      dlhm = dlf.Execute(historyWorkspace);

            CompoundHistoryMemento chm = new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { bhm, dlhm });

            return(chm);
        }
Beispiel #15
0
        public void PerformAction(DocumentWorkspace documentWorkspace)
        {
            HistoryMemento finalHM;

            if (documentWorkspace.Selection.IsEmpty)
            {
                finalHM = null;
            }
            else
            {
                CopyToClipboardAction ctca = new CopyToClipboardAction(documentWorkspace);
                bool result = ctca.PerformAction();

                if (!result)
                {
                    finalHM = null;
                }
                else
                {
                    using (new PushNullToolMode(documentWorkspace))
                    {
                        EraseSelectionFunction esa = new EraseSelectionFunction();
                        HistoryMemento         hm  = esa.Execute(documentWorkspace);

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

                        finalHM = chm;
                    }
                }
            }

            if (finalHM != null)
            {
                documentWorkspace.History.PushNewMemento(finalHM);
            }
        }
Beispiel #16
0
 private void CommitDrawing()
 {
     ((TransactedTool <TDerived, TChanges>) this).VerifyAccess <TransactedTool <TDerived, TChanges> >();
     if (this.State != TransactedToolState.Drawing)
     {
         throw new InvalidOperationException($"Can only CommitDrawing when State is Drawing (State={this.State}, Tool={base.GetType().Name})");
     }
     if (this.beforeDrawingMemento == null)
     {
         throw new InternalErrorException($"this.beforeDrawingMemento == null (Tool={base.GetType().Name})");
     }
     if (!this.drawingAgent.TransactionToken.IsCommitting)
     {
         this.drawingAgent.TransactionToken.Commit();
     }
     else
     {
         this.OnEndingDrawing();
         this.drawingAgent.TransactionToken = null;
         this.drawingAgent = null;
         this.SetState(TransactedToolState.Dirty);
         this.CoerceChangesAfterEndDrawing();
         TChanges       newChanges           = this.Changes.Clone();
         HistoryMemento beforeDrawingMemento = this.beforeDrawingMemento;
         this.beforeDrawingMemento = null;
         TChanges      oldChanges = default(TChanges);
         string        historyMementoNameForChanges  = this.GetHistoryMementoNameForChanges(oldChanges, newChanges);
         ImageResource historyMementoImageForChanges = this.GetHistoryMementoImageForChanges(default(TChanges), newChanges);
         TransactedToolUndoDrawHistoryMemento <TDerived, TChanges>   memento2 = new TransactedToolUndoDrawHistoryMemento <TDerived, TChanges>(base.DocumentWorkspace, historyMementoNameForChanges, historyMementoImageForChanges, beforeDrawingMemento);
         TransactedToolUndoCommitHistoryMemento <TDerived, TChanges> memento3 = this.TryCommitChanges();
         if (!(beforeDrawingMemento is EmptyHistoryMemento) || !(memento3.InnerMemento is EmptyHistoryMemento))
         {
             HistoryMemento[]       actions  = new HistoryMemento[] { memento2, memento3 };
             CompoundHistoryMemento memento4 = new CompoundHistoryMemento(memento3.Name, memento3.Image, actions);
             base.HistoryStack.PushNewMemento(memento4);
         }
     }
 }
Beispiel #17
0
        private void FlushHistoryMementos(string name)
        {
            if (this.currentHistoryMementos.Count > 0)
            {
                CompoundHistoryMemento cha = new CompoundHistoryMemento(null, null,
                                                                        this.currentHistoryMementos.ToArray());

                string        haName;
                ImageResource image;

                if (this.didPaste)
                {
                    haName        = PdnResources.GetString("CommonAction.Paste");
                    image         = PdnResources.GetImageResource("Icons.MenuEditPasteIcon.png");
                    this.didPaste = false;
                }
                else
                {
                    if (name == null)
                    {
                        haName = this.Name;
                    }
                    else
                    {
                        haName = name;
                    }

                    image = this.Image;
                }

                CompoundToolHistoryMemento ctha = new CompoundToolHistoryMemento(cha, this.DocumentWorkspace, haName, image);

                ctha.SeriesGuid = context.seriesGuid;
                HistoryStack.PushNewMemento(ctha);

                this.currentHistoryMementos.Clear();
            }
        }
Beispiel #18
0
        public HistoryMemento ImportMultipleFiles(DocumentWorkspace documentWorkspace, string[] fileNames)
        {
            HistoryMemento memento = null;
            SegmentedList <HistoryMemento> historyMementos = new SegmentedList <HistoryMemento>();
            Rectangle empty = Rectangle.Empty;

            foreach (string str in fileNames)
            {
                HistoryMemento item = this.ImportOneFile(documentWorkspace, str, out empty);
                if (item != null)
                {
                    historyMementos.Add(item);
                }
                else
                {
                    this.Rollback(historyMementos);
                    historyMementos.Clear();
                    break;
                }
            }
            if ((empty.Width > 0) && (empty.Height > 0))
            {
                SelectionHistoryMemento memento3 = new SelectionHistoryMemento(null, null, documentWorkspace);
                historyMementos.Add(memento3);
                using (documentWorkspace.Selection.UseChangeScope())
                {
                    documentWorkspace.Selection.Reset();
                    documentWorkspace.Selection.SetContinuation(empty.ToRectInt32(), SelectionCombineMode.Replace);
                    documentWorkspace.Selection.CommitContinuation();
                }
            }
            if (historyMementos.Count > 0)
            {
                HistoryMemento[] actions = historyMementos.ToArrayEx <HistoryMemento>();
                memento = new CompoundHistoryMemento(StaticName, StaticImage, actions);
            }
            return(memento);
        }
Beispiel #19
0
        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);
        }
Beispiel #20
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,
                ImageResource.Get("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);
        }
Beispiel #21
0
 public CompoundToolHistoryMemento(CompoundHistoryMemento chm, DocumentWorkspace documentWorkspace, string name, ImageResource image)
     : base(documentWorkspace, name, image)
 {
     this.CompoundHistoryMemento = chm;
 }
Beispiel #22
0
        private bool PerformActionImpl()
        {
            PointInt32 num2;
            RectInt32  num3;

            if (this.clipData == null)
            {
                try
                {
                    using (new WaitCursorChanger(this.documentWorkspace))
                    {
                        CleanupManager.RequestCleanup();
                        this.clipData = PdnClipboard.GetDataObject();
                    }
                }
                catch (OutOfMemoryException exception)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception);
                    return(false);
                }
                catch (Exception exception2)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception2);
                    return(false);
                }
            }
            bool handled = false;

            if (this.documentWorkspace.Tool != null)
            {
                this.documentWorkspace.Tool.PerformPaste(this.clipData, out handled);
            }
            if (handled)
            {
                return(true);
            }
            if (this.maskedSurface == null)
            {
                try
                {
                    using (new WaitCursorChanger(this.documentWorkspace))
                    {
                        this.maskedSurface = ClipboardUtil.GetClipboardImage(this.documentWorkspace, this.clipData);
                    }
                }
                catch (OutOfMemoryException exception3)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception3);
                    return(false);
                }
                catch (Exception exception4)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception4);
                    return(false);
                }
            }
            if (this.maskedSurface == null)
            {
                MessageBoxUtil.ErrorBox(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.NoImage"));
                return(false);
            }
            RectInt32 cachedGeometryMaskScansBounds = this.maskedSurface.GetCachedGeometryMaskScansBounds();

            if ((cachedGeometryMaskScansBounds.Width > this.documentWorkspace.Document.Width) || (cachedGeometryMaskScansBounds.Height > this.documentWorkspace.Document.Height))
            {
                Surface surface;
                try
                {
                    using (new WaitCursorChanger(this.documentWorkspace))
                    {
                        surface = CreateThumbnail(this.maskedSurface);
                    }
                }
                catch (OutOfMemoryException)
                {
                    surface = null;
                }
                DialogResult result           = ShowExpandCanvasTaskDialog(this.documentWorkspace, surface);
                int          activeLayerIndex = this.documentWorkspace.ActiveLayerIndex;
                ColorBgra    background       = this.documentWorkspace.ToolSettings.SecondaryColor.Value;
                if (result != DialogResult.Cancel)
                {
                    if (result != DialogResult.Yes)
                    {
                        if (result != DialogResult.No)
                        {
                            throw ExceptionUtil.InvalidEnumArgumentException <DialogResult>(result, "dr");
                        }
                        goto Label_031D;
                    }
                    using (new PushNullToolMode(this.documentWorkspace))
                    {
                        int      width    = Math.Max(cachedGeometryMaskScansBounds.Width, this.documentWorkspace.Document.Width);
                        Size     newSize  = new Size(width, Math.Max(cachedGeometryMaskScansBounds.Height, this.documentWorkspace.Document.Height));
                        Document document = CanvasSizeAction.ResizeDocument(this.documentWorkspace.Document, newSize, AnchorEdge.TopLeft, background);
                        if (document == null)
                        {
                            return(false);
                        }
                        SelectionHistoryMemento       memento  = new SelectionHistoryMemento(null, null, this.documentWorkspace);
                        ReplaceDocumentHistoryMemento memento2 = new ReplaceDocumentHistoryMemento(CanvasSizeAction.StaticName, CanvasSizeAction.StaticImage, this.documentWorkspace);
                        this.documentWorkspace.Document = document;
                        HistoryMemento[]       actions  = new HistoryMemento[] { memento, memento2 };
                        CompoundHistoryMemento memento3 = new CompoundHistoryMemento(CanvasSizeAction.StaticName, CanvasSizeAction.StaticImage, actions);
                        this.documentWorkspace.History.PushNewMemento(memento3);
                        this.documentWorkspace.ActiveLayer = (Layer)this.documentWorkspace.Document.Layers[activeLayerIndex];
                        goto Label_031D;
                    }
                }
                return(false);
            }
Label_031D:
            num3 = this.documentWorkspace.Document.Bounds();
            RectDouble visibleDocumentRect = this.documentWorkspace.VisibleDocumentRect;
            RectInt32? nullable            = visibleDocumentRect.Int32Inset();
            RectDouble num5 = nullable.HasValue ? ((RectDouble)nullable.Value) : visibleDocumentRect;
            RectInt32  num6 = num5.Int32Bound;

            if (num5.Contains(cachedGeometryMaskScansBounds))
            {
                num2 = new PointInt32(0, 0);
            }
            else
            {
                int num12;
                int num13;
                int num16;
                int num17;
                if (cachedGeometryMaskScansBounds.X < num5.Left)
                {
                    num12 = -cachedGeometryMaskScansBounds.X + num6.X;
                }
                else if (cachedGeometryMaskScansBounds.Right > num6.Right)
                {
                    num12 = (-cachedGeometryMaskScansBounds.X + num6.Right) - cachedGeometryMaskScansBounds.Width;
                }
                else
                {
                    num12 = 0;
                }
                if (cachedGeometryMaskScansBounds.Y < num5.Top)
                {
                    num13 = -cachedGeometryMaskScansBounds.Y + num6.Y;
                }
                else if (cachedGeometryMaskScansBounds.Bottom > num6.Bottom)
                {
                    num13 = (-cachedGeometryMaskScansBounds.Y + num6.Bottom) - cachedGeometryMaskScansBounds.Height;
                }
                else
                {
                    num13 = 0;
                }
                PointInt32 num14 = new PointInt32(num12, num13);
                RectInt32  num15 = new RectInt32(cachedGeometryMaskScansBounds.X + num14.X, cachedGeometryMaskScansBounds.Y + num14.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height);
                if (num15.X < 0)
                {
                    num16 = num12 - num15.X;
                }
                else
                {
                    num16 = num12;
                }
                if (num15.Y < 0)
                {
                    num17 = num13 - num15.Y;
                }
                else
                {
                    num17 = num13;
                }
                PointInt32 num18 = new PointInt32(num16, num17);
                RectInt32  rect  = new RectInt32(cachedGeometryMaskScansBounds.X + num18.X, cachedGeometryMaskScansBounds.Y + num18.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height);
                if (num3.Contains(rect))
                {
                    num2 = num18;
                }
                else
                {
                    PointInt32 num20 = num18;
                    if (rect.Right > num3.Right)
                    {
                        int num21 = rect.Right - num3.Right;
                        int num22 = Math.Min(num21, rect.Left);
                        num20.X -= num22;
                    }
                    if (rect.Bottom > num3.Bottom)
                    {
                        int num23 = rect.Bottom - num3.Bottom;
                        int num24 = Math.Min(num23, rect.Top);
                        num20.Y -= num24;
                    }
                    num2 = num20;
                }
            }
            RectInt32 b           = this.documentWorkspace.VisibleDocumentRect.Int32Bound;
            RectInt32 a           = new RectInt32(cachedGeometryMaskScansBounds.X + num2.X, cachedGeometryMaskScansBounds.Y + num2.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height);
            bool      hasZeroArea = RectInt32.Intersect(a, b).HasZeroArea;

            MoveTool.BeginPaste(this.documentWorkspace, PdnResources.GetString("CommonAction.Paste"), PdnResources.GetImageResource("Icons.MenuEditPasteIcon.png"), this.maskedSurface.SurfaceReadOnly, this.maskedSurface.GeometryMask, num2);
            if (hasZeroArea)
            {
                PointInt32  num25 = new PointInt32(b.Left + (b.Width / 2), b.Top + (b.Height / 2));
                PointInt32  num26 = new PointInt32(a.Left + (a.Width / 2), a.Top + (a.Height / 2));
                SizeInt32   num27 = new SizeInt32(num26.X - num25.X, num26.Y - num25.Y);
                PointDouble documentScrollPosition = this.documentWorkspace.DocumentScrollPosition;
                PointDouble num29 = new PointDouble(documentScrollPosition.X + num27.Width, documentScrollPosition.Y + num27.Height);
                this.documentWorkspace.DocumentScrollPosition = num29;
            }
            return(true);
        }
Beispiel #23
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            int newWidth;
            int newHeight;

            // Get new width and Height
            switch (rotation)
            {
            case RotateType.Clockwise90:
            case RotateType.CounterClockwise90:
                newWidth  = historyWorkspace.Document.Height;
                newHeight = historyWorkspace.Document.Width;
                break;

            case RotateType.Rotate180:
                newWidth  = historyWorkspace.Document.Width;
                newHeight = historyWorkspace.Document.Height;
                break;

            default:
                throw new InvalidEnumArgumentException("invalid RotateType");
            }

            // Figure out which icon and text to use
            string iconResName;
            string suffix;

            switch (rotation)
            {
            case RotateType.Rotate180:
                iconResName = "Icons.MenuImageRotate180Icon.png";
                suffix      = PdnResources.GetString("RotateAction.180");
                break;

            case RotateType.Clockwise90:
                iconResName = "Icons.MenuImageRotate90CWIcon.png";
                suffix      = PdnResources.GetString("RotateAction.90CW");
                break;

            case RotateType.CounterClockwise90:
                iconResName = "Icons.MenuImageRotate90CCWIcon.png";
                suffix      = PdnResources.GetString("RotateAction.90CCW");
                break;

            default:
                throw new InvalidEnumArgumentException("invalid RotateType");
            }

            // Initialize the new Doc
            string        haNameFormat = PdnResources.GetString("RotateAction.HistoryMementoName.Format");
            string        haName       = string.Format(haNameFormat, StaticName, suffix);
            ImageResource haImage      = PdnResources.GetImageResource(iconResName);

            List <HistoryMemento> actions = new List <HistoryMemento>();

            // do the memory allocation now: if this fails, we can still bail out cleanly
            Document newDoc = new Document(newWidth, newHeight);

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

            ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);

            actions.Add(rdha);

            newDoc.ReplaceMetaDataFrom(historyWorkspace.Document);

            // TODO: serialize oldDoc to disk, and let the GC purge it if needed
            OnProgress(0.0);

            for (int i = 0; i < historyWorkspace.Document.Layers.Count; ++i)
            {
                Layer layer = historyWorkspace.Document.Layers.GetAt(i);

                double progressStart = 100.0 * ((double)i / (double)historyWorkspace.Document.Layers.Count);
                double progressEnd   = 100.0 * ((double)(i + 1) / (double)historyWorkspace.Document.Layers.Count);

                if (layer is BitmapLayer)
                {
                    Layer nl = RotateLayer((BitmapLayer)layer, rotation, newWidth, newHeight, progressStart, progressEnd);
                    newDoc.Layers.Add(nl);
                }
                else
                {
                    throw new InvalidOperationException("Cannot Rotate non-BitmapLayers");
                }

                if (this.PleaseCancel)
                {
                    break;
                }

                OnProgress(progressEnd);
            }

            CompoundHistoryMemento chm = new CompoundHistoryMemento(
                haName,
                haImage,
                actions);

            if (this.PleaseCancel)
            {
                chm = null;
            }
            else
            {
                EnterCriticalRegion();
                historyWorkspace.Document = newDoc;
            }

            return(chm);
        }
Beispiel #24
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            int    height;
            int    width;
            string str;
            string str2;

            switch (this.rotation)
            {
            case RotateType.Clockwise90:
            case RotateType.CounterClockwise90:
                height = historyWorkspace.Document.Height;
                width  = historyWorkspace.Document.Width;
                break;

            case RotateType.Rotate180:
                height = historyWorkspace.Document.Width;
                width  = historyWorkspace.Document.Height;
                break;

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <RotateType>(this.rotation, "this.rotation");
            }
            switch (this.rotation)
            {
            case RotateType.Clockwise90:
                str  = "Icons.MenuImageRotate90CWIcon.png";
                str2 = PdnResources.GetString("RotateAction.90CW");
                break;

            case RotateType.CounterClockwise90:
                str  = "Icons.MenuImageRotate90CCWIcon.png";
                str2 = PdnResources.GetString("RotateAction.90CCW");
                break;

            case RotateType.Rotate180:
                str  = "Icons.MenuImageRotate180Icon.png";
                str2 = PdnResources.GetString("RotateAction.180");
                break;

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <RotateType>(this.rotation, "this.rotation");
            }
            string                name          = string.Format(PdnResources.GetString("RotateAction.HistoryMementoName.Format"), StaticName, str2);
            ImageResource         imageResource = PdnResources.GetImageResource(str);
            List <HistoryMemento> actions       = new List <HistoryMemento>();
            Document              document      = new Document(height, width);

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction function = new DeselectFunction();
                base.EnterCriticalRegion();
                HistoryMemento memento3 = function.Execute(historyWorkspace);
                actions.Add(memento3);
            }
            ReplaceDocumentHistoryMemento item = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);

            actions.Add(item);
            document.ReplaceMetadataFrom(historyWorkspace.Document);
            for (int i = 0; i < historyWorkspace.Document.Layers.Count; i++)
            {
                Layer at = historyWorkspace.Document.Layers.GetAt(i);
                if (!(at is BitmapLayer))
                {
                    throw new InvalidOperationException("Cannot Rotate non-BitmapLayers");
                }
                Layer layer2 = this.RotateLayer((BitmapLayer)at, this.rotation, height, width);
                document.Layers.Add(layer2);
            }
            CompoundHistoryMemento memento2 = new CompoundHistoryMemento(name, imageResource, actions);

            base.EnterCriticalRegion();
            historyWorkspace.Document = document;
            return(memento2);
        }
        private HistoryMemento ImportOneLayer(DocumentWorkspace documentWorkspace, BitmapLayer layer)
        {
            HistoryMemento        retHA;
            List <HistoryMemento> historyMementos = new List <HistoryMemento>();
            bool success = true;

            if (success)
            {
                if (!documentWorkspace.Selection.IsEmpty)
                {
                    HistoryMemento ha = new DeselectFunction().Execute(documentWorkspace);
                    historyMementos.Add(ha);
                }
            }

            if (success)
            {
                if (layer.Width > documentWorkspace.Document.Width ||
                    layer.Height > documentWorkspace.Document.Height)
                {
                    HistoryMemento ha = DoCanvasResize(documentWorkspace, layer.Size);

                    if (ha == null)
                    {
                        success = false;
                    }
                    else
                    {
                        historyMementos.Add(ha);
                    }
                }
            }

            if (success)
            {
                if (layer.Size != documentWorkspace.Document.Size)
                {
                    BitmapLayer newLayer;

                    try
                    {
                        using (new WaitCursorChanger(documentWorkspace))
                        {
                            Utility.GCFullCollect();

                            newLayer = CanvasSizeAction.ResizeLayer((BitmapLayer)layer, documentWorkspace.Document.Size,
                                                                    AnchorEdge.TopLeft, ColorBgra.White.NewAlpha(0));
                        }
                    }

                    catch (OutOfMemoryException)
                    {
                        Utility.ErrorBox(documentWorkspace, PdnResources.GetString("ImportFromFileAction.ImportOneLayer.OutOfMemory"));
                        success  = false;
                        newLayer = null;
                    }

                    if (newLayer != null)
                    {
                        layer.Dispose();
                        layer = newLayer;
                    }
                }
            }

            if (success)
            {
                NewLayerHistoryMemento nlha = new NewLayerHistoryMemento(string.Empty, null, documentWorkspace, documentWorkspace.Document.Layers.Count);
                documentWorkspace.Document.Layers.Add(layer);
                historyMementos.Add(nlha);
            }

            if (success)
            {
                HistoryMemento[] has = historyMementos.ToArray();
                retHA = new CompoundHistoryMemento(string.Empty, null, has);
            }
            else
            {
                Rollback(historyMementos);
                retHA = null;
            }

            return(retHA);
        }
Beispiel #26
0
        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);
            }
        }
Beispiel #27
0
        protected void CommitShape()
        {
            OnShapeCommitting();

            mouseDown = false;

            ArrayList has          = new ArrayList();
            PdnRegion activeRegion = Selection.CreateRegion();

            if (outlineSaveRegion != null)
            {
                using (PdnRegion clipTest = activeRegion.Clone())
                {
                    clipTest.Intersect(outlineSaveRegion);

                    if (!clipTest.IsEmpty())
                    {
                        BitmapHistoryMemento bha = new BitmapHistoryMemento(Name, Image, this.DocumentWorkspace,
                                                                            ActiveLayerIndex, outlineSaveRegion, this.ScratchSurface);

                        has.Add(bha);
                        outlineSaveRegion.Dispose();
                        outlineSaveRegion = null;
                    }
                }
            }

            if (interiorSaveRegion != null)
            {
                using (PdnRegion clipTest = activeRegion.Clone())
                {
                    clipTest.Intersect(interiorSaveRegion);

                    if (!clipTest.IsEmpty())
                    {
                        BitmapHistoryMemento bha = new BitmapHistoryMemento(Name, Image, this.DocumentWorkspace,
                                                                            ActiveLayerIndex, interiorSaveRegion, this.ScratchSurface);

                        has.Add(bha);
                        interiorSaveRegion.Dispose();
                        interiorSaveRegion = null;
                    }
                }
            }

            if (has.Count > 0)
            {
                CompoundHistoryMemento cha = new CompoundHistoryMemento(Name, Image, (HistoryMemento[])has.ToArray(typeof(HistoryMemento)));

                if (this.chaAlreadyOnStack == null)
                {
                    HistoryStack.PushNewMemento(cha);
                }
                else
                {
                    this.chaAlreadyOnStack.PushNewAction(cha);
                    this.chaAlreadyOnStack = null;
                }
            }

            activeRegion.Dispose();
            points = null;
            Update();
            this.shapeWasCommited = true;
        }
Beispiel #28
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            PointF          mousePt        = new PointF(e.X, e.Y);
            MoveNubRenderer mouseCursorNub = PointToNub(mousePt);

            if (this.mouseButton != MouseButtons.None)
            {
                this.shouldMoveBothNubs = !this.shouldMoveBothNubs;
            }
            else
            {
                bool startNewGradient = true;
                this.mouseButton = e.Button;

                if (!this.gradientActive)
                {
                    this.shouldSwapColors = (this.mouseButton == MouseButtons.Right);
                }
                else
                {
                    this.shouldMoveBothNubs = false;

                    // We are already in the process of drawing or adjusting a gradient.
                    // Determine if they clicked to drag one of the nubs for adjusting.

                    if (mouseCursorNub == null)
                    {
                        // No. Commit the old gradient and begin a new one.
                        CommitGradient();
                        startNewGradient      = true;
                        this.shouldSwapColors = (this.mouseButton == MouseButtons.Right);
                    }
                    else
                    {
                        // Yes. Continue adjusting the old gradient.
                        Cursor = this.handCursorMouseDown;

                        this.mouseNub          = mouseCursorNub;
                        this.mouseNub.Location = mousePt;

                        if (this.mouseNub == this.startNub)
                        {
                            this.startPoint = mousePt;
                        }
                        else
                        {
                            this.endPoint = mousePt;
                        }

                        if (this.mouseButton == MouseButtons.Right)
                        {
                            this.shouldSwapColors = !this.shouldSwapColors;
                        }

                        RenderGradient();
                        startNewGradient = false;
                    }
                }

                if (startNewGradient)
                {
                    // Brand new gradient. Set everything up.
                    this.startPoint        = mousePt;
                    this.startNub.Location = mousePt;
                    this.startNub.Visible  = true;

                    this.endNub.Location = mousePt;
                    this.endNub.Visible  = true;
                    this.endPoint        = mousePt;

                    this.mouseNub = mouseCursorNub;

                    Cursor = this.toolMouseDownCursor;

                    this.gradientActive = true;

                    ClearSavedRegion();
                    RenderGradient();

                    this.historyMemento = new CompoundHistoryMemento(StaticName, StaticImage);
                    HistoryStack.PushNewMemento(this.historyMemento); // this makes it so they can push Esc to undo
                }
            }

            base.OnMouseDown(e);
        }