Ejemplo n.º 1
0
            public bool Harvest(ITextureOperations <TTexture, TColor> ops,
                                TTexture targetTexture,
                                out TTexture result)
            {
                if (HasTexture)
                {
                    var textureBounds = Texture.Bounds;
                    // Debug.Log("Extract " + Texture.Name + " via " + textureBounds);
                    var localTextureBounds = new TextureCoordinateRect
                                                 (0, 0, textureBounds.Width, textureBounds.Height);
                    var srcData = ops.ExtractData(Texture, localTextureBounds);
                    ops.MakeDebugVisible(srcData);
                    ops.ApplyTextureData(targetTexture, srcData,
                                         new TextureCoordinatePoint(CellBounds.X, CellBounds.Y));

                    result = ops.Clip(targetTexture.Name + ":" + Texture.Name, targetTexture, CellBounds);
                    // Debug.Log("Harvest: " + result.Name + ":" + Texture.Name + " " + result.Bounds + " @ " + textureBounds);
                    return(true);
                }

                if (Left.Harvest(ops, targetTexture, out var l))
                {
                    result = l;
                    return(true);
                }

                return(Right.Harvest(ops, targetTexture, out result));
            }
Ejemplo n.º 2
0
        public BoundedTextureData <Color> ExtractData(XnaTexture srcTexture, TextureCoordinateRect rect)
        {
            var texture = srcTexture.Texture;

            if (texture == null)
            {
                return(CreateClearTexture(rect.Size));
            }

            var data      = new Color[rect.Width * rect.Height];
            var srcBounds = srcTexture.Bounds;
            var b         = srcBounds.Clip(new TextureCoordinateRect(rect.X + srcBounds.X, rect.Y + srcBounds.Y, rect.Width, rect.Height));

            if (UseSourceTextureCache)
            {
                var srcLineWidth = srcTexture.Texture.Bounds.Width;
                var raw          = ExtractColorData(srcTexture);
                for (var y = 0; y < b.Height; y += 1)
                {
                    var srcIdx = (b.Y + y) * srcLineWidth + b.X;
                    var tgtIdx = y * rect.Width;
                    Array.Copy(raw, srcIdx, data, tgtIdx, b.Width);
                }
            }
            else
            {
                texture.GetData(0, b.ToXna(), data, 0, data.Length);
            }

            var textureBounds = new TextureCoordinateRect(rect.X, rect.Y, b.Width, b.Height);

            return(new BoundedTextureData <Color>(textureBounds, data));
        }
Ejemplo n.º 3
0
 public XnaTexture CreateSubTexture(string name, TextureCoordinateRect bounds)
 {
     return(new XnaTexture(name ?? Name, bounds, Texture));
 }
Ejemplo n.º 4
0
 public static Rectangle ToXna(this TextureCoordinateRect rect)
 {
     return(new Rectangle(rect.X, rect.Y, rect.Width, rect.Height));
 }
Ejemplo n.º 5
0
 public TreeNode(TextureCoordinateRect bounds)
 {
     CellBounds = bounds;
 }
Ejemplo n.º 6
0
 public XnaTexture(string name, TextureCoordinateRect bounds, Texture2D texture)
 {
     Name    = name;
     Bounds  = bounds;
     Texture = texture;
 }
Ejemplo n.º 7
0
 public XnaTexture Clip(string name, XnaTexture texture, TextureCoordinateRect clipRegion)
 {
     return(new XnaTexture(name, clipRegion.Clip(texture.Bounds), texture.Texture));
 }