示例#1
0
        public static RectInt32 FromPoints(PointInt32 a, PointInt32 b)
        {
            int left   = Math.Min(a.X, b.X);
            int top    = Math.Min(a.Y, b.Y);
            int right  = Math.Max(a.X, b.X);
            int bottom = Math.Max(a.Y, b.Y);

            return(RectInt32.FromEdges(left, top, right, bottom));
        }
        public unsafe void Render(ISurfaceAllocator <ColorAlpha8> allocator, int dstWidth, int dstHeight, PointInt32 renderOffset, ref ISurface <ColorAlpha8> dst, out int?fill255Count)
        {
            int stride;

            if ((allocator == null) && (dst == null))
            {
                throw new ArgumentException();
            }
            if (dst != null)
            {
                dst.Clear(ColorAlpha8.Transparent);
            }
            int       x               = renderOffset.X;
            int       y               = renderOffset.Y;
            int       right           = renderOffset.X + dstWidth;
            int       bottom          = renderOffset.Y + dstHeight;
            RectInt32 a               = RectInt32.FromEdges(x, y, right, bottom);
            int       count           = this.scans.Count;
            int       scansStartIndex = this.GetScansStartIndex(y, bottom);

Label_006C:
            stride = -1;
            byte *numPtr = null;

            if (dst != null)
            {
                stride = dst.Stride;
                numPtr = (byte *)dst.Scan0;
            }
            int num9 = 0;

            for (int i = scansStartIndex; i < count; i++)
            {
                RectInt32 scanAt = this.GetScanAt(i);
                if (scanAt.Y >= bottom)
                {
                    break;
                }
                int       left  = Math.Max(x, scanAt.X);
                int       top   = Math.Max(y, scanAt.Y);
                int       num14 = Math.Min(right, scanAt.X + scanAt.Width);
                int       num15 = Math.Min(bottom, scanAt.Y + scanAt.Height);
                RectInt32 b     = RectInt32.FromEdges(left, top, num14, num15);
                if (RectInt32.Intersect(a, b).HasPositiveArea)
                {
                    uint num18 = (uint)(num14 - left);
                    int  num19 = left - renderOffset.X;
                    int  num20 = num14 - renderOffset.X;
                    if (dst == null)
                    {
                        num9 += (int)((num15 - top) * num18);
                    }
                    else
                    {
                        byte *prgBuffer = numPtr + ((byte *)(((top - renderOffset.Y) * stride) + num19));
                        for (int j = top; j < num15; j++)
                        {
                            Memory.FillMemory(prgBuffer, 0xff, (ulong)num18);
                            prgBuffer += stride;
                        }
                    }
                }
            }
            if (((dst != null) || (num9 == 0)) || (num9 == (dstWidth * dstHeight)))
            {
                if (dst == null)
                {
                    fill255Count = new int?(num9);
                }
                else
                {
                    fill255Count = 0;
                }
            }
            else
            {
                dst = allocator.Allocate(dstWidth, dstHeight, AllocationOptions.Default);
                goto Label_006C;
            }
        }