Ejemplo n.º 1
0
        /// <summary>
        /// Add a new texture or return the existing one
        /// </summary>
        public PAImage AddImage(PAFrame frame, PALayer layer)
        {
            var image = FindImage(frame, layer);

            if (null != image)
            {
                return(image);
            }

            var texture = new Texture2D(width, height, TextureFormat.RGBA32, false);

            texture.filterMode = FilterMode.Point;
            texture.Clear(Color.clear);
            texture.Apply();

            image = new PAImage
            {
                frame   = frame,
                layer   = layer,
                texture = texture
            };

            images.Add(image);

            return(image);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Remove a layer from the file
        /// </summary>
        public void DeleteLayer(PALayer remove)
        {
            // Remove all textures that reference the layer
            images = images.Where(t => t.layer != remove).ToList();

            // Adjust the order for all layers after the layer being removed
            foreach (var layer in layers)
            {
                if (layer.order > remove.order)
                {
                    layer.order--;
                }
            }

            // Remove the layer from the list
            layers.Remove(remove);
        }
Ejemplo n.º 3
0
        public PALayerItem(PACanvas canvas, PALayer layer)
        {
            _canvas    = canvas;
            Layer      = layer;
            Layer.Item = this;

            pickingMode = PickingMode.Position;
            focusable   = true;
            AddToClassList("layer");

            Add(PAUtils.CreateIconToggle("LayerVisibilityToggle", "Toggle layer visibility", OnVisibilityChanged));

            _preview = new Image()
            {
                name = "Preview"
            };
            Add(_preview);

            Add(new Label(layer.name));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add a new layer to the file
        /// </summary>
        public PALayer AddLayer()
        {
            // Determine the unique name index for the layer based on the
            // maximum layer named "Layer #"
            var nameIndex = layers
                            .Where(l => l.name.StartsWith("Layer "))
                            .Select(l => int.Parse(l.name.Substring(6)))
                            .DefaultIfEmpty()
                            .Max() + 1;

            var layer = new PALayer(this)
            {
                id      = System.Guid.NewGuid().ToString(),
                name    = $"Layer {nameIndex}",
                opacity = 1.0f,
                order   = layers.Count
            };

            layers.Add(layer);
            return(layer);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Find the texture for the given frame and layer
 /// </summary>
 /// <returns></returns>
 public PAImage FindImage(PAFrame frame, PALayer layer) =>
 images.Where(t => t.frame == frame && t.layer == layer).FirstOrDefault();
Ejemplo n.º 6
0
        /// <summary>
        /// Load a pixel edtior file from the given filename
        /// </summary>
        public static PAFile Load(string filename)
        {
            var file = new PAFile {
                name = Path.GetFileNameWithoutExtension(filename)
            };

            using (var reader = new BinaryReader(File.OpenRead(filename)))
            {
                file.version = reader.ReadInt32();
                file.width   = reader.ReadInt32();
                file.height  = reader.ReadInt32();

                var textureSize = 4 * file.width * file.height;

                // Read the layers
                var layerCount = reader.ReadInt32();
                for (var layerIndex = 0; layerIndex < layerCount; layerIndex++)
                {
                    var layer = new PALayer(file);
                    layer.id      = reader.ReadString();
                    layer.name    = reader.ReadString();
                    layer.opacity = reader.ReadSingle();
                    layer.order   = reader.ReadInt32();
                    layer.visible = reader.ReadBoolean();
                    file.layers.Add(layer);
                }

                // Read the animations
                var animationCount = reader.ReadInt32();
                for (var animationIndex = 0; animationIndex < animationCount; animationIndex++)
                {
                    var animation = new PAAnimation();
                    animation.id   = reader.ReadString();
                    animation.name = reader.ReadString();

                    if (file.version < 3)
                    {
                        animation.fps = 10;
                    }
                    else
                    {
                        animation.fps = reader.ReadInt32();
                    }

                    file.animations.Add(animation);
                }

                // Read the frames
                var frameCount = reader.ReadInt32();
                for (var frameIndex = 0; frameIndex < frameCount; frameIndex++)
                {
                    var frame = new PAFrame(file);
                    frame.id        = reader.ReadString();
                    frame.animation = file.FindAnimation(reader.ReadString());
                    frame.order     = reader.ReadInt32();
                    file.frames.Add(frame);
                }

                // Read the textures
                var imageCount = reader.ReadInt32();
                for (var imageIndex = 0; imageIndex < imageCount; imageIndex++)
                {
                    var image = new PAImage();
                    image.frame = file.FindFrame(reader.ReadString());
                    image.layer = file.FindLayer(reader.ReadString());

                    if (reader.ReadBoolean())
                    {
                        image.texture = new Texture2D(file.width, file.height, TextureFormat.RGBA32, false);
                        image.texture.LoadRawTextureData(reader.ReadBytes(textureSize));
                        image.texture.filterMode = FilterMode.Point;
                        image.texture.Apply();
                    }

                    file.images.Add(image);
                }
            }

            return(file);
        }