private void Activate() { 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.HandCursor = Cursors.Hand; this.HandCursorMouseDown = Cursors.Arrow; this.HandCursorInvalid = Cursors.Arrow; this._mouseDownCount = 0; this._savedTiles = null; this._saveRegion = null; this._scratchSurface = DocumentWorkspace.BorrowScratchSurface(); // // 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(); }
private static BitVector2D PixelatedGeometryListToBitVector2D(GeometryList geometry, int width, int height, CancellationToken cancellationToken) { BitVector2D vectord = new BitVector2D(width, height); foreach (RectInt32 num in geometry.EnumerateInteriorScans()) { cancellationToken.ThrowIfCancellationRequested(); vectord.Set(num, true); } return(vectord); }
private void Deactivate() { 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; } }
private IRenderer <ColorAlpha8> CreateMaskRenderer() { IRenderer <ColorAlpha8> renderer; byte x = (byte)Math.Round((double)(this.changes.Tolerance * 255.0), MidpointRounding.AwayFromZero); byte tolerance = ByteUtil.FastScale(x, x); PointInt32 pt = this.changes.OriginPointInt32; if (!this.sampleSource.Bounds <ColorBgra>().Contains(pt)) { return(new FillRendererAlpha8(this.sampleSource.Width, this.sampleSource.Height, ColorAlpha8.Transparent)); } ColorBgra pointSlow = this.sampleSource.GetPointSlow(pt); base.ThrowIfCancellationRequested(); if (this.changes.FloodMode == FloodMode.Global) { renderer = new FillStencilByColorRenderer(this.sampleSource, pointSlow, tolerance, this); } else { RectInt32 num5; BitVector2D source = new BitVector2D(this.sampleSource.Width, this.sampleSource.Height); BitVector2DStruct stencilBuffer = new BitVector2DStruct(source); source.Clear(true); base.ThrowIfCancellationRequested(); foreach (RectInt32 num6 in this.changes.ClippingMask.EnumerateInteriorScans()) { source.Set(num6, false); base.ThrowIfCancellationRequested(); } BitVector2D other = source.Clone(); base.ThrowIfCancellationRequested(); FloodFillAlgorithm.FillStencilFromPoint <BitVector2DStruct>(this.sampleSource, stencilBuffer, pt, tolerance, this, out num5); base.ThrowIfCancellationRequested(); source.Xor(other); base.ThrowIfCancellationRequested(); renderer = new BitVector2DToAlpha8Renderer <BitVector2DStruct>(stencilBuffer); } if (this.changes.Antialiasing) { return(new FeatheredMaskRenderer(this.sampleSource, pointSlow, renderer, tolerance, this)); } return(renderer); }
protected override void OnActivate() { base.OnActivate(); // initialize any state information you need cursorMouseUp = new Cursor(PdnResources.GetResourceStream("Cursors.RecoloringToolCursor.cur")); cursorMouseDown = new Cursor(PdnResources.GetResourceStream("Cursors.GenericToolCursorMouseDown.cur")); cursorMouseDownPickColor = new Cursor(PdnResources.GetResourceStream("Cursors.RecoloringToolCursorPickColor.cur")); cursorMouseDownAdjustColor = new Cursor(PdnResources.GetResourceStream("Cursors.RecoloringToolCursorAdjustColor.cur")); this.previewRenderer = new BrushPreviewRenderer(this.RendererList); this.RendererList.Add(this.previewRenderer, false); Cursor = cursorMouseUp; mouseDown = false; // fetch colors from workspace palette this.colorToReplace = this.AppEnvironment.PrimaryColor; this.colorReplacing = this.AppEnvironment.SecondaryColor; this.aaPoints = this.ScratchSurface; this.isPointAlreadyAA = new BitVector2D(aaPoints.Width, aaPoints.Height); if (savedSurfaces != null) { foreach (PlacedSurface ps in savedSurfaces) { ps.Dispose(); } } savedSurfaces = new ArrayList(); if (ActiveLayer != null) { bitmapLayer = (BitmapLayer)ActiveLayer; renderArgs = new RenderArgs(bitmapLayer.Surface); } else { bitmapLayer = null; renderArgs = null; } }
public static GeometryGraphicsPath FromRegion(GeometryRegion region) { Rectangle[] scans = region.GetRegionScansReadOnlyInt(); if (scans.Length == 1) { var path = new GeometryGraphicsPath(); path.AddRectangle(scans[0]); path.CloseFigure(); return(path); } else { Rectangle bounds = region.GetBoundsInt(); var 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.UnsafeSet(rect, true); } GeometryGraphicsPath 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); } }
protected override void OnActivate() { base.OnActivate(); // initialize any state information you need cursorMouseUp = new Cursor(PdnResources.GetResourceStream("Cursors.RecoloringToolCursor.cur")); cursorMouseDown = new Cursor(PdnResources.GetResourceStream("Cursors.GenericToolCursorMouseDown.cur")); cursorMouseDownPickColor = new Cursor(PdnResources.GetResourceStream("Cursors.RecoloringToolCursorPickColor.cur")); cursorMouseDownAdjustColor = new Cursor(PdnResources.GetResourceStream("Cursors.RecoloringToolCursorAdjustColor.cur")); this.previewRenderer = new BrushPreviewRenderer(this.RendererList); this.RendererList.Add(this.previewRenderer, false); Cursor = cursorMouseUp; mouseDown = false; // fetch colors from workspace palette this.colorToReplace = this.AppEnvironment.PrimaryColor; this.colorReplacing = this.AppEnvironment.SecondaryColor; this.aaPoints = this.ScratchSurface; this.isPointAlreadyAA = new BitVector2D(aaPoints.Width, aaPoints.Height); if (savedSurfaces != null) { foreach (PlacedSurface ps in savedSurfaces) { ps.Dispose(); } } savedSurfaces = new ArrayList(); if (ActiveLayer != null) { bitmapLayer = (BitmapLayer)ActiveLayer; renderArgs = new RenderArgs(bitmapLayer.Surface); } else { bitmapLayer = null; renderArgs = null; } }
protected override GeometryList CreateSelectionGeometry(MagicWandToolChanges changes, AsyncSelectionToolCreateGeometryContext context, CancellationToken cancellationToken) { GeometryList list; Result <BitVector2D> lazyBaseStencil; IRenderer <ColorBgra> sampleSource = ((MagicWandToolCreateGeometryContext)context).SampleSource; byte x = (byte)Math.Round((double)(changes.Tolerance * 255.0), MidpointRounding.AwayFromZero); byte tolerance = ByteUtil.FastScale(x, x); PointInt32 pt = changes.OriginPointInt32; if (!sampleSource.Bounds <ColorBgra>().Contains(pt)) { switch (changes.SelectionCombineMode) { case SelectionCombineMode.Replace: case SelectionCombineMode.Intersect: return(new GeometryList()); case SelectionCombineMode.Union: case SelectionCombineMode.Exclude: case SelectionCombineMode.Xor: return(changes.BaseGeometry); } throw ExceptionUtil.InvalidEnumArgumentException <SelectionCombineMode>(changes.SelectionCombineMode, "changes.SelectionCombineMode"); } if (cancellationToken.IsCancellationRequested) { return(null); } Func <bool> isCancellationRequestedFn = () => cancellationToken.IsCancellationRequested; ColorBgra basis = sampleSource.GetPointSlow(pt); int width = ((sampleSource.Width + 0x1f) / 0x20) * 0x20; BitVector2D newStencil = new BitVector2D(width, sampleSource.Height); BitVector2DStruct newStencilWrapper = new BitVector2DStruct(newStencil); if (((changes.SelectionCombineMode != SelectionCombineMode.Replace) && sampleSource.Bounds <ColorBgra>().Contains(changes.BaseGeometry.Bounds.Int32Bound)) && changes.BaseGeometry.IsPixelated) { lazyBaseStencil = LazyResult.New <BitVector2D>(() => PixelatedGeometryListToBitVector2D(changes.BaseGeometry, newStencil.Width, newStencil.Height, cancellationToken), LazyThreadSafetyMode.ExecutionAndPublication, new SingleUseCriticalSection()); ThreadPool.QueueUserWorkItem(delegate(object _) { lazyBaseStencil.EnsureEvaluated(); }); } else { lazyBaseStencil = null; } FloodMode floodMode = changes.FloodMode; if (floodMode != FloodMode.Local) { if (floodMode != FloodMode.Global) { throw ExceptionUtil.InvalidEnumArgumentException <FloodMode>(changes.FloodMode, "changes.FloodMode"); } } else { RectInt32 num4; FloodFillAlgorithm.FillStencilFromPoint <BitVector2DStruct>(sampleSource, newStencilWrapper, pt, tolerance, isCancellationRequestedFn, out num4); goto Label_0293; } TileMathHelper tileMathHelper = new TileMathHelper(sampleSource.Width, sampleSource.Height, 7); Work.ParallelForEach <PointInt32>(WaitType.Pumping, tileMathHelper.EnumerateTileOffsets(), delegate(PointInt32 tileOffset) { if (!cancellationToken.IsCancellationRequested) { RectInt32 clipRect = tileMathHelper.GetTileSourceRect(tileOffset); FloodFillAlgorithm.FillStencilByColor <BitVector2DStruct>(sampleSource, newStencilWrapper, basis, tolerance, isCancellationRequestedFn, clipRect); } }, WorkItemQueuePriority.Normal, null); Label_0293: if (cancellationToken.IsCancellationRequested) { return(null); } if (changes.SelectionCombineMode == SelectionCombineMode.Replace) { list = GeometryList.FromStencil <BitVector2DStruct>(newStencilWrapper, cancellationToken); } else if (lazyBaseStencil == null) { GeometryList rhs = GeometryList.FromStencil <BitVector2DStruct>(newStencilWrapper, cancellationToken); if (cancellationToken.IsCancellationRequested) { return(null); } list = GeometryList.Combine(changes.BaseGeometry, changes.SelectionCombineMode.ToGeometryCombineMode(), rhs); } else { BitVector2D other = lazyBaseStencil.Value; if (cancellationToken.IsCancellationRequested) { return(null); } switch (changes.SelectionCombineMode) { case SelectionCombineMode.Replace: throw new InternalErrorException(); case SelectionCombineMode.Union: newStencil.Or(other); break; case SelectionCombineMode.Exclude: newStencil.Invert(); if (cancellationToken.IsCancellationRequested) { return(null); } newStencil.And(other); break; case SelectionCombineMode.Intersect: newStencil.And(other); break; case SelectionCombineMode.Xor: newStencil.Xor(other); break; default: throw ExceptionUtil.InvalidEnumArgumentException <SelectionCombineMode>(changes.SelectionCombineMode, "changes.SelectionCombineMode"); } if (cancellationToken.IsCancellationRequested) { return(null); } list = GeometryList.FromStencil <BitVector2DStruct>(newStencilWrapper, cancellationToken); } if (cancellationToken.IsCancellationRequested) { return(null); } list.Freeze(); return(list); }
public void SaveRegion(GeometryRegion saveMeRegion, Rectangle saveMeBounds) { var 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 static GeometryGraphicsPath FromRegions(GeometryRegion lhs, CombineMode combineMode, GeometryRegion 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"); } for (int i = 0; i < lhsScans.Length; ++i) { Rectangle rect = lhsScans[i]; rect.X -= bounds.X; rect.Y -= bounds.Y; stencil.UnsafeSet(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.UnsafeInvert(rect); break; case CombineMode.Union: stencil.UnsafeSet(rect, true); break; case CombineMode.Exclude: stencil.UnsafeSet(rect, false); break; } } GeometryGraphicsPath path = PathFromStencil(stencil, new Rectangle(0, 0, stencil.Width, stencil.Height)); using (var matrix = new Matrix()) { matrix.Reset(); matrix.Translate(bounds.X, bounds.Y); path.Transform(matrix); } return(path); }