public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (historyWorkspace.Selection.IsEmpty)
            {
                return null;
            }

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

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

            EnterCriticalRegion();

            layer.Surface.Clear(region, this.fillColor);
            layer.Invalidate(simplifiedRegion);

            simplifiedRegion.Dispose();
            region.Dispose();

            return hm;
        }
Exemple #2
0
        protected override HistoryMemento OnUndo(ProgressEventHandler progressCallback)
        {
            BitmapHistoryMementoData data = base.Data as BitmapHistoryMementoData;
            BitmapLayer layer             = (BitmapLayer)this.historyWorkspace.Document.Layers[this.layerIndex];

            RectInt32[]          savedRegion = data.SavedRegion;
            MaskedSurface        surface     = null;
            BitmapHistoryMemento memento     = new BitmapHistoryMemento(base.Name, base.Image, this.historyWorkspace, this.layerIndex, savedRegion);

            if (surface != null)
            {
                surface.Draw(layer.Surface);
            }
            else
            {
                using (FileStream stream = FileSystem.OpenStreamingFile(this.tempFileName, FileAccess.Read))
                {
                    LoadSurfaceRegion(stream, layer.Surface, data.SavedRegion);
                }
                this.tempFileHandle.Dispose();
                this.tempFileHandle = null;
            }
            if (savedRegion.Length != 0)
            {
                RectInt32 roi = savedRegion.Bounds();
                layer.Invalidate(roi);
            }
            return(memento);
        }
        protected override void OnFillRegionComputed(Point[][] polygonSet)
        {
            using (PdnGraphicsPath path = new PdnGraphicsPath())
            {
                path.AddPolygons(polygonSet);

                using (PdnRegion fillRegion = new PdnRegion(path))
                {
                    Rectangle boundingBox = fillRegion.GetBoundsInt();

                    Surface surface = ((BitmapLayer)ActiveLayer).Surface;
                    RenderArgs ra = new RenderArgs(surface);
                    HistoryMemento ha;

                    using (PdnRegion affected = Utility.SimplifyAndInflateRegion(fillRegion))
                    {
                        ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, DocumentWorkspace.ActiveLayerIndex, affected);
                    }

                    ra.Graphics.CompositingMode = AppEnvironment.GetCompositingMode();
                    ra.Graphics.FillRegion(brush, fillRegion.GetRegionReadOnly());

                    HistoryStack.PushNewMemento(ha);
                    ActiveLayer.Invalidate(boundingBox);
                    Update();
                }
            }
        }
        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;
        }
        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;
        }
Exemple #6
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (!KeyDownShiftOnly() && !KeyDownControlOnly())
            {
                Cursor = cursorMouseUp;
            }

            if (mouseDown)
            {
                this.previewRenderer.Visible = true;

                OnMouseMove(e);

                if (savedSurfaces.Count > 0)
                {
                    PdnRegion saveMeRegion = new PdnRegion();
                    saveMeRegion.MakeEmpty();

                    foreach (PlacedSurface pi1 in savedSurfaces)
                    {
                        saveMeRegion.Union(pi1.Bounds);
                    }

                    PdnRegion simplifiedRegion = Utility.SimplifyAndInflateRegion(saveMeRegion);

                    using (IrregularSurface weDrewThis = new IrregularSurface(renderArgs.Surface, simplifiedRegion))
                    {
                        for (int i = savedSurfaces.Count - 1; i >= 0; --i)
                        {
                            PlacedSurface ps = (PlacedSurface)savedSurfaces[i];
                            ps.Draw(renderArgs.Surface);
                            ps.Dispose();
                        }

                        savedSurfaces.Clear();

                        if (hasDrawn)
                        {
                            HistoryMemento ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, 
                                ActiveLayerIndex, simplifiedRegion);

                            weDrewThis.Draw(bitmapLayer.Surface);
                            HistoryStack.PushNewMemento(ha);
                        }
                    }
                }

                mouseDown = false;
                modifierDown = 0;
            }

            if (brushRenderArgs != null)
            {
                if (brushRenderArgs.Surface != null)
                {
                    brushRenderArgs.Surface.Dispose();
                }
            }
        }
Exemple #7
0
        protected override HistoryMemento OnUndo()
        {
            BitmapHistoryMementoData data = this.Data as BitmapHistoryMementoData;
            BitmapLayer layer             = (BitmapLayer)this.historyWorkspace.Document.Layers[this.layerIndex];

            PdnRegion     region;
            MaskedSurface maskedSurface = null;

            if (this.poMaskedSurfaceRef != Guid.Empty)
            {
                PersistedObject <MaskedSurface> poMS = PersistedObjectLocker.Get <MaskedSurface>(this.poMaskedSurfaceRef);
                maskedSurface = poMS.Object;
                region        = maskedSurface.CreateRegion();
            }
            else if (data.UndoImage == null)
            {
                region = data.SavedRegion;
            }
            else
            {
                region = data.UndoImage.Region;
            }

            BitmapHistoryMemento redo;

            if (this.poUndoMaskedSurfaceRef == Guid.Empty)
            {
                redo = new BitmapHistoryMemento(Name, Image, this.historyWorkspace, this.layerIndex, region);
                redo.poUndoMaskedSurfaceRef = this.poMaskedSurfaceRef;
            }
            else
            {
                redo = new BitmapHistoryMemento(Name, Image, this.historyWorkspace, this.layerIndex, this.poUndoMaskedSurfaceRef);
            }

            PdnRegion simplified = Utility.SimplifyAndInflateRegion(region);

            if (maskedSurface != null)
            {
                maskedSurface.Draw(layer.Surface);
            }
            else if (data.UndoImage == null)
            {
                using (FileStream input = FileSystem.OpenStreamingFile(this.tempFileName, FileAccess.Read))
                {
                    LoadSurfaceRegion(input, layer.Surface, data.SavedRegion);
                }

                data.SavedRegion.Dispose();
                this.tempFileHandle.Dispose();
                this.tempFileHandle = null;
            }
            else
            {
                data.UndoImage.Draw(layer.Surface);
                data.UndoImage.Dispose();
            }

            layer.Invalidate(simplified);
            simplified.Dispose();

            return(redo);
        }
        protected override HistoryMemento OnUndo()
        {
            BitmapHistoryMementoData data = this.Data as BitmapHistoryMementoData;
            BitmapLayer layer = (BitmapLayer)this.historyWorkspace.Document.Layers[this.layerIndex];
            
            PdnRegion region;
            MaskedSurface maskedSurface = null;

            if (this.poMaskedSurfaceRef != Guid.Empty)
            {
                PersistedObject<MaskedSurface> poMS = PersistedObjectLocker.Get<MaskedSurface>(this.poMaskedSurfaceRef);
                maskedSurface = poMS.Object;
                region = maskedSurface.CreateRegion();
            }
            else if (data.UndoImage == null)
            {
                region = data.SavedRegion;
            }
            else
            {
                region = data.UndoImage.Region;
            }

            BitmapHistoryMemento redo;

            if (this.poUndoMaskedSurfaceRef == Guid.Empty)
            {
                redo = new BitmapHistoryMemento(Name, Image, this.historyWorkspace, this.layerIndex, region);
                redo.poUndoMaskedSurfaceRef = this.poMaskedSurfaceRef;
            }
            else
            {
                redo = new BitmapHistoryMemento(Name, Image, this.historyWorkspace, this.layerIndex, this.poUndoMaskedSurfaceRef);
            }

            PdnRegion simplified = Utility.SimplifyAndInflateRegion(region);

            if (maskedSurface != null)
            {
                maskedSurface.Draw(layer.Surface);
            }
            else if (data.UndoImage == null)
            {
                using (FileStream input = FileSystem.OpenStreamingFile(this.tempFileName, FileAccess.Read))
                {
                    LoadSurfaceRegion(input, layer.Surface, data.SavedRegion);
                }

                data.SavedRegion.Dispose();
                this.tempFileHandle.Dispose();
                this.tempFileHandle = null;
            }
            else
            {
                data.UndoImage.Draw(layer.Surface);
                data.UndoImage.Dispose();
            }

            layer.Invalidate(simplified);
            simplified.Dispose();

            return redo;
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            mouseUp = true;

            if (!mouseDownSettingCloneSource)
            {
                Cursor = cursorMouseUp;
            }

            if (IsMouseLeftDown(e))
            {
                this.rendererDst.Visible = true;

                if (savedRegion != null)
                {
                    //RestoreRegion(this.savedRegion);
                    ActiveLayer.Invalidate(this.savedRegion.GetBoundsInt());
                    savedRegion.Dispose();
                    savedRegion = null;
                    Update();
                }

                if (GetStaticData().takeFrom == Point.Empty || GetStaticData().lastMoved == Point.Empty)
                {
                    return;
                }

                if (historyRects.Count > 0)
                {
                    PdnRegion saveMeRegion;

                    Rectangle[] rectsRO;
                    int rectsROLength;
                    this.historyRects.GetArrayReadOnly(out rectsRO, out rectsROLength);
                    saveMeRegion = Utility.RectanglesToRegion(rectsRO, 0, rectsROLength);

                    PdnRegion simplifiedRegion = Utility.SimplifyAndInflateRegion(saveMeRegion);
                    SaveRegion(simplifiedRegion, simplifiedRegion.GetBoundsInt());

                    historyRects = new Vector<Rectangle>();

                    HistoryMemento ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, ActiveLayerIndex,
                        simplifiedRegion, this.ScratchSurface);

                    HistoryStack.PushNewMemento(ha);
                    this.ClearSavedMemory();
                }
            }
        }
Exemple #10
0
        private void SaveHistoryMemento()
        {
            pulseEnabled = false;
            RedrawText(false);

            if (saved != null)
            {
                PdnRegion hitTest = Selection.CreateRegion();
                hitTest.Intersect(saved.Region);

                if (!hitTest.IsEmpty())
                {
                    BitmapHistoryMemento bha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace,
                        ActiveLayerIndex, saved);

                    if (this.currentHA == null)
                    {
                        HistoryStack.PushNewMemento(bha);
                    }
                    else
                    {
                        this.currentHA.PushNewAction(bha);
                        this.currentHA = null;
                    }
                }

                hitTest.Dispose();
                saved.Dispose();
                saved = null;
            }
        }
Exemple #11
0
        protected override void OnLift(MouseEventArgs e)
        {
            PdnGraphicsPath liftPath = Selection.CreatePath();
            PdnRegion liftRegion = Selection.CreateRegion();

            this.ourContext.LiftedPixels = new MaskedSurface(activeLayer.Surface, liftPath);

            HistoryMemento bitmapAction = new BitmapHistoryMemento(
                Name, 
                Image, 
                DocumentWorkspace, 
                ActiveLayerIndex, 
                this.ourContext.poLiftedPixelsGuid);

            this.currentHistoryMementos.Add(bitmapAction);
            
            // If the user is holding down the control key, we want to *copy* the pixels
            // and not "lift and erase"
            if ((ModifierKeys & Keys.Control) == Keys.None)
            {
                ColorBgra fill = AppEnvironment.SecondaryColor;
                fill.A = 0;
                UnaryPixelOp op = new UnaryPixelOps.Constant(fill);
                op.Apply(this.renderArgs.Surface, liftRegion);
            }

            liftRegion.Dispose();
            liftRegion = null;

            liftPath.Dispose();
            liftPath = null;
        }
Exemple #12
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);
        }
Exemple #13
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"));
        }
Exemple #14
0
        protected override void OnStylusUp(StylusEventArgs e)
        {
            base.OnStylusUp(e);

            Cursor = cursorMouseUp;

            if (mouseDown)
            {
                this.previewRenderer.Visible = true;
                mouseDown = false;

                if (this.savedRects.Count > 0)
                {
                    PdnRegion saveMeRegion = Utility.RectanglesToRegion(this.savedRects.ToArray());
                    HistoryMemento ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, 
                        ActiveLayerIndex, saveMeRegion, this.ScratchSurface);
                    HistoryStack.PushNewMemento(ha);
                    saveMeRegion.Dispose();
                    this.savedRects.Clear();
                    this.ClearSavedMemory();
                }

                this.brush.Dispose();
                this.brush = null;
            }
        }
        private bool DoEffect(Effect effect, EffectConfigToken token, PdnRegion selectedRegion,
            PdnRegion regionToRender, Surface originalSurface)
        {
            bool oldDirtyValue = AppWorkspace.ActiveDocumentWorkspace.Document.Dirty;
            bool resetDirtyValue = false;

            bool returnVal = false;
            AppWorkspace.ActiveDocumentWorkspace.EnableOutlineAnimation = false;

            try
            {
                using (ProgressDialog aed = new ProgressDialog())
                {
                    if (effect.Image != null)
                    {
                        aed.Icon = Utility.ImageToIcon(effect.Image, Utility.TransparentKey);
                    }

                    aed.Opacity = 0.9;
                    aed.Value = 0;
                    aed.Text = effect.Name;
                    aed.Description = string.Format(PdnResources.GetString("Effects.ApplyingDialog.Description"), effect.Name);

                    invalidateTimer.Enabled = true;

                    using (new WaitCursorChanger(AppWorkspace))
                    {
                        HistoryMemento ha = null;
                        DialogResult result = DialogResult.None;

                        AppWorkspace.Widgets.StatusBarProgress.ResetProgressStatusBar();
                        AppWorkspace.Widgets.LayerControl.SuspendLayerPreviewUpdates();

                        try
                        {
                            ManualResetEvent saveEvent = new ManualResetEvent(false);
                            BitmapHistoryMemento bha = null;

                            // perf bug #1445: save this data in a background thread
                            PdnRegion selectedRegionCopy = selectedRegion.Clone();
                            PaintDotNet.Threading.ThreadPool.Global.QueueUserWorkItem(
                                delegate(object context)
                                {
                                    try
                                    {
                                        ImageResource image;

                                        if (effect.Image == null)
                                        {
                                            image = null;
                                        }
                                        else
                                        {
                                            image = ImageResource.FromImage(effect.Image);
                                        }

                                        bha = new BitmapHistoryMemento(effect.Name, image, this.AppWorkspace.ActiveDocumentWorkspace,
                                            this.AppWorkspace.ActiveDocumentWorkspace.ActiveLayerIndex, selectedRegionCopy, originalSurface);
                                    }

                                    finally
                                    {
                                        saveEvent.Set();
                                        selectedRegionCopy.Dispose();
                                        selectedRegionCopy = null;
                                    }
                                });

                            BackgroundEffectRenderer ber = new BackgroundEffectRenderer(
                                effect,
                                token,
                                new RenderArgs(((BitmapLayer)AppWorkspace.ActiveDocumentWorkspace.ActiveLayer).Surface),
                                new RenderArgs(originalSurface),
                                regionToRender,
                                tilesPerCpu * renderingThreadCount,
                                renderingThreadCount);

                            aed.Tag = ber;
                            ber.RenderedTile += new RenderedTileEventHandler(aed.RenderedTileHandler);
                            ber.RenderedTile += new RenderedTileEventHandler(RenderedTileHandler);
                            ber.StartingRendering += new EventHandler(StartingRenderingHandler);
                            ber.FinishedRendering += new EventHandler(aed.FinishedRenderingHandler);
                            ber.FinishedRendering += new EventHandler(FinishedRenderingHandler);
                            ber.Start();

                            result = Utility.ShowDialog(aed, AppWorkspace);

                            if (result == DialogResult.Cancel)
                            {
                                resetDirtyValue = true;

                                using (new WaitCursorChanger(AppWorkspace))
                                {
                                    ber.Abort();
                                    ber.Join();
                                    ((BitmapLayer)AppWorkspace.ActiveDocumentWorkspace.ActiveLayer).Surface.CopySurface(originalSurface);
                                }
                            }

                            invalidateTimer.Enabled = false;

                            ber.Join();
                            ber.Dispose();

                            saveEvent.WaitOne();
                            saveEvent.Close();
                            saveEvent = null;

                            ha = bha;
                        }

                        catch
                        {
                            using (new WaitCursorChanger(AppWorkspace))
                            {
                                ((BitmapLayer)AppWorkspace.ActiveDocumentWorkspace.ActiveLayer).Surface.CopySurface(originalSurface);
                                ha = null;
                            }
                        }

                        finally
                        {
                            AppWorkspace.Widgets.LayerControl.ResumeLayerPreviewUpdates();
                        }

                        using (PdnRegion simplifiedRenderRegion = Utility.SimplifyAndInflateRegion(selectedRegion))
                        {
                            using (new WaitCursorChanger(AppWorkspace))
                            {
                                AppWorkspace.ActiveDocumentWorkspace.ActiveLayer.Invalidate(simplifiedRenderRegion);
                            }
                        }

                        using (new WaitCursorChanger(AppWorkspace))
                        {
                            if (result == DialogResult.OK)
                            {
                                if (ha != null)
                                {
                                    AppWorkspace.ActiveDocumentWorkspace.History.PushNewMemento(ha);
                                }

                                AppWorkspace.Update();
                                returnVal = true;
                            }
                            else
                            {
                                Utility.GCFullCollect();
                            }
                        }
                    } // using
                } // using
            }

            finally
            {
                AppWorkspace.ActiveDocumentWorkspace.EnableOutlineAnimation = true;

                if (resetDirtyValue)
                {
                    AppWorkspace.ActiveDocumentWorkspace.Document.Dirty = oldDirtyValue;
                }
            }

            AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBarAsync();
            return returnVal;
        }
Exemple #16
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);
        }
Exemple #17
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (mouseDown)
            {
                OnMouseMove(e);
                mouseDown = false;

                if (savedRects.Count > 0)
                {
                    Rectangle[] savedScans = this.savedRects.ToArray();
                    PdnRegion saveMeRegion = Utility.RectanglesToRegion(savedScans);

                    HistoryMemento ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, 
                        ActiveLayerIndex, saveMeRegion, ScratchSurface);

                    HistoryStack.PushNewMemento(ha);
                    saveMeRegion.Dispose();
                    this.savedRects.Clear();
                    ClearSavedMemory();
                }

                tracePoints = null;
            }
        }
Exemple #18
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;
        }