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(); } } }
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(); } } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); this.rendererDst.BrushLocation = new Point(e.X, e.Y); this.rendererDst.BrushSize = AppEnvironment.PenInfo.Width / 2.0f; if (!(ActiveLayer is BitmapLayer) || (takeFromLayer == null)) { return; } if (GetStaticData().updateSrcPreview) { Point currentMouse = new Point(e.X, e.Y); Point difference = new Point(currentMouse.X - GetStaticData().lastMoved.X, currentMouse.Y - GetStaticData().lastMoved.Y); this.rendererSrc.BrushLocation = new Point(GetStaticData().takeFrom.X + difference.X, GetStaticData().takeFrom.Y + difference.Y);; this.rendererSrc.BrushSize = AppEnvironment.PenInfo.Width / 2.0f; } if (IsMouseLeftDown(e) && (GetStaticData().takeFrom != Point.Empty) && !IsCtrlDown()) { Point currentMouse = new Point(e.X, e.Y); Point lastTakeFrom = Point.Empty; lastTakeFrom = GetStaticData().takeFrom; if (GetStaticData().lastMoved != Point.Empty) { Point difference = new Point(currentMouse.X - GetStaticData().lastMoved.X, currentMouse.Y - GetStaticData().lastMoved.Y); GetStaticData().takeFrom = new Point(GetStaticData().takeFrom.X + difference.X, GetStaticData().takeFrom.Y + difference.Y); } else { GetStaticData().lastMoved = currentMouse; } int penWidth = (int)AppEnvironment.PenInfo.Width; Rectangle rect; if (penWidth != 1) { rect = new Rectangle(new Point(GetStaticData().takeFrom.X - penWidth / 2, GetStaticData().takeFrom.Y - penWidth / 2), new Size(penWidth + 1, penWidth + 1)); } else { rect = new Rectangle(new Point(GetStaticData().takeFrom.X - penWidth, GetStaticData().takeFrom.Y - penWidth), new Size(1 + (2 * penWidth), 1 + (2 * penWidth))); } Rectangle boundRect = new Rectangle(GetStaticData().takeFrom, new Size(1, 1)); // If the takeFrom area escapes the boundary if (!ActiveLayer.Bounds.Contains(boundRect)) { GetStaticData().lastMoved = currentMouse; lastTakeFrom = GetStaticData().takeFrom; } if (this.savedRegion != null) { ActiveLayer.Invalidate(savedRegion.GetBoundsInt()); this.savedRegion.Dispose(); this.savedRegion = null; } rect.Intersect(takeFromLayer.Surface.Bounds); if (rect.Width == 0 || rect.Height == 0) { return; } this.savedRegion = new PdnRegion(rect); SaveRegion(this.savedRegion, rect); // Draw that clone line Surface takeFromSurface; if (object.ReferenceEquals(takeFromLayer, ActiveLayer)) { takeFromSurface = this.ScratchSurface; } else { takeFromSurface = takeFromLayer.Surface; } if (this.clipRegion == null) { this.clipRegion = Selection.CreateRegion(); } DrawCloneLine(currentMouse, GetStaticData().lastMoved, lastTakeFrom, takeFromSurface, ((BitmapLayer)ActiveLayer).Surface); this.rendererSrc.BrushLocation = GetStaticData().takeFrom; ActiveLayer.Invalidate(rect); Update(); GetStaticData().lastMoved = currentMouse; } }