예제 #1
0
 protected PixelSourceLayer AddLayer(string name, PixelSourceLayer newLayer)
 {
     mLayerLookup.Add(name, newLayer);
     mLayers.Add(newLayer);
     MarkAsDirty(newLayer);
     return(newLayer);
 }
예제 #2
0
        public void ClearLayer(string layerName)
        {
            // Check if a layer exists
            if (HasLayer(layerName))
            {
                // Get relevant layer
                PixelSourceLayer layer = GetLayer(layerName);

                // Mark the layer as dirty
                MarkAsDirty(layer);

                if (layer.PixelBlendMode == Pixel.PixelBlendMode.Multiply)
                {
                    layer.PixelSource = new SolidColorPixelSource(mWidth, mHeight, Color.white);
                }
                else
                {
                    layer.PixelSource = SolidColorPixelSource.Clear(mWidth, mHeight);
                }
            }
            else
            {
                Console.LogError("LayeredTexture ClearLayer: Layer with name " + layerName + " does not exist in this Complex Texture");
            }
        }
예제 #3
0
        private string GetNameForLayer(PixelSourceLayer layer)
        {
            foreach (KeyValuePair <string, PixelSourceLayer> kvp in mLayerLookup)
            {
                if (kvp.Value == layer)
                {
                    return(kvp.Key);
                }
            }

            throw new KeyNotFoundException("layer");
        }
예제 #4
0
 /// <summary>
 /// Change the PixelFilter Color property
 /// </summary>
 public void SetLayerFilterColor(string layerName, Color color)
 {
     if (HasLayer(layerName))
     {
         PixelSourceLayer layer = GetLayer(layerName);
         layer.Filter.FilterColor = color;
     }
     else
     {
         Console.LogError("LayeredTexture SetLayerFilterColor: Layer with name " + layerName + " does not exist");
     }
 }
예제 #5
0
 public Color GetLayerFilterColor(string layerName)
 {
     if (HasLayer(layerName))
     {
         PixelSourceLayer layer = GetLayer(layerName);
         return(layer.Filter.FilterColor);
     }
     else
     {
         Console.LogError("LayeredTexture GetLayerFilterColor: Layer with name " + layerName + " does not exist");
     }
     return(Color.clear);
 }
예제 #6
0
        public void MoveLayerRelative(string layerName, int x, int y)
        {
            if (HasLayer(layerName))
            {
                PixelSourceLayer moveLayer = GetLayer(layerName);
                MarkAsDirty(moveLayer);

                moveLayer.OffsetX += x;
                moveLayer.OffsetY += y;

                MarkAsDirty(moveLayer);
            }
        }
예제 #7
0
 /*
  *      Add an empty layer to a zone
  */
 public void CreateLayerInZone(string layerName, string zoneName, Pixel.PixelBlendMode blendMode)
 {
     if (!HasZone(zoneName))
     {
         Console.LogError("LayeredPalette AddLayer(): Zone " + zoneName + " does not exist");
     }
     else
     {
         TextureZone           zone           = GetZone(zoneName);
         SolidColorPixelSource newPixelSource = SolidColorPixelSource.Clear((int)zone.Area.width, (int)zone.Area.height);
         PixelSourceLayer      newLayer       = new PixelSourceLayer(this, newPixelSource, blendMode, (int)zone.Area.x, (int)zone.Area.y);
         CreateLayerInZone(layerName, zoneName, newLayer);
     }
 }
예제 #8
0
        public override string ToString()
        {
            string result = "Complex Texture:\n";
            ICollection <string> layerNames = mLayerLookup.Keys;

            foreach (string l in layerNames)
            {
                PixelSourceLayer printLayer = GetLayer(l);
                result += GetLayerIndex(l) + " " + l + " " + printLayer.ToString() + "\n";
            }

            result += "Is Dirty: " + HasDirtyPixels() + "\nDirty Pixels: " + mDirtyPixels;
            return(result);
        }
예제 #9
0
 public void ChangeLayerBlendMode(string name, Pixel.PixelBlendMode newBlendMode)
 {
     // Check if a layer exists
     if (HasLayer(name))
     {
         PixelSourceLayer layer = GetLayer(name);
         layer.PixelBlendMode = newBlendMode;
         MarkAsDirty(layer);
     }
     else
     {
         Console.LogError("LayeredTexture ChangeLayerBlendMode: TexturePixelSource with name " + name + " does not exist");
     }
 }
예제 #10
0
        public void CreateLayerInAllZones(string layerName, PixelSource newPixelSource, Pixel.PixelBlendMode blendMode)
        {
            PixelSourceLayer newLayer = new PixelSourceLayer(this, newPixelSource, blendMode, 0, 0);

            mUniversalLayers.Add(newLayer);

            // Add this layer to all zones
            for (int x = 0; x < mZones.Count; ++x)
            {
                mZones[x].AddLayer(newLayer);
            }

            // Create Layer
            AddLayer(layerName, newLayer);
        }
예제 #11
0
        /// <summary>
        /// Flatten a Pixel of the Complex Texture. Recurse down the layers and combine pixels
        /// </summary>
        protected HColor FlattenPixel(int x, int y, int level, List <PixelSourceLayer> layers)
        {
            // Base Case 1
            switch (level)
            {
            case 0:
                return(new HColor(0, 0, 0, 0));

            case 1:
                return(layers[0][x, y]);

            default:
                PixelSourceLayer currentLayer = layers[level - 1];

                // Optimization 1: Out of PixelSource Bounds
                // If we are out of bounds for this layer don't bother Blending Pixels, go to next layer
                if (!currentLayer.IndexInBounds(x, y))
                {
                    return(FlattenPixel(x, y, level - 1, layers));
                }

                HColor pixel = currentLayer[x, y];
                Pixel.PixelBlendMode blendMode = currentLayer.PixelBlendMode;

                // Optimization 2
                // If layer Blendmode == Layer, and alpha is 1, get the hell out of here
                if (blendMode == Pixel.PixelBlendMode.Layer)
                {
                    // Quick Exit
                    if (pixel.a == 255)
                    {
                        return(pixel);
                    }

                    // If 100% transparent go down to next layer
                    if (pixel.a == 0)
                    {
                        return(FlattenPixel(x, y, level - 1, layers));
                    }
                }

                // Else recurse down and combine pixel with the result of the lower pixel
                Pixel.BlendPixels blendFunction = Pixel.GetBlendFunction(blendMode);
                return(blendFunction(FlattenPixel(x, y, level - 1, layers), pixel));
            }
        }
예제 #12
0
        /*
         *
         */
        private PixelSourceLayer CreateLayerInZone(string layerName, string zoneName, PixelSourceLayer newLayer)
        {
            TextureZone zone = GetZone(zoneName);

            /* Create Layer */
            PixelSourceLayer addedLayer = AddLayer(layerName, newLayer);

            /* Does the Layer Clip the Zone? */
            if (addedLayer.PixelSource.Width > zone.Area.width + 1 || addedLayer.PixelSource.Height > zone.Area.height + 1)
            {
                Console.LogError("LayeredPalette CreateLayerInZone(): Layer " + layerName + " will be clipped when placed in zone " + zoneName);
            }

            /* Add Layer to Zone */
            zone.AddLayer(newLayer);

            return(addedLayer);
        }
예제 #13
0
        /// <summary>
        /// Change the PixelFilter used by the Layer
        /// </summary>
        public void SetLayerFilter(string layerName, PixelFilter newFilter)
        {
            // Check if a layer exists
            if (!HasLayer(layerName))
            {
                throw new Exception("LayeredTexture SetLayerFilter: Layer with name " + layerName + " does not exist");
            }

            // Get relevant layer
            PixelSourceLayer layer = GetLayer(layerName);

            // Mark the layer as dirty
            MarkAsDirty(layer);

            // Swap
            layer.Filter     = newFilter;
            newFilter.Parent = layer;
        }
예제 #14
0
        public void SetLayerPixelSource(string layerName, PixelSource newPixelSource)
        {
            // Check if a layer exists
            if (HasLayer(layerName))
            {
                // Get relevant layer
                PixelSourceLayer layer = GetLayer(layerName);

                // Mark the old pixel source as dirty
                MarkAsDirty(layer);

                // Swap
                layer.PixelSource = newPixelSource;

                // Mark the new source as dirty
                MarkAsDirty(layer);
            }
            else
            {
                Console.LogError("LayeredTexture SetLayerPixelSource: Layer with name " + layerName + " does not exist");
            }
        }
예제 #15
0
        public void MarkAsDirty(PixelSourceLayer dirtyLayer)
        {
            // If already Dirty combine dirty spaces
            if (HasDirtyPixels())
            {
                float minX = Mathf.Min(mDirtyPixels.x, dirtyLayer.OffsetX);
                float minY = Mathf.Min(mDirtyPixels.y, dirtyLayer.OffsetY);

                float maxX = Mathf.Max(mDirtyPixels.xMax, dirtyLayer.OffsetX + dirtyLayer.PixelSource.Width);
                float maxY = Mathf.Max(mDirtyPixels.yMax, dirtyLayer.OffsetY + dirtyLayer.PixelSource.Height);

                maxX = Mathf.Clamp(maxX, 0, mWidth);
                maxY = Mathf.Clamp(maxY, 0, mHeight);

                minX = Mathf.Clamp(minX, 0, mWidth);
                minY = Mathf.Clamp(minY, 0, mHeight);

                mDirtyPixels = new Rect(minX, minY, maxX - minX, maxY - minY);
            }
            else
            {
                mDirtyPixels = new Rect(dirtyLayer.OffsetX, dirtyLayer.OffsetY, dirtyLayer.PixelSource.Width, dirtyLayer.PixelSource.Height);
            }
        }
예제 #16
0
 public void AddLayer(PixelSourceLayer pl)
 {
     mZoneLayers.Add(pl);
 }
예제 #17
0
 private bool IsLayerDirty(PixelSourceLayer pl)
 {
     return(mDirtyLayers.Contains(pl));
 }