Drawable shape;
int ClickedShape = -1;
ArrayList primitives = new ArrayList();
List<ArrayList> Undo = new List<ArrayList>();
int startx = 0;
int starty = 0;
bool CanMove = false;
int UndoPosition = 0;
private void button1_Click(object sender, EventArgs e)
{
GraphicsPath path = new GraphicsPath();
Rectangle r = new Rectangle(10, 10, 45, 45);
path.AddRectangle(r);
primitives.Add(new Shape(path, Color.Red));
GraphicsPath path2 = new GraphicsPath();
Rectangle r2 = new Rectangle(50, 10, 45, 45);
path2.AddRectangle(r2);
primitives.Add(new Shape(path2, Color.Green));
Draw();
[COLOR=Red]ArrayList Temp = new ArrayList();
foreach (Shape s in primitives)
{
Shape te = new Shape(s.GraphicsPath, s.Color);
Temp.Add(te);
}
Undo.Add(Temp);[/COLOR] }
private void button2_Click(object sender, EventArgs e)
{
primitives.Reverse(ClickedShape, 2);
Draw();
}
private void pane1_MouseMove(object sender, MouseEventArgs e)
{
if (CanMove == true)
{
shape = ((Drawable)(primitives[ClickedShape]));
shape.Move(new Point(e.X, e.Y), new Point(startx, starty));
Draw();
}
}
private void pane1_MouseDown(object sender, MouseEventArgs e)
{
foreach (Shape s in primitives)
{
if(s.GraphicsPath.IsVisible(e.X,e.Y))
{
CanMove = true;
ClickedShape = primitives.IndexOf(s);
shape = ((Drawable)(primitives[ClickedShape]));
}
}
startx = e.X - (int)shape.GraphicsPath.GetBounds().X;
starty = e.Y - (int)shape.GraphicsPath.GetBounds().Y;
}
private void pane1_MouseUp(object sender, MouseEventArgs e)
{
CanMove = false;
[COLOR=RoyalBlue]ArrayList Temp = new ArrayList();
foreach (Shape s in primitives)
{
Shape te = new Shape(s.GraphicsPath, s.Color);
Temp.Add(te);
}
Undo.Add(Temp);[/COLOR]
}
public void Draw()
{
Bitmap bat = new Bitmap(pane1.TempImage, pane1.Width, pane1.Height);
Image d = bat;
Graphics graphics = Graphics.FromImage(d);
Drawable shapepy;
for (int i = 0; i <= primitives.Count - 1; i++)
{
shapepy = ((Drawable)(primitives[i]));
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.FillPath(new SolidBrush(Color.FromArgb(255, shapepy.Color.R, shapepy.Color.G, shapepy.Color.B)), shapepy.GraphicsPath);
graphics.DrawPath(new Pen(shapepy.Color, 2), shapepy.GraphicsPath);
}
pane1.Image = d;
}
private Image _Image()
{
Bitmap b = new Bitmap(pane1.Width, pane1.Height);
Rectangle rect2 = new Rectangle(0, 0, pane1.Width, pane1.Height);
pane1.DrawToBitmap(b, rect2);
return b;
}