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; } }
protected override HistoryMemento OnPostRender(IHistoryWorkspace historyWorkspace) { HistoryMemento memento = base.OnPostRender(historyWorkspace); historyWorkspace.Selection.Reset(); return(memento); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if (layer1Index < 0 || layer1Index >= historyWorkspace.Document.Layers.Count || layer2Index < 0 || layer2Index >= historyWorkspace.Document.Layers.Count) { throw new ArgumentOutOfRangeException("layer1Index = " + this.layer1Index + ", layer2Index = " + layer2Index + ", expected [0," + historyWorkspace.Document.Layers.Count + ")"); } SwapLayerHistoryMemento slhm = new SwapLayerHistoryMemento( StaticName, StaticImage, historyWorkspace, layer1Index, layer2Index); Layer layer1 = historyWorkspace.Document.Layers.GetAt(layer1Index); Layer layer2 = historyWorkspace.Document.Layers.GetAt(layer2Index); EnterCriticalRegion(); historyWorkspace.Document.Layers[layer1Index] = layer2; historyWorkspace.Document.Layers[layer2Index] = layer1; layer1.Invalidate(); layer2.Invalidate(); return slhm; }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if (this.layerIndex < 0 || this.layerIndex >= historyWorkspace.Document.Layers.Count) { throw new ArgumentOutOfRangeException("layerIndex = " + layerIndex + ", expected [0, " + historyWorkspace.Document.Layers.Count + ")"); } Layer newLayer = null; newLayer = (Layer)historyWorkspace.ActiveLayer.Clone(); newLayer.IsBackground = false; int newIndex = 1 + this.layerIndex; HistoryMemento ha = new NewLayerHistoryMemento( StaticName, StaticImage, historyWorkspace, newIndex); EnterCriticalRegion(); historyWorkspace.Document.Layers.Insert(newIndex, newLayer); newLayer.Invalidate(); return(ha); }
public DeleteLayerHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, Layer deleteMe) : base(name, image) { this.historyWorkspace = historyWorkspace; this.index = historyWorkspace.Document.Layers.IndexOf(deleteMe); this.Data = new DeleteLayerHistoryMementoData(deleteMe); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if (!this.QueryCanExecute(historyWorkspace)) { return(null); } HistoryMemento memento = this.OnPreRender(historyWorkspace); int activeLayerIndex = historyWorkspace.ActiveLayerIndex; BitmapLayer activeLayer = (BitmapLayer)historyWorkspace.ActiveLayer; RectInt32 num2 = activeLayer.Bounds(); RectDouble bounds = historyWorkspace.Selection.GetCachedClippingMask().Bounds; IRenderer <ColorAlpha8> cachedClippingMaskRenderer = historyWorkspace.Selection.GetCachedClippingMaskRenderer(historyWorkspace.ToolSettings.Selection.RenderingQuality.Value); IEnumerable <IMaskedRenderer <ColorBgra, ColorAlpha8> > contentRenderers = this.OnCreateContentRenderers(historyWorkspace, num2.Width, num2.Height); ContentBlendMode contentBlendMode = this.GetContentBlendMode(); ContentRendererBgra renderer = new ContentRendererBgra(activeLayer.Surface, contentBlendMode, contentRenderers, cachedClippingMaskRenderer); base.EnterCriticalRegion(); HistoryMemento memento2 = new ApplyRendererToBitmapLayerHistoryFunction(this.HistoryMementoName, this.HistoryMementoImage, activeLayerIndex, renderer, bounds.Int32Bound, 4, 0x7d0, ActionFlags.None).Execute(historyWorkspace); HistoryMemento memento3 = this.OnPostRender(historyWorkspace); HistoryMemento[] items = new HistoryMemento[] { memento, memento2, memento3 }; HistoryMemento[] actions = ArrayUtil.Infer <HistoryMemento>(items).WhereNotNull <HistoryMemento>().ToArrayEx <HistoryMemento>(); if (actions.Length == 0) { return(null); } return(new CompoundHistoryMemento(this.HistoryMementoName, this.HistoryMementoImage, actions)); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if ((this.layerIndex < 1) || (this.layerIndex >= historyWorkspace.Document.Layers.Count)) { object[] objArray1 = new object[] { "layerIndex must be greater than or equal to 1, and a valid layer index. layerIndex=", this.layerIndex, ", allowableRange=[0,", historyWorkspace.Document.Layers.Count, ")" }; throw new ArgumentException(string.Concat(objArray1)); } int layerIndex = this.layerIndex - 1; RectInt32 rect = historyWorkspace.Document.Bounds(); GeometryList list = new GeometryList(); list.AddRect(rect); RectInt32[] changedRegion = list.EnumerateInteriorScans().ToArrayEx <RectInt32>(); BitmapHistoryMemento memento = new BitmapHistoryMemento(null, null, historyWorkspace, layerIndex, changedRegion); BitmapLayer layer = (BitmapLayer)historyWorkspace.Document.Layers[this.layerIndex]; BitmapLayer layer2 = (BitmapLayer)historyWorkspace.Document.Layers[layerIndex]; RenderArgs args = new RenderArgs(layer2.Surface); base.EnterCriticalRegion(); foreach (RectInt32 num4 in changedRegion) { layer.Render(args, num4.ToGdipRectangle()); } layer2.Invalidate(); args.Dispose(); args = null; list = null; HistoryMemento memento2 = new DeleteLayerFunction(this.layerIndex).Execute(historyWorkspace); return(new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { memento, memento2 })); }
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); }
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); }
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 BitmapHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex, IEnumerable <RectInt32> changedRegion, Surface copyFromThisSurface) : base(name, image) { RectInt32[] scans = changedRegion.ToArrayEx <RectInt32>(); this.historyWorkspace = historyWorkspace; this.layerIndex = layerIndex; this.tempFileName = FileSystem.GetTempFileName(); FileStream output = null; try { output = FileSystem.OpenStreamingFile(this.tempFileName, FileAccess.Write); SaveSurfaceRegion(output, copyFromThisSurface, scans); } finally { if (output != null) { output.Dispose(); output = null; } } this.tempFileHandle = new DeleteFileOnFree(this.tempFileName); BitmapHistoryMementoData data = new BitmapHistoryMementoData(scans); base.Data = data; }
public LayerPropertyHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex) : base(name, image) { this.historyWorkspace = historyWorkspace; this.layerIndex = layerIndex; this.properties = ((Layer)this.historyWorkspace.Document.Layers[layerIndex]).SaveProperties(); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if (this.layerIndex < 0 || this.layerIndex >= historyWorkspace.Document.Layers.Count) { throw new ArgumentOutOfRangeException("layerIndex = " + layerIndex + ", expected [0, " + historyWorkspace.Document.Layers.Count + ")"); } Layer newLayer = null; newLayer = (Layer)historyWorkspace.ActiveLayer.Clone(); newLayer.IsBackground = false; int newIndex = 1 + this.layerIndex; HistoryMemento ha = new NewLayerHistoryMemento( StaticName, StaticImage, historyWorkspace, newIndex); EnterCriticalRegion(); historyWorkspace.Document.Layers.Insert(newIndex, newLayer); newLayer.Invalidate(); return ha; }
public FlipLayerHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex, FlipType flipType) : base(name, image) { this.historyWorkspace = historyWorkspace; this.layerIndex = layerIndex; this.flipType = flipType; }
public BitmapHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex, PdnRegion changedRegion, Surface copyFromThisSurface) : base(name, image) { this.historyWorkspace = historyWorkspace; this.layerIndex = layerIndex; PdnRegion region = changedRegion.Clone(); this.tempFileName = FileSystem.GetTempFileName(); FileStream outputStream = null; try { outputStream = FileSystem.OpenStreamingFile(this.tempFileName, FileAccess.Write); SaveSurfaceRegion(outputStream, copyFromThisSurface, region); } finally { if (outputStream != null) { outputStream.Dispose(); outputStream = null; } } this.tempFileHandle = new DeleteFileOnFree(this.tempFileName); BitmapHistoryMementoData data = new BitmapHistoryMementoData(null, region); this.Data = data; }
public ReplaceDocumentHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, Document document) : base(name, image) { this.historyWorkspace = historyWorkspace; ReplaceDocumentHistoryMementoData data = new ReplaceDocumentHistoryMementoData(document); base.Data = data; }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if (layer1Index < 0 || layer1Index >= historyWorkspace.Document.Layers.Count || layer2Index < 0 || layer2Index >= historyWorkspace.Document.Layers.Count) { throw new ArgumentOutOfRangeException("layer1Index = " + this.layer1Index + ", layer2Index = " + layer2Index + ", expected [0," + historyWorkspace.Document.Layers.Count + ")"); } SwapLayerHistoryMemento slhm = new SwapLayerHistoryMemento( StaticName, StaticImage, historyWorkspace, layer1Index, layer2Index); Layer layer1 = historyWorkspace.Document.Layers.GetAt(layer1Index); Layer layer2 = historyWorkspace.Document.Layers.GetAt(layer2Index); EnterCriticalRegion(); historyWorkspace.Document.Layers[layer1Index] = layer2; historyWorkspace.Document.Layers[layer2Index] = layer1; layer1.Invalidate(); layer2.Invalidate(); return(slhm); }
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; }
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; }
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); } }
public BitmapHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex, Guid poMaskedSurfaceRef) : base(name, image) { this.layerIndex = layerIndex; this.historyWorkspace = historyWorkspace; this.poMaskedSurfaceRef = poMaskedSurfaceRef; }
protected override HistoryMemento OnPreRender(IHistoryWorkspace historyWorkspace) { HistoryMemento memento = base.OnPreRender(historyWorkspace); SelectionHistoryMemento memento2 = new SelectionHistoryMemento(string.Empty, null, historyWorkspace); HistoryMemento[] mementos = new HistoryMemento[] { memento, memento2 }; return(HistoryMemento.Combine(this.HistoryMementoName, this.HistoryMementoImage, mementos)); }
public ReplaceDocumentHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace) : base(name, image) { this.historyWorkspace = historyWorkspace; ReplaceDocumentHistoryMementoData data = new ReplaceDocumentHistoryMementoData(this.historyWorkspace.Document); this.Data = data; }
public MetaDataHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace) : base(name, image) { this.historyWorkspace = historyWorkspace; Document document = new Document(1, 1); // we need some place to store the metadata... document.ReplaceMetaDataFrom(historyWorkspace.Document); MetaDataHistoryMementoData data = new MetaDataHistoryMementoData(document); this.Data = data; }
public MoveLayerHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int oldIndex, int newIndex) : base(name, image) { this.historyWorkspace = historyWorkspace; this.oldIndex = oldIndex; this.newIndex = newIndex; if (((this.oldIndex < 0) || (this.newIndex < 0)) || ((this.oldIndex >= this.historyWorkspace.Document.Layers.Count) || (this.newIndex >= this.historyWorkspace.Document.Layers.Count))) { throw new ArgumentOutOfRangeException("[old|new]Index", "out of range"); } }
public MetadataHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace) : base(name, image) { this.historyWorkspace = historyWorkspace; Document document = new Document(1, 1); document.ReplaceMetadataFrom(historyWorkspace.Document); MetadataHistoryMementoData data = new MetadataHistoryMementoData(document); base.Data = data; }
public SwapLayerHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex1, int layerIndex2) : base(name, image) { this.historyWorkspace = historyWorkspace; this.layerIndex1 = layerIndex1; this.layerIndex2 = layerIndex2; if (((this.layerIndex1 < 0) || (this.layerIndex2 < 0)) || ((this.layerIndex1 >= this.historyWorkspace.Document.Layers.Count) || (this.layerIndex2 >= this.historyWorkspace.Document.Layers.Count))) { throw new ArgumentOutOfRangeException("layerIndex[1|2]", "out of range"); } }
public HistoryMemento Execute(IHistoryWorkspace historyWorkspace) { HistoryMemento memento = null; Exception exception = null; HistoryMemento memento2; try { try { if (this.executed) { ExceptionUtil.ThrowInvalidOperationException("Already executed this HistoryFunction"); } this.executed = true; memento = this.OnExecute(historyWorkspace); memento2 = memento; } catch (ArgumentOutOfRangeException exception2) { if (this.criticalRegionCount > 0) { throw; } throw new HistoryFunctionNonFatalException(null, exception2); } catch (OutOfMemoryException exception3) { if (this.criticalRegionCount > 0) { throw; } throw new HistoryFunctionNonFatalException(null, exception3); } } catch (Exception exception4) { if (!this.IsAsync) { throw; } exception = exception4; memento2 = memento; } finally { if (this.IsAsync) { this.OnFinished(memento, exception); } } return(memento2); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { GeometryList cachedClippingMask = historyWorkspace.Selection.GetCachedClippingMask(); if (historyWorkspace.Selection.IsEmpty || (cachedClippingMask.Bounds.Area < 1.0)) { return(null); } Document document = historyWorkspace.Document; List <HistoryMemento> mementos = new List <HistoryMemento>(document.Layers.Count); RectInt32 b = cachedClippingMask.Bounds.GetInt32Bound(1E-05); RectInt32 sourceRect = RectInt32.Intersect(document.Bounds(), b); Document document2 = new Document(sourceRect.Width, sourceRect.Height); document2.ReplaceMetadataFrom(document); RectInt32 rect = new RectInt32(0, 0, sourceRect.Width, sourceRect.Height); IRenderer <ColorAlpha8> cachedClippingMaskRenderer = historyWorkspace.Selection.GetCachedClippingMaskRenderer(historyWorkspace.ToolSettings.Selection.RenderingQuality.Value); IRenderer <ColorAlpha8> newClipMaskRenderer = new ClippedRenderer <ColorAlpha8>(cachedClippingMaskRenderer, sourceRect); SelectionHistoryMemento item = new SelectionHistoryMemento(null, null, historyWorkspace); mementos.Add(item); base.EnterCriticalRegion(); int count = document.Layers.Count; while (document.Layers.Count > 0) { BitmapLayer layer = (BitmapLayer)document.Layers[0]; Surface croppedSurface = layer.Surface.CreateWindow(sourceRect); BitmapLayer newLayer = RetryManager.RunMemorySensitiveOperation <BitmapLayer>(() => new BitmapLayer(croppedSurface)); newLayer.LoadProperties(layer.SaveProperties()); HistoryMemento deleteLayerMemento = new DeleteLayerFunction(0).Execute(historyWorkspace); mementos.Add(deleteLayerMemento); Task task = Task.Factory.StartNew(delegate { deleteLayerMemento.Flush(); }, TaskCreationOptions.LongRunning); Parallel.ForEach <RectInt32>(rect.GetTiles(TilingStrategy.Tiles, 7), delegate(RectInt32 newTileRect) { ISurface <ColorBgra> surface = newLayer.Surface.CreateWindow(newTileRect); IRenderer <ColorAlpha8> mask = new ClippedRenderer <ColorAlpha8>(newClipMaskRenderer, newTileRect); surface.MultiplyAlphaChannel(mask); }); document2.Layers.Add(newLayer); task.Wait(); if (document2.Layers.Count > count) { ExceptionUtil.ThrowInternalErrorException("newDocument.Layers.Count > oldLayerCount"); } } ReplaceDocumentHistoryMemento memento2 = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace); mementos.Add(memento2); historyWorkspace.Document = document2; return(HistoryMemento.Combine(HistoryMementoName, HistoryMementoImage, mementos)); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if (historyWorkspace.Selection.IsEmpty) { return(null); } SelectionHistoryMemento memento = new SelectionHistoryMemento(StaticName, StaticImage, historyWorkspace); base.EnterCriticalRegion(); historyWorkspace.Selection.Reset(); return(memento); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if ((this.layerIndex < 0) || (this.layerIndex >= historyWorkspace.Document.Layers.Count)) { object[] objArray1 = new object[] { "layerIndex = ", this.layerIndex, ", expected [0, ", historyWorkspace.Document.Layers.Count, ")" }; throw new ArgumentOutOfRangeException(string.Concat(objArray1)); } HistoryMemento memento = new DeleteLayerHistoryMemento(StaticName, StaticImage, historyWorkspace, historyWorkspace.Document.Layers.GetAt(this.layerIndex)); base.EnterCriticalRegion(); historyWorkspace.Document.Layers.RemoveAt(this.layerIndex); return(memento); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { SelectionHistoryMemento memento = new SelectionHistoryMemento(StaticName, StaticImage, historyWorkspace); base.EnterCriticalRegion(); using (historyWorkspace.Selection.UseChangeScope()) { historyWorkspace.Selection.Reset(); historyWorkspace.Selection.SetContinuation(historyWorkspace.Document.Bounds(), SelectionCombineMode.Replace); historyWorkspace.Selection.CommitContinuation(); } return(memento); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { BitmapLayer layer = RetryManager.RunMemorySensitiveOperation <BitmapLayer>(() => new BitmapLayer(historyWorkspace.Document.Width, historyWorkspace.Document.Height)); string format = PdnResources.GetString("AddNewBlankLayer.LayerName.Format"); layer.Name = string.Format(format, (1 + historyWorkspace.Document.Layers.Count).ToString()); int layerIndex = historyWorkspace.ActiveLayerIndex + 1; NewLayerHistoryMemento memento = new NewLayerHistoryMemento(PdnResources.GetString("AddNewBlankLayer.HistoryMementoName"), PdnResources.GetImageResource("Icons.MenuLayersAddNewLayerIcon.png"), historyWorkspace, layerIndex); base.EnterCriticalRegion(); historyWorkspace.Document.Layers.Insert(layerIndex, layer); return(memento); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if (((this.oldIndex < 0) || (this.oldIndex >= historyWorkspace.Document.Layers.Count)) || ((this.newIndex < 0) || (this.newIndex >= historyWorkspace.Document.Layers.Count))) { object[] objArray1 = new object[] { "oldIndex = ", this.oldIndex, ", newIndex = ", this.newIndex, ", expected [0,", historyWorkspace.Document.Layers.Count, ")" }; throw new ArgumentOutOfRangeException(string.Concat(objArray1)); } MoveLayerHistoryMemento memento = new MoveLayerHistoryMemento(StaticName, StaticImage, historyWorkspace, this.oldIndex, this.newIndex); base.EnterCriticalRegion(); historyWorkspace.Document.Layers.Move(this.oldIndex, this.newIndex); historyWorkspace.Document.Invalidate(); return(memento); }
public SwapLayerHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex1, int layerIndex2) : base(name, image) { this.historyWorkspace = historyWorkspace; this.layerIndex1 = layerIndex1; this.layerIndex2 = layerIndex2; if (this.layerIndex1 < 0 || this.layerIndex2 < 0 || this.layerIndex1 >= this.historyWorkspace.Document.Layers.Count || this.layerIndex2 >= this.historyWorkspace.Document.Layers.Count) { throw new ArgumentOutOfRangeException("layerIndex[1|2]", "out of range"); } }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if (this.layerIndex < 0 || this.layerIndex >= historyWorkspace.Document.Layers.Count) { throw new ArgumentOutOfRangeException("layerIndex = " + this.layerIndex + ", expected [0, " + historyWorkspace.Document.Layers.Count + ")"); } HistoryMemento hm = new DeleteLayerHistoryMemento(StaticName, StaticImage, historyWorkspace, historyWorkspace.Document.Layers.GetAt(this.layerIndex)); EnterCriticalRegion(); historyWorkspace.Document.Layers.RemoveAt(this.layerIndex); return(hm); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if (this.layerIndex < 0 || this.layerIndex >= historyWorkspace.Document.Layers.Count) { throw new ArgumentOutOfRangeException("layerIndex = " + this.layerIndex + ", expected [0, " + historyWorkspace.Document.Layers.Count + ")"); } HistoryMemento hm = new DeleteLayerHistoryMemento(StaticName, StaticImage, historyWorkspace, historyWorkspace.Document.Layers.GetAt(this.layerIndex)); EnterCriticalRegion(); historyWorkspace.Document.Layers.RemoveAt(this.layerIndex); return hm; }
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; } }
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) { 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) { BitmapLayer newLayer = null; newLayer = new BitmapLayer(historyWorkspace.Document.Width, historyWorkspace.Document.Height); string newLayerNameFormat = PdnResources.GetString("AddNewBlankLayer.LayerName.Format"); newLayer.Name = string.Format(newLayerNameFormat, (1 + historyWorkspace.Document.Layers.Count).ToString()); NewLayerHistoryMemento ha = new NewLayerHistoryMemento( PdnResources.GetString("AddNewBlankLayer.HistoryMementoName"), ImageResource.Get("Icons.MenuLayersAddNewLayerIcon.png"), historyWorkspace, historyWorkspace.Document.Layers.Count); EnterCriticalRegion(); historyWorkspace.Document.Layers.Add(newLayer); return ha; }
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 (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; }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { List<HistoryMemento> actions = new List<HistoryMemento>(); if (!historyWorkspace.Selection.IsEmpty) { DeselectFunction da = new DeselectFunction(); EnterCriticalRegion(); HistoryMemento hm = da.Execute(historyWorkspace); actions.Add(hm); } int count = historyWorkspace.Document.Layers.Count; for (int i = 0; i < count; ++i) { HistoryMemento memento = new FlipLayerHistoryMemento(this.historyName, undoImage, historyWorkspace, i, flipType); EnterCriticalRegion(); HistoryMemento mementoToAdd = memento.PerformUndo(); actions.Add(mementoToAdd); } return new CompoundHistoryMemento(this.historyName, undoImage, actions); }
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 abstract HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace);
public BitmapHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex, IrregularSurface saved) : this(name, image, historyWorkspace, layerIndex, saved, false) { }
public BitmapHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex, PdnRegion changedRegion) : this(name, image, historyWorkspace, layerIndex, changedRegion, ((BitmapLayer)historyWorkspace.Document.Layers[layerIndex]).Surface) { }
public BitmapHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex, IrregularSurface saved, bool takeOwnershipOfSaved) : base(name, image) { this.historyWorkspace = historyWorkspace; this.layerIndex = layerIndex; IrregularSurface iss; if (takeOwnershipOfSaved) { iss = saved; } else { iss = (IrregularSurface)saved.Clone(); } BitmapHistoryMementoData data = new BitmapHistoryMementoData(iss, null); this.Data = data; }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { int newWidth; int newHeight; // Get new width and Height switch (rotation) { case RotateType.Clockwise90: case RotateType.Clockwise270: case RotateType.CounterClockwise90: case RotateType.CounterClockwise270: newWidth = historyWorkspace.Document.Height; newHeight = historyWorkspace.Document.Width; break; case RotateType.Clockwise180: case RotateType.CounterClockwise180: 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.Clockwise180: iconResName = "Icons.MenuImageRotate180CWIcon.png"; suffix = PdnResources.GetString("RotateAction.180CW"); break; case RotateType.Clockwise270: iconResName = "Icons.MenuImageRotate270CWIcon.png"; suffix = PdnResources.GetString("RotateAction.270CW"); break; case RotateType.Clockwise90: iconResName = "Icons.MenuImageRotate90CWIcon.png"; suffix = PdnResources.GetString("RotateAction.90CW"); break; case RotateType.CounterClockwise180: iconResName = "Icons.MenuImageRotate180CCWIcon.png"; suffix = PdnResources.GetString("RotateAction.180CCW"); break; case RotateType.CounterClockwise270: iconResName = "Icons.MenuImageRotate270CCWIcon.png"; suffix = PdnResources.GetString("RotateAction.270CCW"); 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 = ImageResource.Get(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; }
public SelectionHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace) : base(name, image) { this.historyWorkspace = historyWorkspace; this.savedSelectionData = this.historyWorkspace.Selection.Save(); }
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; } }
public NewLayerHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex) : base(name, image) { this.historyWorkspace = historyWorkspace; this.layerIndex = layerIndex; }