public bool RequestBoundsChange(RectInt32 newBounds) { base.VerifyAccess(); bool handled = false; this.OnBoundsChangeRequested(newBounds, ref handled); return(handled); }
public RectDouble ClientToDocument(RectInt32 clientRect) { RectInt32 screenRect = this.RectangleToScreen(clientRect); RectInt32 viewportRect = this.scrollableCanvasControl.CanvasControl.RectangleToClient(screenRect); RectDouble extentRect = this.CanvasView.ConvertViewportToExtent(viewportRect); return(this.CanvasView.ConvertExtentToCanvas(extentRect)); }
private void OnCanvasViewViewportCanvasBoundsChanged(object sender, ValueChangedEventArgs <RectDouble> e) { if (this.IsVisible && this.IsActive) { RectInt32 sourceRect = e.NewValue.Int32Bound; this.tileCache.QueueInvalidTilesForRendering(sourceRect, true); } }
public unsafe void Render(ISurface <ColorAlpha8> dst, PointInt32 renderOffset) { this.cancelToken.ThrowIfCancellationRequested <ICancellationToken>(); int width = dst.Width; int height = dst.Height; RectInt32 bounds = RectInt32.Inflate(new RectInt32(renderOffset, new SizeInt32(width, height)), 1, 1); byte[] buffer = toleranceToMaskValueLookupTable(this.tolerance); this.cancelToken.ThrowIfCancellationRequested <ICancellationToken>(); using (ISurface <ColorAlpha8> surface = UseTileOrToSurfaceWithEdgePadding(this.stencilSource, bounds, ColorAlpha8.Transparent)) { for (int i = 0; i < height; i++) { this.cancelToken.ThrowIfCancellationRequested <ICancellationToken>(); byte *rowPointer = (byte *)dst.GetRowPointer <ColorAlpha8>(i); byte *numPtr2 = (byte *)surface.GetPointPointer <ColorAlpha8>(0, i); byte *numPtr3 = (byte *)surface.GetPointPointer <ColorAlpha8>(0, (i + 1)); byte *numPtr4 = (byte *)surface.GetPointPointer <ColorAlpha8>(0, (i + 2)); for (int j = 0; j < width; j++) { byte num6; byte num7 = numPtr3[1]; if (num7 != 0) { num6 = num7; } else { byte num8 = numPtr2[0]; byte num9 = numPtr2[1]; byte num10 = numPtr2[2]; byte num11 = numPtr3[0]; byte num12 = numPtr3[2]; byte num13 = numPtr4[0]; byte num14 = numPtr4[1]; byte num15 = numPtr4[2]; if ((((num8 == 0xff) || (num9 == 0xff)) || ((num10 == 0xff) || (num11 == 0xff))) || (((num12 == 0xff) || (num13 == 0xff)) || ((num14 == 0xff) || (num15 == 0xff)))) { ColorBgra b = this.colorSource.GetPointSlow(j + renderOffset.X, i + renderOffset.Y); byte distance = FloodFillAlgorithm.GetDistance(this.basis, b); byte mask = buffer[distance]; byte coverage = this.GetCoverageValue(num8, num9, num10, num11, num12, num13, num14, num15); num6 = this.CombineMaskAndCoverageValues(mask, coverage); } else { num6 = 0; } } rowPointer[0] = num6; rowPointer++; numPtr2++; numPtr3++; numPtr4++; } } } }
/// <summary> /// Adds the rendering liquid vertices to the provided list for the MapChunk given by: /// </summary> /// <param name="indexY">The y index of the map chunk.</param> /// <param name="indexX">The x index of the map chunk</param> /// <param name="vertices">The Collection to add the vertices to.</param> /// <returns>The number of vertices added.</returns> public override int GenerateLiquidVertices(int indexX, int indexY, ICollection <Vector3> vertices) { var count = 0; var chunk = Chunks[indexX, indexY]; if (chunk == null) { return(count); } if (!chunk.HasLiquid) { return(count); } //var clr = Color.Green; //switch (mh2O.Header.Type) //{ // case FluidType.Water: // clr = Color.Blue; // break; // case FluidType.Lava: // clr = Color.Red; // break; // case FluidType.OceanWater: // clr = Color.Coral; // break; //} var mh2OHeightMap = chunk.LiquidHeights; var header = chunk.WaterInfo.Header; var bounds = new RectInt32(header.XOffset, header.YOffset, header.Width, header.Height); for (var xStep = 0; xStep <= TerrainConstants.UnitsPerChunkSide; xStep++) { for (var yStep = 0; yStep < 9; yStep++) { var xPos = TerrainConstants.CenterPoint - (TileX * TerrainConstants.TileSize) - (indexX * TerrainConstants.ChunkSize) - (xStep * TerrainConstants.UnitSize); var yPos = TerrainConstants.CenterPoint - (TileY * TerrainConstants.TileSize) - (indexY * TerrainConstants.ChunkSize) - (yStep * TerrainConstants.UnitSize); if (((xStep < bounds.X) || ((xStep - bounds.X) > bounds.Height)) || ((yStep < bounds.Y) || ((yStep - bounds.Y) > bounds.Width))) { continue; } var zPos = mh2OHeightMap[yStep - bounds.Y, xStep - bounds.X]; var position = new Vector3(xPos, yPos, zPos); vertices.Add(position); count++; } } return(count); }
private static PointInt32 AdjustNewLocation(SnapObstacle obstacle, PointInt32 newLocation, SnapDescription snapDescription) { obstacle.VerifyAccess(); if ((snapDescription == null) || ((snapDescription.HorizontalEdge == HorizontalSnapEdge.Neither) && (snapDescription.VerticalEdge == VerticalSnapEdge.Neither))) { return(obstacle.Bounds.Location); } RectInt32 num = new RectInt32(newLocation, obstacle.Bounds.Size); RectInt32 bounds = snapDescription.SnappedTo.Bounds; HorizontalSnapEdge horizontalEdge = snapDescription.HorizontalEdge; VerticalSnapEdge verticalEdge = snapDescription.VerticalEdge; SnapRegion snapRegion = snapDescription.SnappedTo.SnapRegion; int num3 = 0; if ((horizontalEdge == HorizontalSnapEdge.Top) && (snapRegion == SnapRegion.Exterior)) { int num7 = bounds.Top - snapDescription.YOffset; num3 = num.Bottom - num7; } else if ((horizontalEdge == HorizontalSnapEdge.Bottom) && (snapRegion == SnapRegion.Exterior)) { int num8 = bounds.Bottom + snapDescription.YOffset; num3 = num.Top - num8; } else if ((horizontalEdge == HorizontalSnapEdge.Top) && (snapRegion == SnapRegion.Interior)) { int num9 = Math.Min(bounds.Bottom, bounds.Top + snapDescription.YOffset); num3 = num.Top - num9; } else if ((horizontalEdge == HorizontalSnapEdge.Bottom) && (snapRegion == SnapRegion.Interior)) { int num10 = Math.Max(bounds.Top, bounds.Bottom - snapDescription.YOffset); num3 = num.Bottom - num10; } int num4 = 0; if ((verticalEdge == VerticalSnapEdge.Left) && (snapRegion == SnapRegion.Exterior)) { int num11 = bounds.Left - snapDescription.XOffset; num4 = num.Right - num11; } else if ((verticalEdge == VerticalSnapEdge.Right) && (snapRegion == SnapRegion.Exterior)) { int num12 = bounds.Right + snapDescription.XOffset; num4 = num.Left - num12; } else if ((verticalEdge == VerticalSnapEdge.Left) && (snapRegion == SnapRegion.Interior)) { int num13 = Math.Min(bounds.Right, bounds.Left + snapDescription.XOffset); num4 = num.Left - num13; } else if ((verticalEdge == VerticalSnapEdge.Right) && (snapRegion == SnapRegion.Interior)) { int num14 = Math.Max(bounds.Left, bounds.Right - snapDescription.XOffset); num4 = num.Right - num14; } return(new PointInt32(num.Left - num4, num.Top - num3)); }
public BitmapLayerToolLayerOverlay(BitmapLayer layer, RectInt32 affectedBounds, TChanges changes, ContentBlendMode blendMode, IEnumerable <IMaskedRenderer <ColorBgra, ColorAlpha8> > contentRenderers, IRenderer <ColorAlpha8> clipMaskRenderer) : base(layer, affectedBounds) { Validate.IsNotNull <TChanges>(changes, "changes"); this.changes = changes; this.blendMode = blendMode; this.contentRenderers = contentRenderers.ToArrayEx <IMaskedRenderer <ColorBgra, ColorAlpha8> >(); this.clipMaskRenderer = clipMaskRenderer; this.renderer = new ContentRendererBgra(base.Layer.Surface, this.blendMode, this.contentRenderers, this.clipMaskRenderer); }
private static Surface CreateThumbnail(MaskedSurface maskedSurface) { int thumbSideLength = UIUtil.ScaleWidth(120); Surface surfaceReadOnly = maskedSurface.SurfaceReadOnly; GeometryList geometryMaskCopy = maskedSurface.GetGeometryMaskCopy(); RectInt32 maskBounds = maskedSurface.GeometryMaskBounds.Int32Bound; return(CreateThumbnail(surfaceReadOnly, geometryMaskCopy, maskBounds, thumbSideLength)); }
private void EnsureItemIsFullyVisible(ItemType itemType, int itemIndex) { PointInt32 location = this.StackIndexToViewPoint(itemType, itemIndex); RectInt32 num2 = new RectInt32(location, new SizeInt32(this.ViewWidth, this.itemHeight)); int num3 = num2.Bottom - base.ClientSize.Height; int top = num2.Top; this.ScrollOffset = Int32Util.ClampSafe(this.ScrollOffset, num3, top); }
private void UpdateTileWhileLocked(TileData tileData, ICancellationToken cancelToken) { RectInt32 tileSourceRect = this.tileMathHelper.GetTileSourceRect(tileData.Offset); RectDouble num2 = tileSourceRect; cancelToken.ThrowIfCancellationRequested <ICancellationToken>(); object newCurrencyToken = this.renderData.CreateCurrencyToken(); cancelToken.ThrowIfCancellationRequested <ICancellationToken>(); IList <int?> list = this.renderData.GetStrokeSampleIndicesInRect(tileSourceRect, tileData.CurrencyToken, newCurrencyToken); int count = list.Count; if (count > 0) { SizeDouble size = this.stamp.Size; RectDouble num5 = new RectDouble(PointDouble.Zero, size); IDrawingContext dc = null; try { for (int i = 0; i < count; i++) { int?nullable = list[i]; if (nullable.HasValue) { if (tileData.Mask == null) { cancelToken.ThrowIfCancellationRequested <ICancellationToken>(); tileData.Mask = new SurfaceAlpha8(tileSourceRect.Size); } if (tileData.MaskRenderTarget == null) { cancelToken.ThrowIfCancellationRequested <ICancellationToken>(); tileData.MaskRenderTarget = RenderTarget.FromSurface(tileData.Mask, FactorySource.PerThread); } if (dc == null) { cancelToken.ThrowIfCancellationRequested <ICancellationToken>(); dc = DrawingContext.FromRenderTarget(tileData.MaskRenderTarget); dc.UseTranslateTransform((float)-tileSourceRect.X, (float)-tileSourceRect.Y, MatrixMultiplyOrder.Prepend); dc.AntialiasMode = AntialiasMode.Aliased; } int valueOrDefault = nullable.GetValueOrDefault(); RectDouble bounds = this.renderData.StrokeSamples[valueOrDefault].GetBounds(size); RectDouble num9 = this.stamp.Antialiased ? bounds : RectDouble.Round(bounds, MidpointRounding.AwayFromZero); cancelToken.ThrowIfCancellationRequested <ICancellationToken>(); RectDouble?srcRect = null; dc.FillOpacityMask(this.lazyStampMaskDevBitmap.CancelableValue <DeviceBitmap>(), whiteBrush, OpacityMaskContent.Graphics, new RectDouble?(num9), srcRect); } } } finally { DisposableUtil.Free <IDrawingContext>(ref dc); } } tileData.CurrencyToken = newCurrencyToken; }
private static void ParkObstacle(SnapObstacle avoider, SnapDescription snapDescription) { avoider.VerifyAccess(); PointInt32 location = avoider.Bounds.Location; PointInt32 num2 = AdjustNewLocation(avoider, location, snapDescription); RectInt32 newBounds = new RectInt32(num2, avoider.Bounds.Size); avoider.RequestBoundsChange(newBounds); }
public unsafe BaseMaskSampler(MoveToolContentRenderer owner, RectInt32 sourceRect) { this.owner = owner; this.sourceRect = sourceRect; this.baseMaskWindow = null; this.isInitialized = false; this.ptr = null; this.margin = -1; }
public ApplyRendererToBitmapLayerHistoryFunction(string historyMementoName, ImageResource historyMementoImage, int layerIndex, IRenderer <ColorBgra> renderer, RectInt32 rendererClipRect, int rendererTileEdgeLog2 = 4, int delayUntilProgressDialogMs = 0x7d0, ActionFlags actionFlags = 0) : base(actionFlags) { this.historyMementoName = historyMementoName; this.historyMementoImage = historyMementoImage; this.layerIndex = layerIndex; this.renderer = renderer; this.rendererClipRect = rendererClipRect; this.rendererTileEdgeLog2 = rendererTileEdgeLog2; this.delayUntilProgressDialogMs = delayUntilProgressDialogMs; }
public RectInt32 GetDefaultDifferentialMaxBounds(TChanges oldChanges, TChanges newChanges) { if (oldChanges.Equals((ReferenceValue)newChanges)) { return(new RectInt32(newChanges.GetMaxRenderBounds().Location, SizeInt32.Zero)); } RectInt32 maxRenderBounds = oldChanges.GetMaxRenderBounds(); RectInt32 b = newChanges.GetMaxRenderBounds(); return(RectInt32.Union(maxRenderBounds, b)); }
protected override void OnBoundsChangeRequested(RectInt32 newBounds, ref bool handled) { base.VerifyAccess(); if (this.BoundsChangeRequested != null) { HandledEventArgs <RectInt32> e = new HandledEventArgs <RectInt32>(handled, newBounds); this.BoundsChangeRequested(this, e); handled = e.Handled; } base.OnBoundsChangeRequested(newBounds, ref handled); }
private static unsafe void RenderWithClipMask( Effect effect, EffectConfigToken token, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, IRenderer <ColorAlpha8> clipMaskRenderer) { // Render the effect effect.Render(token, dstArgs, srcArgs, rois); if (effect.IsCancelRequested) { return; } if (clipMaskRenderer != null) { RectInt32 bounds = RectangleUtil.Bounds(rois).ToRectInt32(); if (bounds.HasPositiveArea) { // dstArgs = (srcArgs * (1 - clipMask)) + (dstArgs * clipMask) // TODO: optimize, or at least refactor into its own method using (ISurface <ColorAlpha8> clipMask = clipMaskRenderer.UseTileOrToSurface(bounds)) { int width = bounds.Width; int height = bounds.Height; int left = bounds.Left; int top = bounds.Top; int bottom = bounds.Bottom; int dstStride = dstArgs.Surface.Stride; int srcStride = srcArgs.Surface.Stride; int clipMaskStride = clipMask.Stride; ColorBgra *dstNextRowPtr = dstArgs.Surface.GetPointAddress(left, top); ColorBgra *srcNextRowPtr = srcArgs.Surface.GetPointAddress(left, top); byte * clipMaskNextRowPtr = (byte *)clipMask.Scan0; int rows = height; while (rows > 0) { ColorBgra.Underwrite(srcNextRowPtr, dstNextRowPtr, clipMaskNextRowPtr, width); dstNextRowPtr = (ColorBgra *)((byte *)dstNextRowPtr + dstStride); srcNextRowPtr = (ColorBgra *)((byte *)srcNextRowPtr + srcStride); clipMaskNextRowPtr = clipMaskNextRowPtr + clipMaskStride; --rows; } } } } }
public void SetBounds(RectInt32 bounds) { base.VerifyAccess(); if (base.bounds != bounds) { this.OnBoundsChanging(); base.previousBounds = base.bounds; base.bounds = bounds; this.OnBoundsChanged(); } }
private void RenderOutput(Surface dst, Rectangle[] rects, RectInt32 bounds, bool isForwards) { if (isForwards) { this.RenderOutputForwards(dst, rects, bounds); } else { this.RenderOutputBackwards(dst, rects, bounds); } }
private void SetInput(Surface src, Rectangle[] rects, RectInt32 bounds, bool isForwards) { if (isForwards) { this.SetInputForwards(src, rects, bounds); } else { this.SetInputBackwards(src, rects, bounds); } }
private void OnSnapObstacleBoundsChanged(object sender, ValueChangedEventArgs <RectInt32> e) { base.VerifyAccess(); SnapObstacle senderSO = (SnapObstacle)sender; senderSO.VerifyAccess(); RectInt32 oldValue = e.OldValue; RectInt32 bounds = senderSO.Bounds; this.UpdateDependentObstacles(senderSO, oldValue, bounds); }
private static unsafe void LoadOrSaveSurfaceRegion(Stream stream, Surface surface, RectInt32[] scans, bool trueForSave) { int length = scans.Length; if (length != 0) { void *[] voidPtrArray; ulong[] numArray; RectInt32 b = surface.Bounds <ColorBgra>(); RectInt32 bounds = RectInt32.Intersect(scans.Bounds(), b); int num5 = 0; long num6 = (bounds.Width * bounds.Height) * 4L; if (((length == 1) && (num6 <= 0xffffffffL)) && surface.IsContiguousMemoryRegion(bounds)) { voidPtrArray = new void *[] { surface.GetPointAddressUnchecked(bounds.Location.ToGdipPoint()) }; numArray = new ulong[] { num6 }; } else { for (int i = 0; i < length; i++) { RectInt32 num9 = RectInt32.Intersect(scans[i], b); if ((num9.Width != 0) && (num9.Height != 0)) { num5 += num9.Height; } } int index = 0; voidPtrArray = new void *[num5]; numArray = new ulong[num5]; for (int j = 0; j < length; j++) { RectInt32 num11 = RectInt32.Intersect(scans[j], b); if ((num11.Width != 0) && (num11.Height != 0)) { for (int k = num11.Y; k < (num11.Y + num11.Height); k++) { voidPtrArray[index] = (void *)surface.GetPointAddress(num11.X, k); numArray[index] = (ulong)(num11.Width * 4L); index++; } } } } if (trueForSave) { WriteToStreamGather(stream, voidPtrArray, numArray); } else { ReadFromStreamScatter(stream, voidPtrArray, numArray); } } }
protected override void OnRender(ISurface <ColorBgra> dstCropped, PointInt32 renderOffset) { RectInt32 num = this.Bounds <ColorBgra>(); using (RenderArgs args = new RenderArgs(dstCropped)) { args.Graphics.Clear(Color.Transparent); this.sourceOutset.Render(dstCropped, renderOffset); args.Graphics.TranslateTransform((float)-renderOffset.X, (float)-renderOffset.Y, MatrixOrder.Append); DropShadow.DrawInside(args.Graphics, new Rectangle(0, 0, base.Width, base.Height), this.shadowExtent); } }
public void CopyPixels(RectInt32?srcRect, int bufferStride, int bufferSize, IntPtr buffer) { RectInt32?nullable = srcRect; RectInt32 rect = nullable.HasValue ? nullable.GetValueOrDefault() : this.sourceRect; RectInt32 num2 = RectInt32.Offset(rect, this.sourceRect.Location); if (!this.source.Bounds().Contains(num2)) { ExceptionUtil.ThrowArgumentException(); } this.source.CopyPixels(new RectInt32?(num2), bufferStride, bufferSize, buffer); }
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)); }
private void InvalidateCancelledTiles(IEnumerable <PointInt32> tileOffsets) { if (!this.IsDisposed) { base.VerifyAccess(); foreach (PointInt32 num in tileOffsets) { RectInt32 tileSourceRect = this.tileMathHelper.GetTileSourceRect(num); this.Invalidate(tileSourceRect); } } }
internal SnapObstacle(string name, RectInt32 bounds, PaintDotNet.Snap.SnapRegion snapRegion, bool stickyEdges, int snapProximity, int snapDistance, ISnapObstaclePersist persistenceHandler) { this.name = name; this.bounds = bounds; this.previousBounds = bounds; this.snapRegion = snapRegion; this.stickyEdges = stickyEdges; this.snapProximity = snapProximity; this.snapDistance = snapDistance; this.enabled = true; this.persistenceHandler = persistenceHandler; }
public bool IsRegionCurrent(RectInt32 canvasRect) { base.VerifyAccess(); foreach (PointInt32 num in this.tileMathHelper.EnumerateTileOffsets(canvasRect)) { if ((!this.isDeviceBitmapCurrent[num.Y][num.X] || (this.deviceBitmaps[num.Y][num.X] == null)) || !this.tileCache.IsTileValid(num)) { return(false); } } return(true); }
public static RectInt32[] ToRectInt32Array(this Rectangle[] array) { if (array.Length == 0) { return(Array.Empty <RectInt32>()); } RectInt32[] numArray = new RectInt32[array.Length]; for (int i = 0; i < numArray.Length; i++) { numArray[i] = array[i].ToRectInt32(); } return(numArray); }
public void BeforeRender(RectFloat clipRect) { if ((!this.afterRenderCalled || this.beforeRenderCalled) || this.renderCalled) { throw new PaintDotNet.InternalErrorException(); } this.afterRenderCalled = false; this.beforeRenderCalled = true; bool flag = this.canvasView.RenderTarget.IsSupported(RenderTargetType.Software, null, null, null); if (flag || this.IsActive) { this.renderStopwatch.Restart(); RectInt32 num2 = RectInt32.Intersect(clipRect.Int32Bound, this.owner.Document.Bounds()); bool flag2 = false; if (num2.HasPositiveArea) { PointInt32 num7; PointInt32[] array = this.nonCurrentTileOffsets.ToArrayEx <PointInt32>(); this.nonCurrentTileOffsets.Clear(); PointInt32 sourcePt = PointDouble.Round(this.owner.Owner.MouseLocation, MidpointRounding.AwayFromZero); PointInt32 comparand = this.tileMathHelper.ConvertSourcePointToTileOffset(sourcePt); CompareTileOffsetsByDistance comparer = new CompareTileOffsetsByDistance(comparand); ListUtil.Sort <PointInt32, ArrayStruct <PointInt32>, CompareTileOffsetsByDistance>(array.AsStruct <PointInt32>(), comparer); DequeSet <PointInt32> set = new DequeSet <PointInt32>(array); int count = set.Count; while (set.TryDequeue(out num7)) { if (!this.isDeviceBitmapCurrent[num7.Y][num7.X]) { if (flag2) { this.nonCurrentTileOffsets.TryEnqueue(num7); } else { if (!this.TryUpdateDeviceBitmap(num7)) { this.nonCurrentTileOffsets.TryEnqueue(num7); flag2 = true; } if ((!flag2 && !flag) && (this.renderStopwatch.ElapsedMilliseconds > 0x7fffffffffffffffL)) { flag2 = true; } } } } } } }
internal void NotifyTileCacheInvalidated(DocumentCanvasTileCache tileCache, RectInt32 sourceRect) { int mipLevel = tileCache.MipLevel; this.mipLayers[mipLevel].NotifyTileCacheInvalidated(sourceRect); if (this.mipLayers[mipLevel].IsActive) { RectInt32 num4 = RectInt32.Intersect(this.canvasView.GetVisibleCanvasBounds().Int32Bound, sourceRect); if (num4.HasPositiveArea) { this.tileCaches[mipLevel].QueueInvalidTilesForRendering(num4, true); } } }
public MazeGenerator(int Width, int Height, IFeedback Handler) { // port from http://en.wikipedia.org/wiki/Image:Maze.png this.Width = Width; this.Height = Height; clip = new RectInt32 { Width = Width, Height = Height }; int x, y, n, d; int[] dx = { 0, 0, -1, 1 }; //int[] dy = { -1, 1, Convert.ToInt32(0), Convert.ToInt32(0) }; int[] dy = { -1, 1, 0, 0 }; int[] todo = new int[Width * Height]; int todonum = 0; /* We want to create a maze on a grid. */ maze = new int[Width][]; /* We start with a grid full of walls. */ for (x = 0; x < Width; x++) { maze[x] = new int[Height]; for (y = 0; y < Height; y++) { var p = new PointInt32 { X = x, Y = y }; if (clip.IsBorder(p)) { maze[x][y] = 32; } else { maze[x][y] = 63; } } } /* Select any square of the grid, to start with. */ x = ToInt32(1 + random() * (Width - 2)); y = ToInt32(1 + random() * (Height - 2)); /* Mark this square as connected to the maze. */ maze[x][y] &= ~48; /* Remember the surrounding squares, as we will */ for (d = 0; d < 4; d++) if ((maze[x + dx[d]][y + dy[d]] & 16) != 0) { /* want to connect them to the maze. */ /* alternately, you could use a struct to store the two integers * this would result in easier to read code, though not as speedy * of course, if you were worried about speed, you wouldn't be using Java * you could also use a single integer which represents (x + y * width) * this would actually be faster than the current approach * - quin/10-24-06 * Actually, the former wouldn't work in Java- there's no such thing as a * struct. It's a class or nothing, I'm afraid. * - Jae Armstrong/23-03-07 */ todo[todonum++] = ((x + dx[d]) << 16) | (y + dy[d]); maze[x + dx[d]][y + dy[d]] &= ~16; } /* We won't be finished until all is connected. */ while (todonum > 0) { if (Handler != null) Handler.Invoke("todonum = " + todonum); /* We select one of the squares next to the maze. */ n = ToInt32(random() * todonum); x = todo[n] >> 16; /* the top 2 bytes of the data */ y = todo[n] & 65535; /* the bottom 2 bytes of the data */ /* We will connect it, so remove it from the queue. */ todonum--; todo[n] = todo[todonum]; /* Select a direction, which leads to the maze. */ d = ToInt32(random() * 4); if ((maze[x + dx[d]][y + dy[d]] & 32) != 0) d = (d + 1) % dx.Length; if ((maze[x + dx[d]][y + dy[d]] & 32) != 0) d = (d + 1) % dx.Length; if ((maze[x + dx[d]][y + dy[d]] & 32) != 0) d = (d + 1) % dx.Length; /* Connect this square to the maze. */ maze[x][y] &= ~((1 << d) | 32); maze[x + dx[d]][y + dy[d]] &= ~(1 << (d ^ 1)); /* Remember the surrounding squares, which aren't */ for (d = 0; d < 4; d++) if ((maze[x + dx[d]][y + dy[d]] & 16) != 0) { /* connected to the maze, and aren't yet queued to be. */ todo[todonum++] = ((x + dx[d]) << 16) | (y + dy[d]); maze[x + dx[d]][y + dy[d]] &= ~16; } /* Repeat until finished. */ } /* One may want to add an entrance and exit. */ maze[1][1] &= ~1; maze[Width - 2][Height - 2] &= ~2; }