heh cancel is not really as difficult as it seems. The magic here is that you have to record each action as an object that is listed in a list or queue, f.ex, the user draws a line, so your entry may look like x, y start poing and x, y end point or it self object, which has a Draw () method, so canceling something will just delete this object.
in code that might look something like this:
interface IDrawObject
{
public void Draw();
}
class Line : IDrawObject
{
private Point _startP;
private Point _endP;
public Line(Point startPoint; Poing endPoint)
{
_startP = startPoint;
_endP = endPoint;
}
public void Draw()
{
}
}
class Rectangle : IDrawObject
{
public void Draw()
{
}
}
List<IDrawObject> myObjectsINeedToDraw = new List<IDrawObject>();
myObjectsINeedToDraw.Add(new Line(new Point(0, 0), new Point(10, 10));
foreach(IDrawObject objectToDraw in myObjectsINeedToDraw)
{
objectToDraw.Draw();
}
source
share