From 93ac9c657ce285c5daa5a3ea6ed8c91b50e0281c Mon Sep 17 00:00:00 2001 From: Ian C Date: Sat, 30 Jul 2005 01:55:41 +0000 Subject: Development checkin --- Sprite.cs | 546 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 546 insertions(+) create mode 100644 Sprite.cs (limited to 'Sprite.cs') diff --git a/Sprite.cs b/Sprite.cs new file mode 100644 index 0000000..47678e9 --- /dev/null +++ b/Sprite.cs @@ -0,0 +1,546 @@ +// BitmapSpriteEd - Bitmap Sprite Editor +// Copyright (C) 2005 Ian Cowburn +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// $Id$ +// +using System; +using System.Drawing; +using System.IO; +using System.Collections; + +namespace BitmapSpriteEd +{ + /// + /// A sprite frame. + /// + public class Frame + { + public Frame(int width, int height) + { + CheckSize(width,height); + m_width=width; + m_height=height; + m_data=new Color[m_width,m_height]; + Clear(Color.Transparent); + m_changed=false; + } + + public Frame() : this(16,16) + { + } + + public Frame(Frame old) + { + m_width=old.m_width; + m_height=old.m_height; + m_data=new Color[m_width,m_height]; + + for(int x=0;x=0 && nx=0 && ny=0 && nx=0 && ny + /// Describes a set of sprite frames that make up a single sprite + /// + public class Sprite : IEnumerable + { + // ------------------------------------------------ + // PUBLIC + // + public Sprite() + { + m_changed=false; + m_name="Untitled"; + m_frames=new ArrayList(); + m_frames.Add(new Frame(16,16)); + } + + public IEnumerator GetEnumerator() + { + return m_frames.GetEnumerator(); + } + + public string Name + { + get {return m_name;} + set {m_name=value;} + } + + public static bool IsValidNameChar(char c) + { + return (Char.IsLetterOrDigit(c) || c=='_'); + } + + public Frame this[int i] + { + get + { + return (Frame)m_frames[i]; + } + set + { + m_frames[i]=value; + m_changed=true; + } + } + + public void Add(Frame s) + { + m_frames.Add(s); + m_changed=true; + } + + public void Remove(Frame s) + { + m_frames.Remove(s); + m_changed=true; + } + + public bool Changed + { + get + { + if (!m_changed) + { + foreach (Frame s in m_frames) + { + if (s.Changed) + { + return true; + } + } + } + + return m_changed; + } + set {m_changed=value;} + } + + public int Count + { + get {return m_frames.Count;} + } + + public void Output(Stream stream) + { + Util.WriteString(stream,m_name); + Util.WriteInt(stream,m_frames.Count); + + foreach (Frame s in m_frames) + { + s.Output(stream); + } + + m_changed=false; + } + + public static Sprite Input(Stream stream) + { + Sprite fr=new Sprite(); + + fr.Name=Util.ReadString(stream); + + int num=Util.ReadInt(stream); + + for(int f=0;f + /// Describes a list of sprites + /// + public class SpriteList : IEnumerable + { + // ------------------------------------------------ + // PUBLIC + // + public SpriteList() + { + m_changed=false; + m_list=new ArrayList(); + } + + public IEnumerator GetEnumerator() + { + return m_list.GetEnumerator(); + } + + public Sprite this[int i] + { + get + { + return (Sprite)m_list[i]; + } + set + { + m_list[i]=value; + m_changed=true; + } + } + + public void Add(Sprite s) + { + m_list.Add(s); + m_changed=true; + } + + public void Remove(Sprite s) + { + m_list.Remove(s); + m_changed=true; + } + + public bool Changed + { + get + { + if (!m_changed) + { + foreach (Sprite s in m_list) + { + if (s.Changed) + { + return true; + } + } + } + + return m_changed; + } + + set {m_changed=value;} + } + + public int Count + { + get {return m_list.Count;} + } + + public void Validate() + { + int num=m_list.Count; + + for(int i=0;i