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; } }
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); }
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; } }
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); }
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; }
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)) { 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 })); }
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")); }
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(); } } }
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); }
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(); } } }
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); }
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; }
/// <summary> /// Provided as a special entry point so that Paste can work well. /// </summary> /// <param name="surface">What you want to paste.</param> /// <param name="offset">Where you want to paste it.</param> public void PasteMouseDown(SurfaceForClipboard sfc, Point offset) { if (this.context.lifted) { Drop(); } MaskedSurface pixels = sfc.MaskedSurface; PdnGraphicsPath pastePath = pixels.CreatePath(); PdnRegion pasteRegion = new PdnRegion(pastePath); PdnRegion simplifiedPasteRegion = Utility.SimplifyAndInflateRegion(pasteRegion); HistoryMemento bitmapAction = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, ActiveLayerIndex, simplifiedPasteRegion); // SLOW (110ms) this.currentHistoryMementos.Add(bitmapAction); PushContextHistoryMemento(); this.context.seriesGuid = Guid.NewGuid(); this.context.currentMode = Mode.Translate; this.context.startEdge = Edge.None; this.context.startAngle = 0.0f; this.ourContext.LiftedPixels = pixels; this.context.lifted = true; this.context.liftTransform = new Matrix(); this.context.liftTransform.Reset(); this.context.deltaTransform = new Matrix(); this.context.deltaTransform.Reset(); this.context.offset = new Point(0, 0); bool oldDD = this.dontDrop; this.dontDrop = true; SelectionHistoryMemento sha = new SelectionHistoryMemento(null, null, DocumentWorkspace); this.currentHistoryMementos.Add(sha); Selection.PerformChanging(); Selection.Reset(); Selection.SetContinuation(pastePath, CombineMode.Replace, true); pastePath = null; Selection.CommitContinuation(); Selection.PerformChanged(); PushContextHistoryMemento(); this.context.liftedBounds = Selection.GetBoundsF(false); this.context.startBounds = this.context.liftedBounds; this.context.baseTransform = new Matrix(); this.context.baseTransform.Reset(); this.tracking = true; this.dontDrop = oldDD; this.didPaste = true; this.tracking = true; DestroyNubs(); PositionNubs(this.context.currentMode); // we use the value 70,000 to simulate mouse input because that's guaranteed to be out of bounds of where // the mouse can actually be -- PDN is limited to 65536 x 65536 images by design MouseEventArgs mea1 = new MouseEventArgs(MouseButtons.Left, 0, 70000, 70000, 0); MouseEventArgs mea2 = new MouseEventArgs(MouseButtons.Left, 0, 70000 + offset.X, 70000 + offset.Y, 0); this.context.startMouseXY = new Point(70000, 70000); OnMouseDown(mea1); OnMouseMove(mea2); // SLOW (200ms) OnMouseUp(mea2); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { historyWorkspace.VerifyAccess(); BitmapLayer layer = (BitmapLayer)historyWorkspace.Document.Layers[this.layerIndex]; Surface layerSurface = layer.Surface; TileMathHelper tileMathHelper = new TileMathHelper(layerSurface.Width, layerSurface.Height, this.rendererTileEdgeLog2); TileMathHelper tileGroupMathHelper = new TileMathHelper(layerSurface.Width, layerSurface.Height, this.rendererTileEdgeLog2 + 3); HistoryMemento actionHM = null; ManualResetEvent taskFinishedEvent = new ManualResetEvent(false); ThreadTask <Unit> commitTask = historyWorkspace.TaskManager.StartNewThreadTask(delegate(Task task) { SegmentedList <RectInt32> list = tileGroupMathHelper.EnumerateTilesClippedToSourceRect(this.rendererClipRect).ToSegmentedList <RectInt32>(); ListUtil.FisherYatesShuffle <RectInt32>(list); ConcurrentQueue <ISurface <ColorBgra> > queue = new ConcurrentQueue <ISurface <ColorBgra> >(); ConcurrentQueue <RectInt32> changedTiles = new ConcurrentQueue <RectInt32>(); ConcurrentQueue <TupleStruct <RectInt32, ISurface <ColorBgra> > > changedTileGroups = new ConcurrentQueue <TupleStruct <RectInt32, ISurface <ColorBgra> > >(); double progressIncrement = 1.0 / ((double)Math.Max(1, list.Count)); task.Progress = 0.0; Work.ParallelForEach <RectInt32>(WaitType.Blocking, list, delegate(RectInt32 tileGroupRect) { ISurface <ColorBgra> dst = RetryManager.RunMemorySensitiveOperation <ISurfaceRef <ColorBgra> >(() => SurfaceAllocator.Bgra.Allocate <ColorBgra>(tileGroupRect.Size, AllocationOptions.ZeroFillNotRequired)); this.renderer.Render(dst, tileGroupRect.Location); bool flag = false; foreach (RectInt32 num in tileMathHelper.EnumerateTilesClippedToSourceRect(tileGroupRect)) { RectInt32 bounds = RectInt32.Offset(num, -tileGroupRect.Location); using (ISurface <ColorBgra> surface2 = layerSurface.CreateWindow(num)) { using (ISurface <ColorBgra> surface3 = dst.CreateWindow <ColorBgra>(bounds)) { if (!SurfaceBgraUtil.ArePixelsEqual(surface2, surface3)) { flag = true; changedTiles.Enqueue(num); } } } } if (flag) { changedTileGroups.Enqueue(TupleStruct.Create <RectInt32, ISurface <ColorBgra> >(tileGroupRect, dst)); } else { DisposableUtil.Free <ISurface <ColorBgra> >(ref dst); } task.IncrementProgressBy(progressIncrement); }, WorkItemQueuePriority.Normal, null); task.Progress = null; if (changedTiles.Count == 0) { actionHM = null; } else { SegmentedList <RectInt32> scans = new SegmentedList <RectInt32>(changedTiles.Count, 7); scans.AddRange(changedTiles); ScansHelpers.SortScansByTopLeft(scans); ScansHelpers.ConsolidateSortedScansInPlace(scans); actionHM = new BitmapHistoryMemento(this.historyMementoName, this.historyMementoImage, historyWorkspace, this.layerIndex, scans); this.EnterCriticalRegion(); Work.ParallelForEach <TupleStruct <RectInt32, ISurface <ColorBgra> > >(WaitType.Blocking, changedTileGroups, delegate(TupleStruct <RectInt32, ISurface <ColorBgra> > tileInfo) { using (ISurface <ColorBgra> surface = layerSurface.CreateWindow(tileInfo.Item1)) { tileInfo.Item2.Render(surface, PointInt32.Zero); } tileInfo.Item2.Dispose(); }, WorkItemQueuePriority.Normal, null); foreach (RectInt32 num in scans) { layer.Invalidate(num); } } }, ApartmentState.MTA); commitTask.ResultAsync <Unit>().Receive(delegate(Result <Unit> r) { taskFinishedEvent.Set(); }).Observe(); if (!taskFinishedEvent.WaitOne(this.delayUntilProgressDialogMs)) { string headerText = PdnResources.GetString("ApplyRendererToBitmapLayerHistoryFunction.ProgressDialog.HeaderText"); string headerTextFormat = PdnResources.GetString("ApplyRendererToBitmapLayerHistoryFunction.ProgressDialog.HeaderText.Format"); using (TaskProgressDialog progressDialog = new TaskProgressDialog()) { Action updateHeaderText = delegate { progressDialog.VerifyAccess(); if (!progressDialog.IsDisposed) { string text1; double?progress = commitTask.Progress; if (!progress.HasValue) { text1 = headerText; } else { text1 = string.Format(headerTextFormat, (progress.Value * 100.0).ToString("N0")); } progressDialog.HeaderText = text1; } }; progressDialog.Text = this.historyMementoName; progressDialog.Icon = this.historyMementoImage.Reference.ToIcon(); progressDialog.CloseOnFinished = true; progressDialog.ShowCancelButton = false; progressDialog.Task = commitTask; updateHeaderText(); commitTask.ProgressChanged += delegate(object s, ValueEventArgs <double?> e) { PdnSynchronizationContext.Instance.EnsurePosted(updateHeaderText); }; progressDialog.ShowDialog(historyWorkspace.Window); } } if (!commitTask.TaskResult.IsError) { return(actionHM); } if (commitTask.TaskResult.Error is OutOfMemoryException) { throw new OutOfMemoryException(null, commitTask.TaskResult.Error); } throw new AggregateException(null, commitTask.TaskResult.Error); }