private void Activate() { Debug.Assert(this.active != true, "already active!"); this.active = true; this.handCursor = new Cursor(PdnResources.GetResourceStream("Cursors.PanToolCursor.cur")); this.handCursorMouseDown = new Cursor(PdnResources.GetResourceStream("Cursors.PanToolCursorMouseDown.cur")); this.handCursorInvalid = new Cursor(PdnResources.GetResourceStream("Cursors.PanToolCursorInvalid.cur")); this.panTracking = false; this.panMode = false; this.mouseDown = 0; this.savedTiles = null; this.saveRegion = null; this.scratchSurface = DocumentWorkspace.BorrowScratchSurface(this.GetType().Name + ": Tool.Activate()"); #if DEBUG this.haveClearedScratch = false; #endif Selection.Changing += new EventHandler(SelectionChangingHandler); Selection.Changed += new EventHandler(SelectionChangedHandler); HistoryStack.ExecutingHistoryMemento += new ExecutingHistoryMementoEventHandler(ExecutingHistoryMemento); HistoryStack.ExecutedHistoryMemento += new ExecutedHistoryMementoEventHandler(ExecutedHistoryMemento); HistoryStack.FinishedStepGroup += new EventHandler(FinishedHistoryStepGroup); this.trackingNub = new MoveNubRenderer(this.RendererList); this.trackingNub.Visible = false; this.trackingNub.Size = new SizeF(10, 10); this.trackingNub.Shape = MoveNubShape.Compass; this.RendererList.Add(this.trackingNub, false); OnActivate(); }
public static PdnGraphicsPath FromRegion(PdnRegion region) { Rectangle bounds = region.GetBoundsInt(); Rectangle[] scans = region.GetRegionScansReadOnlyInt(); BitVector2D stencil = new BitVector2D(bounds.Width, bounds.Height); for (int i = 0; i < scans.Length; ++i) { Rectangle rect = scans[i]; rect.X -= bounds.X; rect.Y -= bounds.Y; stencil.SetUnchecked(rect, true); } PdnGraphicsPath path = PathFromStencil(stencil, new Rectangle(0, 0, stencil.Width, stencil.Height)); using (Matrix matrix = new Matrix()) { matrix.Reset(); matrix.Translate(bounds.X, bounds.Y); path.Transform(matrix); } return(path); }
private void Deactivate() { Debug.Assert(this.active != false, "not active!"); this.active = false; Selection.Changing -= new EventHandler(SelectionChangingHandler); Selection.Changed -= new EventHandler(SelectionChangedHandler); HistoryStack.ExecutingHistoryMemento -= new ExecutingHistoryMementoEventHandler(ExecutingHistoryMemento); HistoryStack.ExecutedHistoryMemento -= new ExecutedHistoryMementoEventHandler(ExecutedHistoryMemento); HistoryStack.FinishedStepGroup -= new EventHandler(FinishedHistoryStepGroup); OnDeactivate(); this.RendererList.Remove(this.trackingNub); this.trackingNub.Dispose(); this.trackingNub = null; DocumentWorkspace.ReturnScratchSurface(this.scratchSurface); this.scratchSurface = null; if (this.saveRegion != null) { this.saveRegion.Dispose(); this.saveRegion = null; } this.savedTiles = null; if (this.handCursor != null) { this.handCursor.Dispose(); this.handCursor = null; } if (this.handCursorMouseDown != null) { this.handCursorMouseDown.Dispose(); this.handCursorMouseDown = null; } if (this.handCursorInvalid != null) { this.handCursorInvalid.Dispose(); this.handCursorInvalid = null; } }
public void SaveRegion(PdnRegion saveMeRegion, Rectangle saveMeBounds) { BitmapLayer activeLayer = (BitmapLayer)ActiveLayer; if (savedTiles == null) { savedTiles = new BitVector2D( (activeLayer.Width + saveTileGranularity - 1) / saveTileGranularity, (activeLayer.Height + saveTileGranularity - 1) / saveTileGranularity); savedTiles.Clear(false); } Rectangle regionBounds; if (saveMeRegion == null) { regionBounds = saveMeBounds; } else { regionBounds = saveMeRegion.GetBoundsInt(); } Rectangle bounds = Rectangle.Union(regionBounds, saveMeBounds); bounds.Intersect(activeLayer.Bounds); int leftTile = bounds.Left / saveTileGranularity; int topTile = bounds.Top / saveTileGranularity; int rightTile = (bounds.Right - 1) / saveTileGranularity; int bottomTile = (bounds.Bottom - 1) / saveTileGranularity; for (int tileY = topTile; tileY <= bottomTile; ++tileY) { Rectangle rowAccumBounds = Rectangle.Empty; for (int tileX = leftTile; tileX <= rightTile; ++tileX) { if (!savedTiles.Get(tileX, tileY)) { Rectangle tileBounds = new Rectangle(tileX * saveTileGranularity, tileY * saveTileGranularity, saveTileGranularity, saveTileGranularity); tileBounds.Intersect(activeLayer.Bounds); if (rowAccumBounds == Rectangle.Empty) { rowAccumBounds = tileBounds; } else { rowAccumBounds = Rectangle.Union(rowAccumBounds, tileBounds); } savedTiles.Set(tileX, tileY, true); } else { if (rowAccumBounds != Rectangle.Empty) { using (Surface dst = ScratchSurface.CreateWindow(rowAccumBounds), src = activeLayer.Surface.CreateWindow(rowAccumBounds)) { dst.CopySurface(src); } rowAccumBounds = Rectangle.Empty; } } } if (rowAccumBounds != Rectangle.Empty) { using (Surface dst = ScratchSurface.CreateWindow(rowAccumBounds), src = activeLayer.Surface.CreateWindow(rowAccumBounds)) { dst.CopySurface(src); } rowAccumBounds = Rectangle.Empty; } } if (this.saveRegion != null) { this.saveRegion.Dispose(); this.saveRegion = null; } if (saveMeRegion != null) { this.saveRegion = saveMeRegion.Clone(); } }
public void ClearSavedMemory() { this.savedTiles = null; }
public BitVector2D(BitVector2D copyMe) { this.Width = copyMe.Width; this.Height = copyMe.Height; this.bitArray = (BitArray)copyMe.bitArray.Clone(); }
public static PdnGraphicsPath FromRegions(PdnRegion lhs, CombineMode combineMode, PdnRegion rhs) { Rectangle lhsBounds = lhs.GetBoundsInt(); Rectangle rhsBounds = rhs.GetBoundsInt(); int left = Math.Min(lhsBounds.Left, rhsBounds.Left); int top = Math.Min(lhsBounds.Top, rhsBounds.Top); int right = Math.Max(lhsBounds.Right, rhsBounds.Right); int bottom = Math.Max(lhsBounds.Bottom, rhsBounds.Bottom); Rectangle bounds = Rectangle.FromLTRB(left, top, right, bottom); BitVector2D stencil = new BitVector2D(bounds.Width, bounds.Height); Rectangle[] lhsScans = lhs.GetRegionScansReadOnlyInt(); Rectangle[] rhsScans = rhs.GetRegionScansReadOnlyInt(); switch (combineMode) { case CombineMode.Complement: case CombineMode.Intersect: case CombineMode.Replace: throw new ArgumentException("combineMode can't be Complement, Intersect, or Replace"); default: break; } for (int i = 0; i < lhsScans.Length; ++i) { Rectangle rect = lhsScans[i]; rect.X -= bounds.X; rect.Y -= bounds.Y; stencil.SetUnchecked(rect, true); } for (int i = 0; i < rhsScans.Length; ++i) { Rectangle rect = rhsScans[i]; rect.X -= bounds.X; rect.Y -= bounds.Y; switch (combineMode) { case CombineMode.Xor: stencil.InvertUnchecked(rect); break; case CombineMode.Union: stencil.SetUnchecked(rect, true); break; case CombineMode.Exclude: stencil.SetUnchecked(rect, false); break; } } PdnGraphicsPath path = PathFromStencil(stencil, new Rectangle(0, 0, stencil.Width, stencil.Height)); using (Matrix matrix = new Matrix()) { matrix.Reset(); matrix.Translate(bounds.X, bounds.Y); path.Transform(matrix); } return(path); }
public static PdnGraphicsPath FromRegions(PdnRegion lhs, CombineMode combineMode, PdnRegion rhs) { Rectangle lhsBounds = lhs.GetBoundsInt(); Rectangle rhsBounds = rhs.GetBoundsInt(); int left = Math.Min(lhsBounds.Left, rhsBounds.Left); int top = Math.Min(lhsBounds.Top, rhsBounds.Top); int right = Math.Max(lhsBounds.Right, rhsBounds.Right); int bottom = Math.Max(lhsBounds.Bottom, rhsBounds.Bottom); Rectangle bounds = Rectangle.FromLTRB(left, top, right, bottom); BitVector2D stencil = new BitVector2D(bounds.Width, bounds.Height); Rectangle[] lhsScans = lhs.GetRegionScansReadOnlyInt(); Rectangle[] rhsScans = rhs.GetRegionScansReadOnlyInt(); switch (combineMode) { case CombineMode.Complement: case CombineMode.Intersect: case CombineMode.Replace: throw new ArgumentException("combineMode can't be Complement, Intersect, or Replace"); default: break; } for (int i = 0; i < lhsScans.Length; ++i) { Rectangle rect = lhsScans[i]; rect.X -= bounds.X; rect.Y -= bounds.Y; stencil.SetUnchecked(rect, true); } for (int i = 0; i < rhsScans.Length; ++i) { Rectangle rect = rhsScans[i]; rect.X -= bounds.X; rect.Y -= bounds.Y; switch (combineMode) { case CombineMode.Xor: stencil.InvertUnchecked(rect); break; case CombineMode.Union: stencil.SetUnchecked(rect, true); break; case CombineMode.Exclude: stencil.SetUnchecked(rect, false); break; } } PdnGraphicsPath path = PathFromStencil(stencil, new Rectangle(0, 0, stencil.Width, stencil.Height)); using (Matrix matrix = new Matrix()) { matrix.Reset(); matrix.Translate(bounds.X, bounds.Y); path.Transform(matrix); } return path; }
public static PdnGraphicsPath FromRegion(PdnRegion region) { Rectangle[] scans = region.GetRegionScansReadOnlyInt(); if (scans.Length == 1) { PdnGraphicsPath path = new PdnGraphicsPath(); path.AddRectangle(scans[0]); path.CloseFigure(); return path; } else { Rectangle bounds = region.GetBoundsInt(); BitVector2D stencil = new BitVector2D(bounds.Width, bounds.Height); for (int i = 0; i < scans.Length; ++i) { Rectangle rect = scans[i]; rect.X -= bounds.X; rect.Y -= bounds.Y; stencil.SetUnchecked(rect, true); } PdnGraphicsPath path = PathFromStencil(stencil, new Rectangle(0, 0, stencil.Width, stencil.Height)); using (Matrix matrix = new Matrix()) { matrix.Reset(); matrix.Translate(bounds.X, bounds.Y); path.Transform(matrix); } return path; } }
public BitVector2D(BitVector2D copyMe) { this.width = copyMe.width; this.height = copyMe.height; this.bitArray = (BitArray)copyMe.bitArray.Clone(); }