public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace) { AnchorEdge initialAnchor = AppSettings.Instance.Workspace.LastCanvasSizeAnchorEdge.Value; Document document = ResizeDocument(documentWorkspace, initialAnchor, documentWorkspace.ToolSettings.SecondaryColor.Value, true, true); if (document != null) { using (new PushNullToolMode(documentWorkspace)) { List <HistoryMemento> actions = new List <HistoryMemento>(2); SelectionHistoryMemento item = new SelectionHistoryMemento(null, null, documentWorkspace); actions.Add(item); if (document.DpuUnit != MeasurementUnit.Pixel) { AppSettings.Instance.Workspace.LastNonPixelUnits.Value = document.DpuUnit; if (documentWorkspace.AppWorkspace.Units != MeasurementUnit.Pixel) { documentWorkspace.AppWorkspace.Units = document.DpuUnit; } } ReplaceDocumentHistoryMemento memento2 = new ReplaceDocumentHistoryMemento(null, null, documentWorkspace); actions.Add(memento2); documentWorkspace.Document = document; return(new CompoundHistoryMemento(StaticName, StaticImage, actions)); } } return(null); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { SelectionData state = null; SegmentedList <HistoryMemento> actions = new SegmentedList <HistoryMemento>(); if (!historyWorkspace.Selection.IsEmpty) { state = historyWorkspace.Selection.Save(); HistoryMemento memento3 = new DeselectFunction().Execute(historyWorkspace); actions.Add(memento3); } ReplaceDocumentHistoryMemento item = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace); actions.Add(item); CompoundHistoryMemento memento2 = new CompoundHistoryMemento(StaticName, PdnResources.GetImageResource("Icons.MenuImageFlattenIcon.png"), actions); Document document = RetryManager.RunMemorySensitiveOperation <Document>(() => historyWorkspace.Document.Flatten()); base.EnterCriticalRegion(); historyWorkspace.Document = document; if (state != null) { SelectionHistoryMemento newHA = new SelectionHistoryMemento(null, null, historyWorkspace); historyWorkspace.Selection.Restore(state); memento2.AddMemento(newHA); } return(memento2); }
public override HistoryMemento 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 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)); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (tracking) { moveOriginMode = true; lastXY = new Point(e.X, e.Y); OnMouseMove(e); } else if ((e.Button & MouseButtons.Left) == MouseButtons.Left || (e.Button & MouseButtons.Right) == MouseButtons.Right) { tracking = true; hasMoved = false; startTime = DateTime.Now; tracePoints = new List <Point>(); tracePoints.Add(new Point(e.X, e.Y)); undoAction = new SelectionHistoryMemento("sentinel", this.Image, DocumentWorkspace); wasNotEmpty = !Selection.IsEmpty; // if the user is holding down the control key then we don't want to reset the path, merely append to it if ((ModifierKeys & Keys.Control) == Keys.Control) { append = true; if ((e.Button & MouseButtons.Right) == MouseButtons.Right) { this.combineMode = CombineMode.Xor; } else { this.combineMode = CombineMode.Union; } Selection.ResetContinuation(); } else if ((e.Button & MouseButtons.Right) == MouseButtons.Right) { append = true; this.combineMode = CombineMode.Exclude; Selection.ResetContinuation(); } else { append = false; this.combineMode = CombineMode.Replace; Selection.Reset(); } } }
protected override void OnFillRegionComputed(Point[][] polygonSet) { SelectionHistoryMemento undoAction = new SelectionHistoryMemento(this.Name, this.Image, this.DocumentWorkspace); Selection.PerformChanging(); Selection.SetContinuation(polygonSet, this.combineMode); Selection.CommitContinuation(); Selection.PerformChanged(); HistoryStack.PushNewMemento(undoAction); }
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")); }
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); }
private void OnUIGestureBegin(object sender, MouseEventArgs e) { using (this.onUIGestureRegion.UseEnterScope()) { UIElement source = e.Source as UIElement; if (source != null) { PointDouble position = e.GetPosition(this.UI); this.gestureBeginCanvasPt = position; if ((this.State == TransactedToolState.Drawing) && !this.mouseInputDrawingAgent.IsActive) { this.RequestCancelDrawing(); base.VerifyState(TransactedToolState.Idle); } if ((this.State == TransactedToolState.Editing) && !this.mouseInputEditingAgent.IsActive) { this.RequestEndEditing(); base.VerifyState(TransactedToolState.Dirty); } FloodFillToolHandleType handleType = FloodFillToolUIBase <MagicWandTool, MagicWandToolChanges> .GetHandleType(source); switch (handleType) { case FloodFillToolHandleType.Canvas: if (this.State == TransactedToolState.Dirty) { base.CommitChanges(); base.VerifyState(TransactedToolState.Idle); } if (this.State == TransactedToolState.Idle) { SelectionHistoryMemento selectionHistoryMementoAndPrepareForBeginDrawing = base.GetSelectionHistoryMementoAndPrepareForBeginDrawing(); GeometryList cachedGeometryList = base.Selection.GetCachedGeometryList(); SelectionCombineMode? selectionCombineModeOverride = base.GetSelectionCombineModeOverride(); FloodMode? floodModeOverride = ((base.PresentationSource.PrimaryKeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) ? ((FloodMode?)1) : null; MagicWandToolChanges initialChanges = new MagicWandToolChanges(base.DrawingSettingsValues, position, selectionCombineModeOverride, floodModeOverride, cachedGeometryList); base.BeginDrawing(this.mouseInputDrawingAgent, initialChanges, selectionHistoryMementoAndPrepareForBeginDrawing); } return; case FloodFillToolHandleType.Origin: case FloodFillToolHandleType.Move: if (this.State == TransactedToolState.Dirty) { base.BeginEditing(this.mouseInputEditingAgent); } return; } throw ExceptionUtil.InvalidEnumArgumentException <FloodFillToolHandleType>(handleType, "sender.(MagicWandToolUI.HandleType)"); } } }
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); }
protected override void Drop() { ContextHistoryMemento cha = new ContextHistoryMemento(this.DocumentWorkspace, this.context, this.Name, this.Image); this.currentHistoryMementos.Add(cha); SelectionHistoryMemento sha = new SelectionHistoryMemento(this.Name, this.Image, this.DocumentWorkspace); this.currentHistoryMementos.Add(sha); this.context.Dispose(); this.context = new Context(); this.FlushHistoryMementos(PdnResources.GetString("MoveSelectionTool.HistoryMemento.DropSelection")); }
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); }
protected SelectionHistoryMemento GetSelectionHistoryMementoAndPrepareForBeginDrawing() { ((AsyncSelectionToolBase <TDerived, TChanges>) this).VerifyAccess <AsyncSelectionToolBase <TDerived, TChanges> >(); base.VerifyState(TransactedToolState.Idle); SelectionHistoryMemento memento = new SelectionHistoryMemento(base.Name, base.Image, base.DocumentWorkspace); using (new PresentationBasedTool <TDerived, TChanges> .AllowSelectionChangesScope((TDerived)this)) { using (base.Selection.UseChangeScope()) { if (!base.Selection.GetInterimTransform().IsIdentity) { base.Selection.CommitInterimTransform(); return(memento); } base.Selection.CommitContinuation(); } } return(memento); }
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 HistoryMemento ImportMultipleFiles(DocumentWorkspace documentWorkspace, string[] fileNames) { HistoryMemento retHA = null; List <HistoryMemento> historyMementos = new List <HistoryMemento>(); Rectangle lastLayerBounds = Rectangle.Empty; foreach (string fileName in fileNames) { HistoryMemento ha = ImportOneFile(documentWorkspace, fileName, out lastLayerBounds); if (ha != null) { historyMementos.Add(ha); } else { Rollback(historyMementos); historyMementos.Clear(); break; } } if (lastLayerBounds.Width > 0 && lastLayerBounds.Height > 0) { SelectionHistoryMemento sha = new SelectionHistoryMemento(null, null, documentWorkspace); historyMementos.Add(sha); documentWorkspace.Selection.PerformChanging(); documentWorkspace.Selection.Reset(); documentWorkspace.Selection.SetContinuation(lastLayerBounds, System.Drawing.Drawing2D.CombineMode.Replace); documentWorkspace.Selection.CommitContinuation(); documentWorkspace.Selection.PerformChanged(); } if (historyMementos.Count > 0) { HistoryMemento[] haArray = historyMementos.ToArray(); retHA = new CompoundHistoryMemento(StaticName, StaticImage, haArray); } return(retHA); }
public HistoryMemento ImportMultipleFiles(DocumentWorkspace documentWorkspace, string[] fileNames) { HistoryMemento memento = null; SegmentedList <HistoryMemento> historyMementos = new SegmentedList <HistoryMemento>(); Rectangle empty = Rectangle.Empty; foreach (string str in fileNames) { HistoryMemento item = this.ImportOneFile(documentWorkspace, str, out empty); if (item != null) { historyMementos.Add(item); } else { this.Rollback(historyMementos); historyMementos.Clear(); break; } } if ((empty.Width > 0) && (empty.Height > 0)) { SelectionHistoryMemento memento3 = new SelectionHistoryMemento(null, null, documentWorkspace); historyMementos.Add(memento3); using (documentWorkspace.Selection.UseChangeScope()) { documentWorkspace.Selection.Reset(); documentWorkspace.Selection.SetContinuation(empty.ToRectInt32(), SelectionCombineMode.Replace); documentWorkspace.Selection.CommitContinuation(); } } if (historyMementos.Count > 0) { HistoryMemento[] actions = historyMementos.ToArrayEx <HistoryMemento>(); memento = new CompoundHistoryMemento(StaticName, StaticImage, actions); } return(memento); }
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) { object savedSelection = null; List <HistoryMemento> actions = new List <HistoryMemento>(); if (!historyWorkspace.Selection.IsEmpty) { savedSelection = historyWorkspace.Selection.Save(); DeselectFunction da = new DeselectFunction(); HistoryMemento hm = da.Execute(historyWorkspace); actions.Add(hm); } ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace); actions.Add(rdha); CompoundHistoryMemento chm = new CompoundHistoryMemento( StaticName, ImageResource.Get("Icons.MenuImageFlattenIcon.png"), actions); // TODO: we can save memory here by serializing, then flattening on to an existing layer Document flat = historyWorkspace.Document.Flatten(); EnterCriticalRegion(); historyWorkspace.Document = flat; if (savedSelection != null) { SelectionHistoryMemento shm = new SelectionHistoryMemento(null, null, historyWorkspace); historyWorkspace.Selection.Restore(savedSelection); chm.PushNewAction(shm); } return(chm); }
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); } }
/// <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); }
protected override void OnMouseDown(MouseEventArgsF e) { base.OnMouseDown(e); base.Cursor = this.GetCursor(); PointDouble point = e.Point; PointDouble item = this.RoundMouseCanvasPoint(point); if (this.tracking) { this.moveOriginMode = true; this.lastXY = item; this.OnMouseMove(e); } else if (((e.Button & MouseButtons.Left) == MouseButtons.Left) || ((e.Button & MouseButtons.Right) == MouseButtons.Right)) { this.tracking = true; this.hasMoved = false; this.startTime = DateTime.Now; this.tracePoints = new SegmentedList <PointDouble>(); this.tracePoints.Add(item); this.undoAction = new SelectionHistoryMemento("sentinel", base.Image, base.DocumentWorkspace); this.wasNotEmpty = !base.Selection.IsEmpty; if (((base.ModifierKeys & Keys.Control) != Keys.None) && (e.Button == MouseButtons.Left)) { this.combineMode = SelectionCombineMode.Union; } else if (((base.ModifierKeys & Keys.Alt) != Keys.None) && (e.Button == MouseButtons.Left)) { this.combineMode = SelectionCombineMode.Exclude; } else if (((base.ModifierKeys & Keys.Control) != Keys.None) && (e.Button == MouseButtons.Right)) { this.combineMode = SelectionCombineMode.Xor; } else if (((base.ModifierKeys & Keys.Alt) != Keys.None) && (e.Button == MouseButtons.Right)) { this.combineMode = SelectionCombineMode.Intersect; } else { this.combineMode = base.ToolSettings.Selection.CombineMode.Value; } base.DocumentWorkspace.EnableSelectionOutline = false; Result <GeometryList> oldSelectionGeometryLazy0 = base.Selection.GetCachedLazyGeometryList(); this.oldSelectionGeometryLazy = oldSelectionGeometryLazy0; Work.QueueWorkItem(delegate { Result <GeometryList> oldSelectionGeometryLazy = this.oldSelectionGeometryLazy; if (oldSelectionGeometryLazy0 == oldSelectionGeometryLazy) { oldSelectionGeometryLazy.EnsureEvaluated(); } }); this.newSelection.Restore(base.Selection.Save()); switch (this.combineMode) { case SelectionCombineMode.Replace: this.append = false; base.Selection.Reset(); break; case SelectionCombineMode.Union: case SelectionCombineMode.Exclude: case SelectionCombineMode.Intersect: case SelectionCombineMode.Xor: this.append = true; base.Selection.ResetContinuation(); break; default: throw ExceptionUtil.InvalidEnumArgumentException <SelectionCombineMode>(this.combineMode, "this.combineMode"); } this.newSelectionRenderer.IsVisible = true; if (this.tracePoints.Count >= this.MinPointsForRender) { this.Render(); } } }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { GeometryList cachedClippingMask = historyWorkspace.Selection.GetCachedClippingMask(); if (historyWorkspace.Selection.IsEmpty || (cachedClippingMask.Bounds.Area < 1.0)) { return(null); } Document oldDocument = historyWorkspace.Document; RectInt32 b = cachedClippingMask.Bounds.GetInt32Bound(1E-05); RectInt32 oldClipBounds = RectInt32.Intersect(oldDocument.Bounds(), b); Document document = new Document(oldClipBounds.Width, oldClipBounds.Height); document.ReplaceMetadataFrom(oldDocument); RectInt32 newClipBounds = new RectInt32(0, 0, oldClipBounds.Width, oldClipBounds.Height); SelectionRenderingQuality quality = historyWorkspace.ToolSettings.Selection.RenderingQuality.Value; Result <IRenderer <ColorAlpha8> > oldClipMaskRendererLazy = historyWorkspace.Selection.GetCachedLazyClippingMaskRenderer(quality); LazyResult <ClippedRenderer <ColorAlpha8> > newClipMaskRendererLazy = LazyResult.New <ClippedRenderer <ColorAlpha8> >(() => new ClippedRenderer <ColorAlpha8>(oldClipMaskRendererLazy.Value, oldClipBounds), LazyThreadSafetyMode.ExecutionAndPublication, new VistaCriticalSection(0)); SelectionData selectionData = historyWorkspace.Selection.Save(); System.Threading.Tasks.Task <SelectionHistoryMemento> task = System.Threading.Tasks.Task.Factory.StartNew <SelectionHistoryMemento>(() => new SelectionHistoryMemento(null, null, historyWorkspace, selectionData)); System.Threading.Tasks.Task <ReplaceDocumentHistoryMemento> task2 = System.Threading.Tasks.Task.Factory.StartNew <ReplaceDocumentHistoryMemento>(() => new ReplaceDocumentHistoryMemento(null, null, historyWorkspace, oldDocument), TaskCreationOptions.LongRunning); int count = oldDocument.Layers.Count; System.Threading.Tasks.Task <BitmapLayer>[] items = new System.Threading.Tasks.Task <BitmapLayer> [count]; for (int i = 0; i < count; i++) { int iP = i; items[iP] = System.Threading.Tasks.Task.Factory.StartNew <BitmapLayer>(delegate { if (iP == 0) { newClipMaskRendererLazy.EnsureEvaluated(); } BitmapLayer layer = (BitmapLayer)oldDocument.Layers[iP]; Surface croppedSurface = layer.Surface.CreateWindow(oldClipBounds); BitmapLayer newLayer = RetryManager.RunMemorySensitiveOperation <BitmapLayer>(() => new BitmapLayer(croppedSurface)); newLayer.LoadProperties(layer.SaveProperties()); Parallel.ForEach <RectInt32>(newClipBounds.GetTiles(TilingStrategy.Tiles, 7), delegate(RectInt32 newTileRect) { ISurface <ColorBgra> surface = newLayer.Surface.CreateWindow(newTileRect); IRenderer <ColorAlpha8> mask = new ClippedRenderer <ColorAlpha8>(newClipMaskRendererLazy.Value, newTileRect); surface.MultiplyAlphaChannel(mask); }); return(newLayer); }); } List <TupleStruct <System.Threading.Tasks.Task, double> > collection = new List <TupleStruct <System.Threading.Tasks.Task, double> >(); collection.AddTuple <System.Threading.Tasks.Task, double>(task, 0.1); collection.AddTuple <System.Threading.Tasks.Task, double>(task2, 1.0); for (int j = 0; j < items.Length; j++) { collection.AddTuple <System.Threading.Tasks.Task, double>(items[j], 0.1); } PaintDotNet.Threading.Tasks.Task <Unit> task3 = historyWorkspace.TaskManager.CreateFrameworkTasksWrapper(collection); historyWorkspace.WaitWithProgress(task3, HistoryMementoImage, HistoryMementoName, PdnResources.GetString("Effects.ApplyingDialog.Description")); document.Layers.AddRange <Layer>(items.Select <System.Threading.Tasks.Task <BitmapLayer>, BitmapLayer>(t => t.Result)); SelectionHistoryMemento result = task.Result; ReplaceDocumentHistoryMemento memento2 = task2.Result; base.EnterCriticalRegion(); historyWorkspace.Document = document; HistoryMemento[] mementos = new HistoryMemento[] { result, memento2 }; return(HistoryMemento.Combine(HistoryMementoName, HistoryMementoImage, mementos)); }
private bool PerformActionImpl() { PointInt32 num2; RectInt32 num3; if (this.clipData == null) { try { using (new WaitCursorChanger(this.documentWorkspace)) { CleanupManager.RequestCleanup(); this.clipData = PdnClipboard.GetDataObject(); } } catch (OutOfMemoryException exception) { ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception); return(false); } catch (Exception exception2) { ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception2); return(false); } } bool handled = false; if (this.documentWorkspace.Tool != null) { this.documentWorkspace.Tool.PerformPaste(this.clipData, out handled); } if (handled) { return(true); } if (this.maskedSurface == null) { try { using (new WaitCursorChanger(this.documentWorkspace)) { this.maskedSurface = ClipboardUtil.GetClipboardImage(this.documentWorkspace, this.clipData); } } catch (OutOfMemoryException exception3) { ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception3); return(false); } catch (Exception exception4) { ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception4); return(false); } } if (this.maskedSurface == null) { MessageBoxUtil.ErrorBox(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.NoImage")); return(false); } RectInt32 cachedGeometryMaskScansBounds = this.maskedSurface.GetCachedGeometryMaskScansBounds(); if ((cachedGeometryMaskScansBounds.Width > this.documentWorkspace.Document.Width) || (cachedGeometryMaskScansBounds.Height > this.documentWorkspace.Document.Height)) { Surface surface; try { using (new WaitCursorChanger(this.documentWorkspace)) { surface = CreateThumbnail(this.maskedSurface); } } catch (OutOfMemoryException) { surface = null; } DialogResult result = ShowExpandCanvasTaskDialog(this.documentWorkspace, surface); int activeLayerIndex = this.documentWorkspace.ActiveLayerIndex; ColorBgra background = this.documentWorkspace.ToolSettings.SecondaryColor.Value; if (result != DialogResult.Cancel) { if (result != DialogResult.Yes) { if (result != DialogResult.No) { throw ExceptionUtil.InvalidEnumArgumentException <DialogResult>(result, "dr"); } goto Label_031D; } using (new PushNullToolMode(this.documentWorkspace)) { int width = Math.Max(cachedGeometryMaskScansBounds.Width, this.documentWorkspace.Document.Width); Size newSize = new Size(width, Math.Max(cachedGeometryMaskScansBounds.Height, this.documentWorkspace.Document.Height)); Document document = CanvasSizeAction.ResizeDocument(this.documentWorkspace.Document, newSize, AnchorEdge.TopLeft, background); if (document == null) { return(false); } SelectionHistoryMemento memento = new SelectionHistoryMemento(null, null, this.documentWorkspace); ReplaceDocumentHistoryMemento memento2 = new ReplaceDocumentHistoryMemento(CanvasSizeAction.StaticName, CanvasSizeAction.StaticImage, this.documentWorkspace); this.documentWorkspace.Document = document; HistoryMemento[] actions = new HistoryMemento[] { memento, memento2 }; CompoundHistoryMemento memento3 = new CompoundHistoryMemento(CanvasSizeAction.StaticName, CanvasSizeAction.StaticImage, actions); this.documentWorkspace.History.PushNewMemento(memento3); this.documentWorkspace.ActiveLayer = (Layer)this.documentWorkspace.Document.Layers[activeLayerIndex]; goto Label_031D; } } return(false); } Label_031D: num3 = this.documentWorkspace.Document.Bounds(); RectDouble visibleDocumentRect = this.documentWorkspace.VisibleDocumentRect; RectInt32? nullable = visibleDocumentRect.Int32Inset(); RectDouble num5 = nullable.HasValue ? ((RectDouble)nullable.Value) : visibleDocumentRect; RectInt32 num6 = num5.Int32Bound; if (num5.Contains(cachedGeometryMaskScansBounds)) { num2 = new PointInt32(0, 0); } else { int num12; int num13; int num16; int num17; if (cachedGeometryMaskScansBounds.X < num5.Left) { num12 = -cachedGeometryMaskScansBounds.X + num6.X; } else if (cachedGeometryMaskScansBounds.Right > num6.Right) { num12 = (-cachedGeometryMaskScansBounds.X + num6.Right) - cachedGeometryMaskScansBounds.Width; } else { num12 = 0; } if (cachedGeometryMaskScansBounds.Y < num5.Top) { num13 = -cachedGeometryMaskScansBounds.Y + num6.Y; } else if (cachedGeometryMaskScansBounds.Bottom > num6.Bottom) { num13 = (-cachedGeometryMaskScansBounds.Y + num6.Bottom) - cachedGeometryMaskScansBounds.Height; } else { num13 = 0; } PointInt32 num14 = new PointInt32(num12, num13); RectInt32 num15 = new RectInt32(cachedGeometryMaskScansBounds.X + num14.X, cachedGeometryMaskScansBounds.Y + num14.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height); if (num15.X < 0) { num16 = num12 - num15.X; } else { num16 = num12; } if (num15.Y < 0) { num17 = num13 - num15.Y; } else { num17 = num13; } PointInt32 num18 = new PointInt32(num16, num17); RectInt32 rect = new RectInt32(cachedGeometryMaskScansBounds.X + num18.X, cachedGeometryMaskScansBounds.Y + num18.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height); if (num3.Contains(rect)) { num2 = num18; } else { PointInt32 num20 = num18; if (rect.Right > num3.Right) { int num21 = rect.Right - num3.Right; int num22 = Math.Min(num21, rect.Left); num20.X -= num22; } if (rect.Bottom > num3.Bottom) { int num23 = rect.Bottom - num3.Bottom; int num24 = Math.Min(num23, rect.Top); num20.Y -= num24; } num2 = num20; } } RectInt32 b = this.documentWorkspace.VisibleDocumentRect.Int32Bound; RectInt32 a = new RectInt32(cachedGeometryMaskScansBounds.X + num2.X, cachedGeometryMaskScansBounds.Y + num2.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height); bool hasZeroArea = RectInt32.Intersect(a, b).HasZeroArea; MoveTool.BeginPaste(this.documentWorkspace, PdnResources.GetString("CommonAction.Paste"), PdnResources.GetImageResource("Icons.MenuEditPasteIcon.png"), this.maskedSurface.SurfaceReadOnly, this.maskedSurface.GeometryMask, num2); if (hasZeroArea) { PointInt32 num25 = new PointInt32(b.Left + (b.Width / 2), b.Top + (b.Height / 2)); PointInt32 num26 = new PointInt32(a.Left + (a.Width / 2), a.Top + (a.Height / 2)); SizeInt32 num27 = new SizeInt32(num26.X - num25.X, num26.Y - num25.Y); PointDouble documentScrollPosition = this.documentWorkspace.DocumentScrollPosition; PointDouble num29 = new PointDouble(documentScrollPosition.X + num27.Width, documentScrollPosition.Y + num27.Height); this.documentWorkspace.DocumentScrollPosition = num29; } return(true); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); this.Cursor = GetCursor(); if (tracking) { moveOriginMode = true; lastXY = new Point(e.X, e.Y); OnMouseMove(e); } else if ((e.Button & MouseButtons.Left) == MouseButtons.Left || (e.Button & MouseButtons.Right) == MouseButtons.Right) { tracking = true; hasMoved = false; startTime = DateTime.Now; tracePoints = new List <Point>(); tracePoints.Add(new Point(e.X, e.Y)); undoAction = new SelectionHistoryMemento("sentinel", this.Image, DocumentWorkspace); wasNotEmpty = !Selection.IsEmpty; // Determine this.combineMode if ((ModifierKeys & Keys.Control) != 0 && e.Button == MouseButtons.Left) { this.combineMode = CombineMode.Union; } else if ((ModifierKeys & Keys.Alt) != 0 && e.Button == MouseButtons.Left) { this.combineMode = CombineMode.Exclude; } else if ((ModifierKeys & Keys.Control) != 0 && e.Button == MouseButtons.Right) { this.combineMode = CombineMode.Xor; } else if ((ModifierKeys & Keys.Alt) != 0 && e.Button == MouseButtons.Right) { this.combineMode = CombineMode.Intersect; } else { this.combineMode = AppEnvironment.SelectionCombineMode; } DocumentWorkspace.EnableSelectionOutline = false; this.newSelection.Reset(); PdnGraphicsPath basePath = Selection.CreatePath(); this.newSelection.SetContinuation(basePath, CombineMode.Replace, true); this.newSelection.CommitContinuation(); bool newSelectionRendererVisible = true; // Act on this.combineMode switch (this.combineMode) { case CombineMode.Xor: append = true; Selection.ResetContinuation(); break; case CombineMode.Union: append = true; Selection.ResetContinuation(); break; case CombineMode.Exclude: append = true; Selection.ResetContinuation(); break; case CombineMode.Replace: append = false; Selection.Reset(); break; case CombineMode.Intersect: append = true; Selection.ResetContinuation(); break; default: throw new InvalidEnumArgumentException(); } this.newSelectionRenderer.Visible = newSelectionRendererVisible; } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (tracking) { return; } bool determinedMoveMode = false; Mode newMode = Mode.Translate; Edge newEdge = Edge.None; if (Selection.IsEmpty) { SelectionHistoryMemento shm = new SelectionHistoryMemento( HistoryFunctions.SelectAllFunction.StaticName, PdnResources.GetImageResource("Icons.MenuEditSelectAllIcon.png"), DocumentWorkspace); DocumentWorkspace.History.PushNewMemento(shm); DocumentWorkspace.Selection.PerformChanging(); DocumentWorkspace.Selection.Reset(); DocumentWorkspace.Selection.SetContinuation(Document.Bounds, CombineMode.Replace); DocumentWorkspace.Selection.CommitContinuation(); DocumentWorkspace.Selection.PerformChanged(); if (e.Button == MouseButtons.Right) { newMode = Mode.Rotate; } else { newMode = Mode.Translate; } newEdge = Edge.None; determinedMoveMode = true; } DocumentWorkspace.EnableSelectionOutline = this.enableOutline; if (!context.lifted) { Lift(e); } PushContextHistoryMemento(); if (!determinedMoveMode) { DetermineMoveMode(e, out newMode, out newEdge); determinedMoveMode = true; } if (this.context.deltaTransform != null) { this.context.deltaTransform.Dispose(); this.context.deltaTransform = null; } this.context.deltaTransform = new Matrix(); this.context.deltaTransform.Reset(); if (newMode == Mode.Translate || newMode == Mode.Scale || newMode != this.context.currentMode || newMode == Mode.Rotate) { this.context.startBounds = Selection.GetBoundsF(); this.context.startMouseXY = new Point(e.X, e.Y); this.context.offset = new Point(0, 0); if (this.context.baseTransform != null) { this.context.baseTransform.Dispose(); this.context.baseTransform = null; } this.context.baseTransform = Selection.GetInterimTransformCopy(); } this.context.startEdge = newEdge; this.context.currentMode = newMode; PositionNubs(this.context.currentMode); tracking = true; this.rotateNub.Visible = (this.context.currentMode == Mode.Rotate); if (this.context.startPath != null) { this.context.startPath.Dispose(); this.context.startPath = null; } this.context.startPath = Selection.CreatePath(); this.context.startAngle = Utility.GetAngleOfTransform(Selection.GetInterimTransformReadOnly()); SelectionHistoryMemento sha1 = new SelectionHistoryMemento(this.Name, this.Image, this.DocumentWorkspace); this.currentHistoryMementos.Add(sha1); OnMouseMove(e); if (this.enableOutline) { DocumentWorkspace.ResetOutlineWhiteOpacity(); } }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if (historyWorkspace.Selection.IsEmpty) { return(null); } SelectionHistoryMemento memento = new SelectionHistoryMemento(StaticName, StaticImage, historyWorkspace); GeometryList selectedPath = historyWorkspace.Selection.GetCachedGeometryList(); SelectionRenderingQuality selectionRenderingQuality = historyWorkspace.ToolSettings.Selection.RenderingQuality.Value; Result <IReadOnlyList <RectInt32> > selectedPathScansLazy = historyWorkspace.Selection.GetCachedLazyClippingMaskScans(); RectInt32 documentBounds = historyWorkspace.Document.Bounds(); Func <GeometryList> invertedPathFn = delegate { if ((selectionRenderingQuality == SelectionRenderingQuality.Aliased) || selectedPath.IsPixelated) { GeometryList list2 = GeometryList.FromNonOverlappingSortedScans(selectedPathScansLazy.Value); list2.AddRect(documentBounds); SegmentedList <RectInt32> scans = new SegmentedList <RectInt32>(); foreach (RectInt32 num in list2.EnumerateInteriorScans()) { if (documentBounds.Contains(num)) { scans.Add(num); } else if (documentBounds.IntersectsWith(num)) { scans.Add(RectInt32.Intersect(documentBounds, num)); } } return(GeometryList.FromNonOverlappingScans(scans)); } GeometryList lhs = documentBounds.Contains(selectedPath.Bounds) ? selectedPath : GeometryList.ClipToRect(selectedPath, documentBounds); return(GeometryList.Combine(lhs, GeometryCombineMode.Xor, documentBounds)); }; ThreadTask <GeometryList> task = historyWorkspace.TaskManager.StartNewThreadTask <GeometryList>(task => invertedPathFn(), ApartmentState.MTA); ManualResetEvent taskFinishedEvent = new ManualResetEvent(false); task.ResultAsync <GeometryList>().Receive(delegate(Result <GeometryList> r) { taskFinishedEvent.Set(); }).Observe(); if (!taskFinishedEvent.WaitOne(0x3e8)) { using (TaskProgressDialog dialog = new TaskProgressDialog()) { dialog.Task = task; dialog.Text = StaticName; dialog.Icon = StaticImage.Reference.ToIcon(); dialog.HeaderText = PdnResources.GetString("SaveConfigDialog.Finishing.Text"); dialog.ShowDialog(historyWorkspace.Window); } } Result <GeometryList> taskResult = task.TaskResult; if (taskResult.IsError) { if (taskResult.Error is OutOfMemoryException) { throw new OutOfMemoryException(null, taskResult.Error); } throw new AggregateException(null, taskResult.Error); } GeometryList geometry = task.TaskResult.Value; base.EnterCriticalRegion(); using (historyWorkspace.Selection.UseChangeScope()) { historyWorkspace.Selection.Reset(); geometry.Freeze(); historyWorkspace.Selection.SetContinuation(geometry, SelectionCombineMode.Replace); historyWorkspace.Selection.CommitContinuation(); } return(memento); }