コード例 #1
0
        public void PointAddition()
        {
            //var calculator = new CalculatorInt32();
            var p1 = new PointInt32(1, 1);
            var p2 = new PointInt32(2, 2);

            //var p3 = calculator.AddPoints(p1, p2);
            var p3 = p1 + p2;

            Assert.AreEqual(p3.X, 3);
            Assert.AreEqual(p3.Y, 3);
        }
コード例 #2
0
ファイル: EuclideanDistance.cs プロジェクト: svejdo1/astar
        public float GetCost(ITileMap map, IMover mover, PointInt32 point, PointInt32 start, PointInt32 target)
        {
            float dx = target.X - point.X;
            float dy = target.Y - point.Y;

            return((float)System.Math.Sqrt((double)((dx * dx) + (dy * dy))) * m_Coefficient);
        }
コード例 #3
0
 protected override void OnRender(ISurface <ColorBgra> dstContent, ISurface <ColorAlpha8> dstMask, PointInt32 renderOffset)
 {
     base.ThrowIfCancellationRequested();
     this.renderer.Render(dstContent, renderOffset);
 }
コード例 #4
0
        private unsafe void RenderTileWorkItem(PointInt32 tileOffset)
        {
            IBitmap <ColorPbgra32> bitmap;
            bool      isCancelled = false;
            bool      flag        = false;
            Exception error       = null;

            isCancelled |= this.IsTileRenderingCancelled(tileOffset);
            if (isCancelled)
            {
                bitmap = null;
            }
            else
            {
                RectInt32 tileSourceRect = this.tileMathHelper.GetTileSourceRect(tileOffset);
                SizeInt32 tileBufferSize = this.GetTileBufferSize(tileOffset);
                bitmap = RetryManager.Eval <IBitmap <ColorPbgra32> >(3, () => BitmapAllocator.Pbgra32.Allocate(tileBufferSize, AllocationOptions.Default), delegate(Exception _) {
                    CleanupManager.RequestCleanup();
                    Thread.Sleep(200);
                    CleanupManager.WaitForPendingCleanup();
                }, delegate(AggregateException ex) {
                    throw new AggregateException($"could not allocate a bitmap of size {tileBufferSize.Width} x {tileBufferSize.Height}", ex).Flatten();
                });
                if (this.source != null)
                {
                    try
                    {
                        isCancelled |= this.IsTileRenderingCancelled(tileOffset);
                        if (!isCancelled)
                        {
                            using (IBitmapLock <ColorPbgra32> @lock = bitmap.Lock <ColorPbgra32>(BitmapLockOptions.ReadWrite))
                            {
                                if (this.mipLevel == 0)
                                {
                                    this.source.CopyPixels(new RectInt32?(tileSourceRect), @lock);
                                    RenderingKernels.ConvertBgra32ToPbgra32((uint *)@lock.Scan0, tileBufferSize.Width, tileBufferSize.Height, @lock.Stride);
                                    flag = true;
                                }
                                else
                                {
                                    BitmapInterpolationMode linear;
                                    if (!this.isHighQuality)
                                    {
                                        linear = BitmapInterpolationMode.Linear;
                                    }
                                    else if (this.mipLevel == 1)
                                    {
                                        linear = BitmapInterpolationMode.Linear;
                                    }
                                    else
                                    {
                                        linear = BitmapInterpolationMode.Fant;
                                    }
                                    IImagingFactory    instance    = ImagingFactory.Instance;
                                    ICancellationToken cancelToken = CancellationTokenUtil.Create((Func <bool>)(() => (isCancelled | this.IsTileRenderingCancelled(tileOffset))));
                                    int copyHeightLog2             = Math.Max(3, 7 - this.mipLevel);
                                    using (ClippedBitmapSource <ColorBgra32> source2 = new ClippedBitmapSource <ColorBgra32>(this.source, tileSourceRect))
                                    {
                                        using (CancellableBitmapSource <ColorBgra32> source3 = new CancellableBitmapSource <ColorBgra32>(source2, r => this.tileMathHelper.EnumerateTilesClippedToSourceRect(r), null, cancelToken))
                                        {
                                            using (IBitmapSource <ColorPbgra32> source4 = CreateBufferedTileScaler(instance, source3, tileBufferSize.Width, tileBufferSize.Height, linear))
                                            {
                                                using (CancellableBitmapSource <ColorPbgra32> source5 = new CancellableBitmapSource <ColorPbgra32>(source4, r => TileRectSplitter(r, ((int)1) << copyHeightLog2), null, cancelToken))
                                                {
                                                    try
                                                    {
                                                        source5.CopyPixels <ColorPbgra32>(@lock);
                                                        flag = true;
                                                    }
                                                    catch (OperationCanceledException exception2)
                                                    {
                                                        error       = exception2;
                                                        isCancelled = true;
                                                    }
                                                    catch (Exception exception3)
                                                    {
                                                        error = exception3;
                                                        throw;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                isCancelled |= this.IsTileRenderingCancelled(tileOffset);
                                if (isCancelled)
                                {
                                    flag = false;
                                }
                            }
                            if (!flag)
                            {
                                DisposableUtil.Free <IBitmap <ColorPbgra32> >(ref bitmap);
                            }
                        }
                    }
                    catch (OperationCanceledException exception4)
                    {
                        error       = exception4;
                        isCancelled = true;
                    }
                    catch (Exception exception5)
                    {
                        error        = exception5;
                        isCancelled |= this.IsTileRenderingCancelled(tileOffset);
                        if (!isCancelled)
                        {
                            using (IDrawingContext context = DrawingContext.FromBitmap(bitmap, FactorySource.PerThread))
                            {
                                context.Clear(new ColorRgba128Float?((ColorRgba128Float)Colors.White));
                                string text = exception5.ToString();
                                using (ISystemFonts fonts = new SystemFonts(true))
                                {
                                    TextLayout textLayout = UIText.CreateLayout(context, text, fonts.Caption, null, HotkeyRenderMode.Ignore, (double)bitmap.Size.Width, 65535.0);
                                    textLayout.FontSize    *= 0.6;
                                    textLayout.WordWrapping = WordWrapping.Wrap;
                                    context.DrawTextLayout(PointDouble.Zero, textLayout, SolidColorBrushCache.Get((ColorRgba128Float)Colors.Black), DrawTextOptions.None);
                                }
                            }
                            flag = true;
                        }
                    }
                }
            }
            isCancelled |= this.IsTileRenderingCancelled(tileOffset);
            if (isCancelled)
            {
                DisposableUtil.Free <IBitmap <ColorPbgra32> >(ref bitmap);
            }
            RenderedTileInfo info = new RenderedTileInfo(bitmap, !isCancelled && (bitmap > null), error);

            if (!this.tilesRenderedQueue.TryEnqueue(tileOffset, info))
            {
                ExceptionUtil.ThrowInternalErrorException("Could not enqueue to this.tilesRenderedQueue");
            }
            if (Interlocked.Exchange(ref this.isProcessTileRenderedQueueQueued, 1) == 0)
            {
                this.syncContext.Post(this.processTileRenderedQueueCallback);
            }
        }
コード例 #5
0
 public bool IsTileValid(PointInt32 tileOffset) =>
 this.IsTileValid(tileOffset.X, tileOffset.Y);
コード例 #6
0
 private SizeInt32 GetTileBufferSize(PointInt32 tileOffset) =>
 this.GetTileBufferSize(tileOffset.X, tileOffset.Y);
コード例 #7
0
 private TileData GetTileData(PointInt32 tileOffset) =>
 this.tileOffsetToTileDataMap.GetOrAdd(tileOffset, to => new TileData(to));
コード例 #8
0
        private bool PerformActionImpl()
        {
            PointInt32 num2;
            RectInt32  num3;

            if (this.clipData == null)
            {
                try
                {
                    using (new WaitCursorChanger(this.documentWorkspace))
                    {
                        CleanupManager.RequestCleanup();
                        this.clipData = PdnClipboard.GetDataObject();
                    }
                }
                catch (OutOfMemoryException exception)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception);
                    return(false);
                }
                catch (Exception exception2)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception2);
                    return(false);
                }
            }
            bool handled = false;

            if (this.documentWorkspace.Tool != null)
            {
                this.documentWorkspace.Tool.PerformPaste(this.clipData, out handled);
            }
            if (handled)
            {
                return(true);
            }
            if (this.maskedSurface == null)
            {
                try
                {
                    using (new WaitCursorChanger(this.documentWorkspace))
                    {
                        this.maskedSurface = ClipboardUtil.TryGetClipboardImage(this.documentWorkspace, this.clipData);
                    }
                }
                catch (OutOfMemoryException exception3)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception3);
                    return(false);
                }
                catch (Exception exception4)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception4);
                    return(false);
                }
            }
            if (this.maskedSurface == null)
            {
                MessageBoxUtil.ErrorBox(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.NoImage"));
                return(false);
            }
            RectInt32 cachedGeometryMaskScansBounds = this.maskedSurface.GetCachedGeometryMaskScansBounds();

            if ((cachedGeometryMaskScansBounds.Width > this.documentWorkspace.Document.Width) || (cachedGeometryMaskScansBounds.Height > this.documentWorkspace.Document.Height))
            {
                Surface surface;
                try
                {
                    using (new WaitCursorChanger(this.documentWorkspace))
                    {
                        surface = CreateThumbnail(this.maskedSurface);
                    }
                }
                catch (OutOfMemoryException)
                {
                    surface = null;
                }
                DialogResult result           = ShowExpandCanvasTaskDialog(this.documentWorkspace, surface);
                int          activeLayerIndex = this.documentWorkspace.ActiveLayerIndex;
                ColorBgra    background       = this.documentWorkspace.ToolSettings.SecondaryColor.Value;
                if (result != DialogResult.Cancel)
                {
                    if (result != DialogResult.Yes)
                    {
                        if (result != DialogResult.No)
                        {
                            throw ExceptionUtil.InvalidEnumArgumentException <DialogResult>(result, "dr");
                        }
                        goto Label_031D;
                    }
                    using (new PushNullToolMode(this.documentWorkspace))
                    {
                        int      width    = Math.Max(cachedGeometryMaskScansBounds.Width, this.documentWorkspace.Document.Width);
                        Size     newSize  = new Size(width, Math.Max(cachedGeometryMaskScansBounds.Height, this.documentWorkspace.Document.Height));
                        Document document = CanvasSizeAction.ResizeDocument(this.documentWorkspace.Document, newSize, AnchorEdge.TopLeft, background);
                        if (document == null)
                        {
                            return(false);
                        }
                        SelectionHistoryMemento       memento  = new SelectionHistoryMemento(null, null, this.documentWorkspace);
                        ReplaceDocumentHistoryMemento memento2 = new ReplaceDocumentHistoryMemento(CanvasSizeAction.StaticName, CanvasSizeAction.StaticImage, this.documentWorkspace);
                        this.documentWorkspace.Document = document;
                        HistoryMemento[]       actions  = new HistoryMemento[] { memento, memento2 };
                        CompoundHistoryMemento memento3 = new CompoundHistoryMemento(CanvasSizeAction.StaticName, CanvasSizeAction.StaticImage, actions);
                        this.documentWorkspace.History.PushNewMemento(memento3);
                        this.documentWorkspace.ActiveLayer = (Layer)this.documentWorkspace.Document.Layers[activeLayerIndex];
                        goto Label_031D;
                    }
                }
                return(false);
            }
Label_031D:
            num3 = this.documentWorkspace.Document.Bounds();
            RectDouble visibleDocumentRect = this.documentWorkspace.VisibleDocumentRect;
            RectInt32? nullable            = visibleDocumentRect.Int32Inset();
            RectDouble num5 = nullable.HasValue ? ((RectDouble)nullable.Value) : visibleDocumentRect;
            RectInt32  num6 = num5.Int32Bound;

            if (num5.Contains(cachedGeometryMaskScansBounds))
            {
                num2 = new PointInt32(0, 0);
            }
            else
            {
                int num12;
                int num13;
                int num16;
                int num17;
                if (cachedGeometryMaskScansBounds.X < num5.Left)
                {
                    num12 = -cachedGeometryMaskScansBounds.X + num6.X;
                }
                else if (cachedGeometryMaskScansBounds.Right > num6.Right)
                {
                    num12 = (-cachedGeometryMaskScansBounds.X + num6.Right) - cachedGeometryMaskScansBounds.Width;
                }
                else
                {
                    num12 = 0;
                }
                if (cachedGeometryMaskScansBounds.Y < num5.Top)
                {
                    num13 = -cachedGeometryMaskScansBounds.Y + num6.Y;
                }
                else if (cachedGeometryMaskScansBounds.Bottom > num6.Bottom)
                {
                    num13 = (-cachedGeometryMaskScansBounds.Y + num6.Bottom) - cachedGeometryMaskScansBounds.Height;
                }
                else
                {
                    num13 = 0;
                }
                PointInt32 num14 = new PointInt32(num12, num13);
                RectInt32  num15 = new RectInt32(cachedGeometryMaskScansBounds.X + num14.X, cachedGeometryMaskScansBounds.Y + num14.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height);
                if (num15.X < 0)
                {
                    num16 = num12 - num15.X;
                }
                else
                {
                    num16 = num12;
                }
                if (num15.Y < 0)
                {
                    num17 = num13 - num15.Y;
                }
                else
                {
                    num17 = num13;
                }
                PointInt32 num18 = new PointInt32(num16, num17);
                RectInt32  rect  = new RectInt32(cachedGeometryMaskScansBounds.X + num18.X, cachedGeometryMaskScansBounds.Y + num18.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height);
                if (num3.Contains(rect))
                {
                    num2 = num18;
                }
                else
                {
                    PointInt32 num20 = num18;
                    if (rect.Right > num3.Right)
                    {
                        int num21 = rect.Right - num3.Right;
                        int num22 = Math.Min(num21, rect.Left);
                        num20.X -= num22;
                    }
                    if (rect.Bottom > num3.Bottom)
                    {
                        int num23 = rect.Bottom - num3.Bottom;
                        int num24 = Math.Min(num23, rect.Top);
                        num20.Y -= num24;
                    }
                    num2 = num20;
                }
            }
            RectInt32 b           = this.documentWorkspace.VisibleDocumentRect.Int32Bound;
            RectInt32 a           = new RectInt32(cachedGeometryMaskScansBounds.X + num2.X, cachedGeometryMaskScansBounds.Y + num2.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height);
            bool      hasZeroArea = RectInt32.Intersect(a, b).HasZeroArea;

            MoveTool.BeginPaste(this.documentWorkspace, PdnResources.GetString("CommonAction.Paste"), PdnResources.GetImageResource("Icons.MenuEditPasteIcon.png"), this.maskedSurface.SurfaceReadOnly, this.maskedSurface.GeometryMask, num2);
            if (hasZeroArea)
            {
                PointInt32  num25 = new PointInt32(b.Left + (b.Width / 2), b.Top + (b.Height / 2));
                PointInt32  num26 = new PointInt32(a.Left + (a.Width / 2), a.Top + (a.Height / 2));
                SizeInt32   num27 = new SizeInt32(num26.X - num25.X, num26.Y - num25.Y);
                PointDouble documentScrollPosition = this.documentWorkspace.DocumentScrollPosition;
                PointDouble num29 = new PointDouble(documentScrollPosition.X + num27.Width, documentScrollPosition.Y + num27.Height);
                this.documentWorkspace.DocumentScrollPosition = num29;
            }
            return(true);
        }
コード例 #9
0
 protected override void OnRenderContent(ISurface <ColorBgra> dstContent, PointInt32 renderOffset)
 {
     this.brushRenderer.Render(dstContent, renderOffset);
 }
コード例 #10
0
        private void DrawLine(PointInt32 endPoint)
        {
            foreach (PointInt32 p in WorldRenderer.DrawLine(_startPoint, endPoint))
            {
                if (_selection.SelectionVisibility == Visibility.Visible)
                {
                    // if selection is active, and point is not inside, skip point
                    if (!_selection.Rectangle.Contains(p))
                    {
                        continue;
                    }
                }

                // center
                int x0 = p.X - _properties.Offset.X;
                int y0 = p.Y - _properties.Offset.Y;

                if (_properties.BrushShape == ToolBrushShape.Square)
                {
                    if (_properties.IsOutline)
                    {
                        TilePicker outline = Utility.DeepCopy(_tilePicker);
                        outline.Wall.IsActive = false;

                        // eraise a center section
                        TilePicker eraser = Utility.DeepCopy(_tilePicker);
                        eraser.IsEraser      = true;
                        eraser.Wall.IsActive = false; // don't erase the wall for the interrior

                        TilePicker wall = Utility.DeepCopy(_tilePicker);
                        wall.Tile.IsActive = false;



                        var interior = new Int32Rect(x0 + _properties.OutlineThickness,
                                                     y0 + _properties.OutlineThickness,
                                                     _properties.Width - (_properties.OutlineThickness * 2),
                                                     _properties.Height - (_properties.OutlineThickness * 2));

                        // Erase center
                        FillRectangle(interior, ref eraser);
                        // Fill center
                        if (wall.Wall.IsActive)
                        {
                            FillRectangle(interior, ref wall);
                        }
                        // Draw outline
                        if (outline.Tile.IsActive)
                        {
                            for (int i = 0; i < _properties.OutlineThickness; i++)
                            {
                                DrawRectangle(new Int32Rect(x0 + i, y0 + i, _properties.Width - (i * 2) - 1, _properties.Height - (i * 2) - 1), ref outline);
                            }
                        }
                    }
                    else
                    {
                        FillRectangle(new Int32Rect(x0, y0, _properties.Width, _properties.Height), ref _tilePicker);
                    }
                }
                else if (_properties.BrushShape == ToolBrushShape.Round)
                {
                    if (_properties.IsOutline)
                    {
                        TilePicker outline = Utility.DeepCopy(_tilePicker);
                        outline.Wall.IsActive = false;

                        // eraise a center section
                        TilePicker eraser = Utility.DeepCopy(_tilePicker);
                        eraser.IsEraser      = true;
                        eraser.Wall.IsActive = false; // don't erase the wall for the interrior

                        TilePicker wall = Utility.DeepCopy(_tilePicker);
                        wall.Tile.IsActive = false;


                        // Draw outline
                        if (outline.Tile.IsActive)
                        {
                            FillEllipse(x0, y0, x0 + _properties.Width, y0 + _properties.Height, ref outline);
                        }

                        // Erase center
                        FillEllipse(x0 + _properties.OutlineThickness,
                                    y0 + _properties.OutlineThickness,
                                    x0 + _properties.Width - _properties.OutlineThickness,
                                    y0 + _properties.Height - _properties.OutlineThickness, ref eraser);
                        // Fill center
                        if (wall.Wall.IsActive)
                        {
                            FillEllipse(x0 + _properties.OutlineThickness,
                                        y0 + _properties.OutlineThickness,
                                        x0 + _properties.Width - _properties.OutlineThickness,
                                        y0 + _properties.Height - _properties.OutlineThickness, ref wall);
                        }



                        eraser = null;
                    }
                    else
                    {
                        FillEllipse(x0, y0, x0 + _properties.Width, y0 + _properties.Height, ref _tilePicker);
                    }
                }
                if (_properties.IsOutline)
                {
                    _renderer.UpdateWorldImage(new Int32Rect(x0, y0, _properties.Width + 1, _properties.Height + 1));
                }
            }
        }
コード例 #11
0
		public override void ClipViewPosition(Point p)
		{
			if (ViewPositionLock != null)
			{
				p.x = ViewPositionLock.x;
				p.y = ViewPositionLock.y;

				return;
			}

			var Walls = this.Map.WallMap;

			if (Walls == null)
				return;

			const double PlayerRadiusMargin = 0.3;

			var fPlayerX = p.x;
			var fPlayerY = p.y;

			var c = new PointInt32
			{
				X = (int)Math.Floor(p.x),
				Y = (int)Math.Floor(p.y)
			};

			var TILE_SIZE = 1.0;

			var PositionInWall =
				 new Point
				 {
					 x = fPlayerX % TILE_SIZE,
					 y = fPlayerY % TILE_SIZE
				 };


			var TileTop = Walls[c.X, c.Y - 1];
			var TileLeft = Walls[c.X - 1, c.Y];
			var TileRight = Walls[c.X + 1, c.Y];
			var TileBottom = Walls[c.X, c.Y + 1];


			var CurrentMapTile = Walls[c.X, c.Y];

			if (CurrentMapTile != 0)
			{
				// we are inside a wall
				// push us out of there

				#region Dia
				var A = PositionInWall.x > PositionInWall.y;
				var B = PositionInWall.x > (TILE_SIZE - PositionInWall.y);

				var DiaClipLeft = !A && !B;
				var DiaClipRight = A && B;
				var DiaClipTop = A && !B;
				var DiaClipBottom = !A && B;
				#endregion

				#region Alt
				var C = PositionInWall.x > (TILE_SIZE / 2);
				var D = PositionInWall.y > (TILE_SIZE / 2);

				var AltClipTopLeft = !C && !D;
				var AltClipBottomLeft = !C && D;
				var AltClipTopRight = C && !D;
				var AltClipBottomRight = C && D;
				#endregion


				var ClipLeft = DiaClipLeft;

				if (TileTop != 0) ClipLeft |= AltClipTopLeft;
				if (TileBottom != 0) ClipLeft |= AltClipBottomLeft;

				var ClipRight = DiaClipRight;

				if (TileTop != 0) ClipRight |= AltClipTopRight;
				if (TileBottom != 0) ClipRight |= AltClipBottomRight;

				var ClipTop = DiaClipTop;

				if (TileLeft != 0) ClipTop |= AltClipTopLeft;
				if (TileRight != 0) ClipTop |= AltClipTopRight;

				var ClipBottom = DiaClipBottom;

				if (TileLeft != 0) ClipBottom |= AltClipBottomLeft;
				if (TileRight != 0) ClipBottom |= AltClipBottomRight;



				if (ClipLeft)
					fPlayerX = fPlayerX.Min(c.X * TILE_SIZE - PlayerRadiusMargin);
				else if (ClipRight)
					fPlayerX = fPlayerX.Max((c.X + 1) * TILE_SIZE + PlayerRadiusMargin);

				if (ClipTop)
					fPlayerY = fPlayerY.Min(c.Y * TILE_SIZE - PlayerRadiusMargin);
				else if (ClipRight)
					fPlayerY = fPlayerY.Max((c.Y + 1) * TILE_SIZE + PlayerRadiusMargin);
			}
			else
			{
				// fix corners
				//
				//   *        L
				//    F      *

				if (TileLeft != 0)
					fPlayerX = fPlayerX.Max(c.X * TILE_SIZE + PlayerRadiusMargin);
				if (TileRight != 0)
					fPlayerX = fPlayerX.Min((c.X + 1) * TILE_SIZE - PlayerRadiusMargin);

				if (TileTop != 0)
					fPlayerY = fPlayerY.Max(c.Y * TILE_SIZE + PlayerRadiusMargin);
				if (TileBottom != 0)
					fPlayerY = fPlayerY.Min((c.Y + 1) * TILE_SIZE - PlayerRadiusMargin);

			}

			p.x = fPlayerX;
			p.y = fPlayerY;
		}
コード例 #12
0
 protected override void OnRenderMask(ISurface <ColorAlpha8> dstMask, PointInt32 renderOffset)
 {
     base.OnRenderMask(dstMask, renderOffset);
     dstMask.Multiply(this.opacity);
 }
コード例 #13
0
 protected override void OnRenderContent(ISurface <ColorBgra> dstContent, PointInt32 renderOffset)
 {
     dstContent.Clear();
 }
コード例 #14
0
        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);
        }
コード例 #15
0
ファイル: HistoryControl.cs プロジェクト: ykafia/Paint.Net4
 private PointInt32 ClientPointToViewPoint(PointInt32 pt) =>
 new PointInt32(pt.X, pt.Y + this.ScrollOffset);
コード例 #16
0
		public override void ClipViewPosition(Point p)
		{
			if (ViewPositionLock != null)
			{
				p.x = ViewPositionLock.x;
				p.y = ViewPositionLock.y;

				return;
			}

			var Walls = this.Map.WallMap;

			if (Walls == null)
				return;

			Func<Point, double, bool> RadialBump =
				(vp, vr) =>
				{

					var z = p.GetDistance(vp);

					if (z < vr)
					{
						// pump us out of that sprite

						var a = (p - vp).GetRotation();

						p.x = vp.x + Math.Cos(a) * vr;
						p.y = vp.y + Math.Sin(a) * vr;

						return true;
					}
					else
					{
						return false;
					}
				};


			#region bump on blocking sprites
			if (EnableBlockingSprites)
				foreach (var v in BlockingSprites)
				{
					RadialBump(v.Position, v.Range);
				}
			#endregion

			var fPlayerX = p.x;
			var fPlayerY = p.y;


			var c = new PointInt32
			{
				X = (int)Math.Floor(p.x),
				Y = (int)Math.Floor(p.y)
			};

			var TILE_SIZE = 1.0;

			var PositionInWall =
				 new Point
				 {
					 x = fPlayerX % TILE_SIZE,
					 y = fPlayerY % TILE_SIZE
				 };


			var TileTop = Walls[c.X, c.Y - 1];
			var TileLeft = Walls[c.X - 1, c.Y];
			var TileRight = Walls[c.X + 1, c.Y];
			var TileBottom = Walls[c.X, c.Y + 1];


			var CurrentMapTile = Walls[c.X, c.Y];

			if (CurrentMapTile != 0)
			{
				// we are inside a wall
				// push us out of there

				#region Dia
				var A = PositionInWall.x > PositionInWall.y;
				var B = PositionInWall.x > (TILE_SIZE - PositionInWall.y);

				var DiaClipLeft = !A && !B;
				var DiaClipRight = A && B;
				var DiaClipTop = A && !B;
				var DiaClipBottom = !A && B;
				#endregion

				#region Alt
				var C = PositionInWall.x > (TILE_SIZE / 2);
				var D = PositionInWall.y > (TILE_SIZE / 2);

				var AltClipTopLeft = !C && !D;
				var AltClipBottomLeft = !C && D;
				var AltClipTopRight = C && !D;
				var AltClipBottomRight = C && D;
				#endregion


				var ClipLeft = DiaClipLeft;

				if (TileTop != 0) ClipLeft |= AltClipTopLeft;
				if (TileBottom != 0) ClipLeft |= AltClipBottomLeft;

				var ClipRight = DiaClipRight;

				if (TileTop != 0) ClipRight |= AltClipTopRight;
				if (TileBottom != 0) ClipRight |= AltClipBottomRight;

				var ClipTop = DiaClipTop;

				if (TileLeft != 0) ClipTop |= AltClipTopLeft;
				if (TileRight != 0) ClipTop |= AltClipTopRight;

				var ClipBottom = DiaClipBottom;

				if (TileLeft != 0) ClipBottom |= AltClipBottomLeft;
				if (TileRight != 0) ClipBottom |= AltClipBottomRight;



				if (ClipLeft)
					fPlayerX = fPlayerX.Min(c.X * TILE_SIZE - PlayerRadiusMargin);
				else if (ClipRight)
					fPlayerX = fPlayerX.Max((c.X + 1) * TILE_SIZE + PlayerRadiusMargin);

				if (ClipTop)
					fPlayerY = fPlayerY.Min(c.Y * TILE_SIZE - PlayerRadiusMargin);
				else if (ClipRight)
					fPlayerY = fPlayerY.Max((c.Y + 1) * TILE_SIZE + PlayerRadiusMargin);
			}
			else
			{
				// fix corners
				//
				//   *        L
				//    F      *

				if (TileLeft != 0)
					fPlayerX = fPlayerX.Max(c.X * TILE_SIZE + PlayerRadiusMargin);
				if (TileRight != 0)
					fPlayerX = fPlayerX.Min((c.X + 1) * TILE_SIZE - PlayerRadiusMargin);

				if (TileTop != 0)
					fPlayerY = fPlayerY.Max(c.Y * TILE_SIZE + PlayerRadiusMargin);
				if (TileBottom != 0)
					fPlayerY = fPlayerY.Min((c.Y + 1) * TILE_SIZE - PlayerRadiusMargin);





			}

			p.x = fPlayerX;
			p.y = fPlayerY;

		
			BumpCounter++;

			var p_top_left = new Point(c.X, c.Y);
			var p_top_right = new Point(c.X + 1, c.Y);
			var p_bottom_right = new Point(c.X + 1, c.Y + 1);
			var p_bottom_left = new Point(c.X, c.Y + 1);

			var z_top_left = p.GetDistance(p_top_left);
			var z_top_right = p.GetDistance(p_top_right);
			var z_bottom_right = p.GetDistance(p_bottom_right);
			var z_bottom_left = p.GetDistance(p_bottom_left);

			var is_top_left = z_top_left < PlayerRadiusMargin;
			var is_top_right = z_top_right < PlayerRadiusMargin;
			var is_bottom_right = z_bottom_right < PlayerRadiusMargin;
			var is_bottom_left = z_bottom_left < PlayerRadiusMargin;

			// this assumes there are always corners.
			// if we add larger rooms we need to adjust this here

			//WriteLine(BumpCounter + " " + new { is_top_left, is_top_right, is_bottom_right, is_bottom_left });

			if (is_top_left)
				if (!RadialBump(p_top_left, PlayerRadiusMargin))
					WriteLine("fail p_top_left");

			if (is_top_right)
				if (!RadialBump(p_top_right, PlayerRadiusMargin))
					WriteLine("fail p_top_right");

			if (is_bottom_right)
				if (!RadialBump(p_bottom_right, PlayerRadiusMargin))
					WriteLine("fail p_bottom_right");

			if (is_bottom_left)
				if (!RadialBump(p_bottom_left, PlayerRadiusMargin))
					WriteLine("fail bottom_left");
		}
コード例 #17
0
 public static void FillStencilFromPoint <TBitVector2D>(IRenderer <ColorBgra> sampleSource, TBitVector2D stencilBuffer, PointInt32 startPt, byte tolerance, CancellationToken cancelToken, out RectInt32 bounds) where TBitVector2D : IBitVector2D
 {
     FillStencilFromPoint <TBitVector2D>(sampleSource, stencilBuffer, startPt, tolerance, CancellationTokenUtil.Create(cancelToken), out bounds);
 }
コード例 #18
0
        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));
            }
            Func <bool> isCancellationRequestedFn = () => base.IsCancellationRequested;
            ColorBgra   pointSlow = this.sampleSource.GetPointSlow(pt);

            if (base.IsCancellationRequested)
            {
                return(null);
            }
            if (this.changes.FloodMode == FloodMode.Global)
            {
                renderer = new FillStencilByColorRenderer(this.sampleSource, pointSlow, tolerance, isCancellationRequestedFn);
            }
            else
            {
                RectInt32         num5;
                BitVector2D       source        = new BitVector2D(this.sampleSource.Width, this.sampleSource.Height);
                BitVector2DStruct stencilBuffer = new BitVector2DStruct(source);
                source.Clear(true);
                if (base.IsCancellationRequested)
                {
                    return(null);
                }
                foreach (RectInt32 num6 in this.changes.ClippingMask.EnumerateInteriorScans())
                {
                    source.Set(num6, false);
                    if (base.IsCancellationRequested)
                    {
                        return(null);
                    }
                }
                BitVector2D other = source.Clone();
                if (base.IsCancellationRequested)
                {
                    return(null);
                }
                FloodFillAlgorithm.FillStencilFromPoint <BitVector2DStruct>(this.sampleSource, stencilBuffer, pt, tolerance, isCancellationRequestedFn, out num5);
                if (base.IsCancellationRequested)
                {
                    return(null);
                }
                source.Xor(other);
                if (base.IsCancellationRequested)
                {
                    return(null);
                }
                renderer = new BitVector2DToAlpha8Renderer <BitVector2DStruct>(stencilBuffer);
            }
            if (this.changes.Antialiasing)
            {
                return(new FeatheredMaskRenderer(this.sampleSource, pointSlow, renderer, tolerance, isCancellationRequestedFn));
            }
            return(renderer);
        }
コード例 #19
0
        public void PasteBufferIntoWorld(World world, ClipboardBuffer buffer, PointInt32 anchor)
        {
            for (int x = 0; x < buffer.Size.W; x++)
            {
                for (int y = 0; y < buffer.Size.H; y++)
                {
                    if (world.IsPointInWorld(x + anchor.X, y + anchor.Y))
                    {
                        HistMan.AddTileToBuffer(x + anchor.X, y + anchor.Y, ref world.Tiles[x + anchor.X, y + anchor.Y]);
                        Tile curTile = (Tile)buffer.Tiles[x, y].Clone();

                        // Remove overwritten chests data
                        if (world.Tiles[x + anchor.X, y + anchor.Y].Type == 21)
                        {
                            var data = world.GetChestAtTile(x + anchor.X, y + anchor.Y);
                            if (data != null)
                            {
                                world.Chests.Remove(data);
                            }
                        }

                        // Remove overwritten sign data
                        if (world.Tiles[x + anchor.X, y + anchor.Y].Type == 55 || world.Tiles[x + anchor.X, y + anchor.Y].Type == 85)
                        {
                            var data = world.GetSignAtTile(x + anchor.X, y + anchor.Y);
                            if (data != null)
                            {
                                world.Signs.Remove(data);
                            }
                        }


                        // Add new chest data
                        if (curTile.Type == 21)
                        {
                            if (world.GetChestAtTile(x + anchor.X, y + anchor.Y) == null)
                            {
                                var data = buffer.GetChestAtTile(x, y);
                                if (data != null) // allow? chest copying may not work...
                                {
                                    // Copied chest
                                    var newChest = Utility.DeepCopy(data);
                                    newChest.Location = new PointInt32(x + anchor.X, y + anchor.Y);
                                    world.Chests.Add(newChest);
                                }
                                else
                                {
                                    // Empty chest
                                    world.Chests.Add(new Chest(new PointInt32(x + anchor.X, y + anchor.Y)));
                                }
                            }
                        }

                        // Add new sign data
                        if (curTile.Type == 55 || curTile.Type == 85)
                        {
                            if (world.GetSignAtTile(x + anchor.X, y + anchor.Y) == null)
                            {
                                var data = buffer.GetSignAtTile(x, y);
                                if (data != null)
                                {
                                    // Copied sign
                                    var newSign = Utility.DeepCopy(data);
                                    newSign.Location = new PointInt32(x + anchor.X, y + anchor.Y);
                                    world.Signs.Add(newSign);
                                }
                                else
                                {
                                    world.Signs.Add(new Sign("", new PointInt32(x + anchor.X, y + anchor.Y)));
                                }
                            }
                        }

                        world.Tiles[x + anchor.X, y + anchor.Y] = curTile;
                    }
                }
            }

            HistMan.AddBufferToHistory();
        }
コード例 #20
0
ファイル: SnapDescription.cs プロジェクト: ykafia/Paint.Net4
 public SnapDescription(SnapObstacle snappedTo, HorizontalSnapEdge horizontalEdge, VerticalSnapEdge verticalEdge, PointInt32 offset) : this(snappedTo, horizontalEdge, verticalEdge, offset.X, offset.Y)
 {
 }
コード例 #21
0
			public bool Contains(PointInt32 e)
			{
				if (e.X < X)
					return false;

				if (e.X >= Width)
					return false;

				if (e.Y < Y)
					return false;

				if (e.Y >= Height)
					return false;

				return true;
			}
コード例 #22
0
 private bool IsTileRenderingCancelled(PointInt32 tileOffset) =>
 this.tilesRenderingCancelledSet.Contains(tileOffset);
コード例 #23
0
		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;

		}
コード例 #24
0
 public bool ProcessTileRenderedQueue()
 {
     base.VerifyAccess();
     using (this.processTileRenderedQueueRegion.UseEnterScope())
     {
         if (this.IsDisposed)
         {
             bool flag = false;
             do
             {
                 KeyValuePair <PointInt32, RenderedTileInfo> pair;
                 while (this.tilesRenderedQueue.TryDequeue(out pair))
                 {
                     DisposableUtil.Free <IBitmap <ColorPbgra32> >(ref pair.Value.Buffer);
                     flag = true;
                 }
             }while (Interlocked.Exchange(ref this.isProcessTileRenderedQueueQueued, 0) == 1);
             return(flag);
         }
         if (Interlocked.Exchange(ref this.isProcessTileRenderedQueueQueued, 0) == 0)
         {
             return(false);
         }
         List <PointInt32> collection           = new List <PointInt32>();
         List <PointInt32> cancelledTileOffsets = null;
         bool flag3 = false;
         int  count = this.tilesRenderedQueue.Count;
         for (int i = 0; i < count; i++)
         {
             KeyValuePair <PointInt32, RenderedTileInfo> pair2;
             if (this.tilesRenderedQueue.TryDequeue(out pair2))
             {
                 PointInt32             key    = pair2.Key;
                 RenderedTileInfo       info2  = pair2.Value;
                 IBitmap <ColorPbgra32> buffer = info2.Buffer;
                 if (this.tilesRenderingCancelledSet.Remove(key) || !info2.Completed)
                 {
                     DisposableUtil.Free <IBitmap <ColorPbgra32> >(ref buffer);
                     if (this.tilesRenderQueue.Contains(key))
                     {
                         flag3 = true;
                     }
                     else if (info2.Error is OperationCanceledException)
                     {
                         if (cancelledTileOffsets == null)
                         {
                             cancelledTileOffsets = new List <PointInt32>();
                         }
                         cancelledTileOffsets.Add(key);
                     }
                 }
                 else
                 {
                     if ((buffer.IsNullReference <IBitmap <ColorPbgra32> >() || buffer.IsDisposed) || !pair2.Value.Completed)
                     {
                         throw new PaintDotNet.InternalErrorException();
                     }
                     IBitmap <ColorPbgra32> disposeMe = this.tileBuffers[key.Y][key.X];
                     DisposableUtil.Free <IBitmap <ColorPbgra32> >(ref disposeMe);
                     this.tileBuffers[key.Y][key.X] = buffer;
                     this.tileIsValid[key.Y][key.X] = true;
                     collection.Add(key);
                 }
                 if (!this.tilesRenderingSet.Remove(key))
                 {
                     throw new PaintDotNet.InternalErrorException();
                 }
             }
         }
         if (collection.Any <PointInt32>())
         {
             this.owner.NotifyTileCacheFinishedRendering <List <PointInt32> >(this, collection);
         }
         if (flag3)
         {
             this.ProcessTileRenderQueue();
         }
         if (!this.tilesRenderingSet.Any <PointInt32>())
         {
             this.owner.NotifyTileCacheIsIdle(this);
         }
         if (cancelledTileOffsets != null)
         {
             this.syncContext.Post(delegate(object _) {
                 this.InvalidateCancelledTiles(cancelledTileOffsets);
             });
         }
         return(collection.Any <PointInt32>());
     }
 }
コード例 #25
0
			public bool IsBorder(PointInt32 e)
			{
				if (e.X == X)
					return true;

				if (e.Y == Y)
					return true;

				if (e.X == X + Width - 1)
					return true;

				if (e.Y == Y + Height - 1)
					return true;

				return false;
			}
コード例 #26
0
 protected abstract void OnRender(ISurface <ColorBgra> dst, PointInt32 renderOffset);
コード例 #27
0
        protected override unsafe void OnRender(ISurface <ColorBgra> dstContent, ISurface <ColorAlpha8> dstMask, PointInt32 renderOffset)
        {
            base.ThrowIfCancellationRequested();
            int        width      = dstContent.Width;
            int        height     = dstContent.Height;
            ColorBgra *bgraPtr    = (ColorBgra *)dstContent.Scan0;
            int        num3       = dstContent.Stride - (width * 4);
            RectInt32  sourceRect = new RectInt32(renderOffset.X, renderOffset.Y, width, height);

            if (this.changes.PixelSource == MoveToolPixelSource.Bitmap)
            {
                ZeroMaskSampler baseMaskSampler = new ZeroMaskSampler();
                this.OnRenderImpl <ZeroMaskSampler>(dstContent, renderOffset, ref baseMaskSampler);
            }
            else if (this.changes.LeaveCopyBehind)
            {
                ZeroMaskSampler sampler2 = new ZeroMaskSampler();
                this.OnRenderImpl <ZeroMaskSampler>(dstContent, renderOffset, ref sampler2);
            }
            else
            {
                using (BaseMaskSampler sampler3 = new BaseMaskSampler(this, sourceRect))
                {
                    this.OnRenderImpl <BaseMaskSampler>(dstContent, renderOffset, ref sampler3);
                }
            }
        }
コード例 #28
0
 public Sign(string text, PointInt32 location)
 {
     _Text     = text;
     _Location = location;
 }
コード例 #29
0
        private unsafe void OnRenderImpl <TMaskSampler>(ISurface <ColorBgra> dstContent, PointInt32 renderOffset, ref TMaskSampler baseMaskSampler) where TMaskSampler : IMaskSampler
        {
            if (Interlocked.Exchange(ref this.isLazyDeltaSelectionMaskFirstTimePrefetched, 1) == 0)
            {
                this.lazyDeltaSelectionMask.EnsureEvaluated();
            }
            else if (Interlocked.Exchange(ref this.isLazyFinalSelectionMaskFirstTimePrefetched, 1) == 0)
            {
                this.lazyFinalSelectionMask.EnsureEvaluated();
            }
            base.ThrowIfCancellationRequested();
            int        width   = dstContent.Width;
            int        height  = dstContent.Height;
            ColorBgra *bgraPtr = (ColorBgra *)dstContent.Scan0;
            int        stride  = dstContent.Stride;
            int        num4    = stride - (width * 4);
            RectInt32  bounds  = new RectInt32(renderOffset.X, renderOffset.Y, width, height);
            uint       num6    = this.changes.BackFillColor.Bgra;

            using (ISurface <ColorAlpha8> surface = alpha8Allocator.Allocate(width, height, AllocationOptions.ZeroFillNotRequired))
            {
                base.ThrowIfCancellationRequested();
                this.sourceTx.Render(dstContent, surface, renderOffset);
                base.ThrowIfCancellationRequested();
                using (ISurface <ColorAlpha8> surface2 = this.lazyFinalSelectionMask.Value.UseTileOrToSurface(bounds))
                {
                    base.ThrowIfCancellationRequested();
                    ColorBgra *pointAddress = this.activeLayer.Surface.GetPointAddress(renderOffset.X, renderOffset.Y);
                    int        num7         = this.activeLayer.Surface.Stride - (width * 4);
                    byte *     numPtr       = (byte *)surface2.Scan0;
                    int        num8         = surface2.Stride - bounds.Width;
                    byte *     numPtr2      = (byte *)surface.Scan0;
                    int        num9         = surface.Stride - bounds.Width;
                    ColorBgra *bgraPtr3     = bgraPtr + width;
                    baseMaskSampler.Initialize();
                    for (int i = 0; i < height; i++)
                    {
                        for (ColorBgra *bgraPtr4 = bgraPtr3 - width; bgraPtr4 < bgraPtr3; bgraPtr4++)
                        {
                            byte next  = baseMaskSampler.GetNext();
                            byte num12 = numPtr[0];
                            byte num13 = numPtr2[0];
                            byte num14 = Math.Min(num13, num12);
                            if (num14 == 0)
                            {
                                byte frac = (byte)(0xff - next);
                                if (frac == 0)
                                {
                                    bgraPtr4->Bgra = num6;
                                }
                                else
                                {
                                    ColorBgra bgra = pointAddress[0];
                                    if (frac != 0xff)
                                    {
                                        bgra.A = ByteUtil.FastScale(bgra.A, frac);
                                    }
                                    bgraPtr4->Bgra = bgra.Bgra;
                                }
                            }
                            else if (num14 != 0xff)
                            {
                                byte      num16 = Math.Min((byte)(0xff - num14), (byte)(0xff - next));
                                ColorBgra bgra2 = bgraPtr4[0];
                                ColorBgra bgra3 = pointAddress[0];
                                ushort    d     = (ushort)((bgra3.A * num16) + (bgra2.A * num14));
                                if (d == 0)
                                {
                                    bgraPtr4->Bgra = num6;
                                }
                                else
                                {
                                    int  num18 = UInt16Util.FastDivideBy255((ushort)((bgra3.A * num16) + (bgra2.A * num14)));
                                    uint num19 = UInt32Util.FastDivideByUInt16((uint)(((bgra3.A * num16) * bgra3.B) + ((bgra2.A * num14) * bgra2.B)), d);
                                    uint num20 = UInt32Util.FastDivideByUInt16((uint)(((bgra3.A * num16) * bgra3.G) + ((bgra2.A * num14) * bgra2.G)), d);
                                    uint num21 = UInt32Util.FastDivideByUInt16((uint)(((bgra3.A * num16) * bgra3.R) + ((bgra2.A * num14) * bgra2.R)), d);
                                    bgraPtr4->Bgra = ColorBgra.BgraToUInt32((byte)num19, (byte)num20, (byte)num21, (byte)num18);
                                }
                            }
                            pointAddress++;
                            numPtr++;
                            numPtr2++;
                        }
                        pointAddress += num7;
                        baseMaskSampler.MoveToNextRow();
                        numPtr   += num8;
                        numPtr2  += num9;
                        bgraPtr3 += stride;
                        base.ThrowIfCancellationRequested();
                    }
                }
            }
        }
コード例 #30
0
 private void PasteClipboard(PointInt32 anchor)
 {
     _clipboardMan.PasteBufferIntoWorld(_world, _clipboardMan.Buffer, anchor);
     _renderer.UpdateWorldImage(new Int32Rect(anchor.X, anchor.Y, _clipboardMan.Buffer.Size.W, _clipboardMan.Buffer.Size.H));
 }
コード例 #31
0
ファイル: DocumentRenderer.cs プロジェクト: ykafia/Paint.Net4
 public void Render(ISurface <ColorBgra> dst, PointInt32 renderOffset)
 {
     this.CreateRenderer().Render(dst, renderOffset);
 }
コード例 #32
0
        public static unsafe void FillStencilFromPoint <TBitVector2D>(IRenderer <ColorBgra> sampleSource, TBitVector2D stencilBuffer, PointInt32 startPt, byte tolerance, Func <bool> isCancellationRequestedFn, out RectInt32 bounds) where TBitVector2D : IBitVector2D
        {
            Validate.IsNotNull <IRenderer <ColorBgra> >(sampleSource, "sampleSource");
            int width  = sampleSource.Width;
            int height = sampleSource.Height;

            if ((width > stencilBuffer.Width) || (height > stencilBuffer.Height))
            {
                throw new ArgumentException();
            }
            if (!sampleSource.CheckPointValue <ColorBgra>(startPt))
            {
                bounds = RectInt32.Empty;
            }
            else
            {
                int num3 = sampleSource.Width;
                int num4 = sampleSource.Height;
                using (RendererRowCache <ColorBgra> cache = new RendererRowCache <ColorBgra>(sampleSource))
                {
                    int num5 = 0x7fffffff;
                    int num6 = 0x7fffffff;
                    int num7 = -2147483648;
                    int num8 = -2147483648;
                    Queue <PointInt32> queue = new Queue <PointInt32>(0x10);
                    queue.Enqueue(startPt);
                    cache.AddRowRef(startPt.Y - 1);
                    cache.AddRowRef(startPt.Y);
                    cache.AddRowRef(startPt.Y + 1);
                    ColorBgra start = *((ColorBgra *)(((void *)cache.GetRow(startPt.Y)) + (startPt.X * sizeof(ColorBgra))));
                    while (queue.Any <PointInt32>())
                    {
                        if (isCancellationRequestedFn())
                        {
                            bounds = RectInt32.Empty;
                            return;
                        }
                        PointInt32 pt = queue.Dequeue();
                        try
                        {
                            if (sampleSource.CheckPointValue <ColorBgra>(pt))
                            {
                                ColorBgra *row   = (ColorBgra *)cache.GetRow(pt.Y);
                                int        x     = pt.X - 1;
                                int        num11 = pt.X;
                                while (((x >= 0) && !stencilBuffer.Get(x, pt.Y)) && CheckColor(start, row[x], tolerance))
                                {
                                    stencilBuffer.Set(x, pt.Y, true);
                                    x--;
                                }
                                while (((num11 < num3) && !stencilBuffer.Get(num11, pt.Y)) && CheckColor(start, row[num11], tolerance))
                                {
                                    stencilBuffer.Set(num11, pt.Y, true);
                                    num11++;
                                }
                                x++;
                                num11--;
                                if (pt.Y > 0)
                                {
                                    cache.AddRowRef(pt.Y - 2);
                                    cache.AddRowRef(pt.Y - 1);
                                    cache.AddRowRef(pt.Y);
                                    try
                                    {
                                        ColorBgra *bgraPtr2 = (ColorBgra *)cache.GetRow(pt.Y - 1);
                                        int        num12    = x;
                                        int        num13    = x;
                                        for (int i = x; i <= num11; i++)
                                        {
                                            if (!stencilBuffer.Get(i, pt.Y - 1) && CheckColor(start, bgraPtr2[i], tolerance))
                                            {
                                                num13++;
                                            }
                                            else
                                            {
                                                if ((num13 - num12) > 0)
                                                {
                                                    queue.Enqueue(new PointInt32(num12, pt.Y - 1));
                                                    cache.AddRowRef(pt.Y - 2);
                                                    cache.AddRowRef(pt.Y - 1);
                                                    cache.AddRowRef(pt.Y);
                                                }
                                                num13++;
                                                num12 = num13;
                                            }
                                        }
                                        if ((num13 - num12) > 0)
                                        {
                                            queue.Enqueue(new PointInt32(num12, pt.Y - 1));
                                            cache.AddRowRef(pt.Y - 2);
                                            cache.AddRowRef(pt.Y - 1);
                                            cache.AddRowRef(pt.Y);
                                        }
                                    }
                                    finally
                                    {
                                        cache.ReleaseRowRef(pt.Y - 2);
                                        cache.ReleaseRowRef(pt.Y - 1);
                                        cache.ReleaseRowRef(pt.Y);
                                    }
                                }
                                if (pt.Y < (num4 - 1))
                                {
                                    cache.AddRowRef(pt.Y);
                                    cache.AddRowRef(pt.Y + 1);
                                    cache.AddRowRef(pt.Y + 2);
                                    try
                                    {
                                        ColorBgra *bgraPtr3 = (ColorBgra *)cache.GetRow(pt.Y + 1);
                                        int        num15    = x;
                                        int        num16    = x;
                                        for (int j = x; j <= num11; j++)
                                        {
                                            if (!stencilBuffer.Get(j, pt.Y + 1) && CheckColor(start, bgraPtr3[j], tolerance))
                                            {
                                                num16++;
                                            }
                                            else
                                            {
                                                if ((num16 - num15) > 0)
                                                {
                                                    queue.Enqueue(new PointInt32(num15, pt.Y + 1));
                                                    cache.AddRowRef(pt.Y);
                                                    cache.AddRowRef(pt.Y + 1);
                                                    cache.AddRowRef(pt.Y + 2);
                                                }
                                                num16++;
                                                num15 = num16;
                                            }
                                        }
                                        if ((num16 - num15) > 0)
                                        {
                                            queue.Enqueue(new PointInt32(num15, pt.Y + 1));
                                            cache.AddRowRef(pt.Y);
                                            cache.AddRowRef(pt.Y + 1);
                                            cache.AddRowRef(pt.Y + 2);
                                        }
                                    }
                                    finally
                                    {
                                        cache.ReleaseRowRef(pt.Y);
                                        cache.ReleaseRowRef(pt.Y + 1);
                                        cache.ReleaseRowRef(pt.Y + 2);
                                    }
                                }
                                num5 = Math.Min(num5, x);
                                num6 = Math.Min(num6, pt.Y);
                                num7 = Math.Max(num7, num11);
                                num8 = Math.Max(num8, pt.Y);
                            }
                            continue;
                        }
                        finally
                        {
                            cache.ReleaseRowRef(pt.Y - 1);
                            cache.ReleaseRowRef(pt.Y);
                            cache.ReleaseRowRef(pt.Y + 1);
                        }
                    }
                    bounds = RectInt32.FromEdges(num5, num6, num7, num8);
                }
            }
        }
コード例 #33
0
 internal BrushStrokeRenderCache.TileData <GetTileData> b__12_0(PointInt32 to) =>
 new BrushStrokeRenderCache.TileData(to);
コード例 #34
0
        protected override void OnRender(ISurface <ColorBgra> dstContent, ISurface <ColorAlpha8> dstMask, PointInt32 renderOffset)
        {
            base.ThrowIfCancellationRequested();
            IRenderer <ColorAlpha8> renderer = this.lazyStencil.CancelableValue <IRenderer <ColorAlpha8> >();

            base.ThrowIfCancellationRequested();
            if (renderer == null)
            {
                throw new PaintDotNet.InternalErrorException("stencil == null");
            }
            base.ThrowIfCancellationRequested();
            renderer.Render(dstMask, renderOffset);
            base.ThrowIfCancellationRequested();
            this.brushRenderer.Render(dstContent, renderOffset);
        }
コード例 #35
0
 public void Render(ISurface <ColorAlpha8> dst, PointInt32 renderOffset)
 {
     this.owner.RenderMask(dst, renderOffset, this.cancelToken);
 }
コード例 #36
0
 public TileData(PointInt32 offset)
 {
     this.Offset = offset;
 }
コード例 #37
0
		public override void ClipViewPosition(Point p)
		{
			if (ViewPositionLock != null)
			{
				p.x = ViewPositionLock.x;
				p.y = ViewPositionLock.y;

				return;
			}

			var Walls = this.Map.WallMap;

			if (Walls == null)
				return;


			#region bump on blocking sprites
			foreach (var v in BlockingSprites)
			{
				var z = Point.distance(p, v.Position);

				if (z < v.Range)
				{
					// pump us out of that sprite

					var a = (p - v.Position).GetRotation();

					p.x = v.Position.x + Math.Cos(a) * v.Range;
					p.y = v.Position.y + Math.Sin(a) * v.Range;
				}

			}
			#endregion

			var fPlayerX = p.x;
			var fPlayerY = p.y;


			var c = new PointInt32
			{
				X = (int)Math.Floor(p.x),
				Y = (int)Math.Floor(p.y)
			};

			var TILE_SIZE = 1.0;

			var PositionInWall =
				 new Point
				 {
					 x = fPlayerX % TILE_SIZE,
					 y = fPlayerY % TILE_SIZE
				 };


			var TileTop = Walls[c.X, c.Y - 1];
			var TileLeft = Walls[c.X - 1, c.Y];
			var TileRight = Walls[c.X + 1, c.Y];
			var TileBottom = Walls[c.X, c.Y + 1];


			var CurrentMapTile = Walls[c.X, c.Y];

			if (CurrentMapTile != 0)
			{
				// we are inside a wall
				// push us out of there

				#region Dia
				var A = PositionInWall.x > PositionInWall.y;
				var B = PositionInWall.x > (TILE_SIZE - PositionInWall.y);

				var DiaClipLeft = !A && !B;
				var DiaClipRight = A && B;
				var DiaClipTop = A && !B;
				var DiaClipBottom = !A && B;
				#endregion

				#region Alt
				var C = PositionInWall.x > (TILE_SIZE / 2);
				var D = PositionInWall.y > (TILE_SIZE / 2);

				var AltClipTopLeft = !C && !D;
				var AltClipBottomLeft = !C && D;
				var AltClipTopRight = C && !D;
				var AltClipBottomRight = C && D;
				#endregion


				var ClipLeft = DiaClipLeft;

				if (TileTop != 0) ClipLeft |= AltClipTopLeft;
				if (TileBottom != 0) ClipLeft |= AltClipBottomLeft;

				var ClipRight = DiaClipRight;

				if (TileTop != 0) ClipRight |= AltClipTopRight;
				if (TileBottom != 0) ClipRight |= AltClipBottomRight;

				var ClipTop = DiaClipTop;

				if (TileLeft != 0) ClipTop |= AltClipTopLeft;
				if (TileRight != 0) ClipTop |= AltClipTopRight;

				var ClipBottom = DiaClipBottom;

				if (TileLeft != 0) ClipBottom |= AltClipBottomLeft;
				if (TileRight != 0) ClipBottom |= AltClipBottomRight;



				if (ClipLeft)
					fPlayerX = fPlayerX.Min(c.X * TILE_SIZE - PlayerRadiusMargin);
				else if (ClipRight)
					fPlayerX = fPlayerX.Max((c.X + 1) * TILE_SIZE + PlayerRadiusMargin);

				if (ClipTop)
					fPlayerY = fPlayerY.Min(c.Y * TILE_SIZE - PlayerRadiusMargin);
				else if (ClipRight)
					fPlayerY = fPlayerY.Max((c.Y + 1) * TILE_SIZE + PlayerRadiusMargin);
			}
			else
			{
				// fix corners
				//
				//   *        L
				//    F      *

				if (TileLeft != 0)
					fPlayerX = fPlayerX.Max(c.X * TILE_SIZE + PlayerRadiusMargin);
				if (TileRight != 0)
					fPlayerX = fPlayerX.Min((c.X + 1) * TILE_SIZE - PlayerRadiusMargin);

				if (TileTop != 0)
					fPlayerY = fPlayerY.Max(c.Y * TILE_SIZE + PlayerRadiusMargin);
				if (TileBottom != 0)
					fPlayerY = fPlayerY.Min((c.Y + 1) * TILE_SIZE - PlayerRadiusMargin);

			}

			p.x = fPlayerX;
			p.y = fPlayerY;



		}