/* * Constructor */ public PixelSourceLayer(LayeredTexture parent, PixelSource ps, Pixel.PixelBlendMode blendMode, int xOffset, int yOffset) { mPixelSource = ps; mPixelBlendMode = blendMode; mOffsetX = xOffset; mOffsetY = yOffset; mParent = parent; mFilter = new ClearFilter(); }
public void AddLayer(string name, Pixel.PixelBlendMode blendMode, PixelSource newPixelSource, int xOffset, int yOffset) { // Check if a layer with the same name already exists if (HasLayer(name)) { Console.LogError("LayeredTexture AddLayer: PixelSource with name " + name + " already exists."); } // Add layer AddLayer(name, new PixelSourceLayer(this, newPixelSource, blendMode, xOffset, yOffset)); }
/* * 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); } }
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"); } }
/// <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)); } }
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); }
public void AddLayer(string name, Pixel.PixelBlendMode blendMode, PixelSource newPixelSource) { AddLayer(name, blendMode, newPixelSource, 0, 0); }