// 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.Drawing.Imaging;
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)
{
CopyFrom(old);
}
public void CopyFrom(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=0 && nx=0 && ny=0 && nx=0 && ny0)
{
m_data[x,y]=to;
}
}
}
m_changed=true;
}
public void Output(Stream stream)
{
Util.WriteInt(stream,m_width);
Util.WriteInt(stream,m_height);
for(int x=0;x
/// Describes a set of sprite frames that make up a single sprite
///
public class Sprite : IEnumerable
{
// ------------------------------------------------
// PUBLIC
//
public Sprite()
{
m_changed=false;
m_name="";
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.m_frames.Clear();
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