/// <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); }
public override void OnDrawStart(PADrawEvent evt) { if (!evt.shift || _drawPosition == null) { _drawPosition = CanvasToTexture(evt.imagePosition); } _drawColor = GetDrawColor(evt.button); _target = Canvas.File.AddImage(Canvas.ActiveFrame, Canvas.ActiveLayer); DrawTo(evt.imagePosition); }
public override void OnDrawEnd(PADrawEvent evt, bool cancelled) { _target = null; Canvas.RefreshImage(); }
/// <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); }