public override void ApplyPaste(ArrangerPaste paste) { var notifyEvent = ApplyPasteInternal(paste).Match( success => { AddHistoryAction(new PasteArrangerHistoryAction(Paste)); IsModified = true; CancelOverlay(); BitmapAdapter.Invalidate(); return(new NotifyOperationEvent("Paste successfully applied")); }, fail => new NotifyOperationEvent(fail.Reason) ); _events.PublishOnUIThread(notifyEvent); }
public MagitekResult ApplyPasteInternal(ArrangerPaste paste) { int destX = Math.Max(0, paste.Rect.SnappedLeft); int destY = Math.Max(0, paste.Rect.SnappedTop); int sourceX = paste.Rect.SnappedLeft >= 0 ? 0 : -paste.Rect.SnappedLeft; int sourceY = paste.Rect.SnappedTop >= 0 ? 0 : -paste.Rect.SnappedTop; var destStart = new Point(destX, destY); var sourceStart = new Point(sourceX, sourceY); ArrangerCopy copy; if (paste?.Copy is ElementCopy elementCopy) { copy = elementCopy.ToPixelCopy(); } else { copy = paste?.Copy; } if (copy is IndexedPixelCopy indexedCopy) { int copyWidth = Math.Min(copy.Width - sourceX, _directImage.Width - destX); int copyHeight = Math.Min(copy.Height - sourceY, _directImage.Height - destY); return(ImageCopier.CopyPixels(indexedCopy.Image, _directImage, sourceStart, destStart, copyWidth, copyHeight)); } else if (copy is DirectPixelCopy directCopy) { int copyWidth = Math.Min(copy.Width - sourceX, _directImage.Width - destX); int copyHeight = Math.Min(copy.Height - sourceY, _directImage.Height - destY); return(ImageCopier.CopyPixels(directCopy.Image, _directImage, sourceStart, destStart, copyWidth, copyHeight)); } else { throw new InvalidOperationException($"{nameof(ApplyPasteInternal)} attempted to copy from an arranger of type {Paste.Copy.Source.ColorType} to {WorkingArranger.ColorType}"); } }
public PasteArrangerHistoryAction(ArrangerPaste paste) { Paste = paste; }