Пример #1
0
 private void Form1_MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         history.Do(new AddShapeMemento());
         shapepool.Add(GetShape(e));
     }
     else if (e.Button == MouseButtons.Right)
     {
         List <Shape> toBeRemoved = new List <Shape>();
         Rectangle    rect        = GetRect(e);
         foreach (Shape s in shapepool)
         {
             if (rect.Contains(s.Bound))
             {
                 toBeRemoved.Add(s);
             }
         }
         if (toBeRemoved.Count > 0)
         {
             history.BeginCompoundDo();
             foreach (Shape s in toBeRemoved)
             {
                 int index = shapepool.IndexOf(s);
                 history.Do(new RemoveShapeMemento(index, s));
                 shapepool.RemoveAt(index);
             }
             history.EndCompoundDo();
         }
     }
     Invalidate();
 }
Пример #2
0
        public override IMemento <ShapePool> Restore(ShapePool target)
        {
            int index = target.Count - 1;
            IMemento <ShapePool> inverse = new RemoveShapeMemento(index, target[index]);

            target.RemoveAt(target.Count - 1);
            return(inverse);
        }
Пример #3
0
        public override IMemento <ShapePool> Restore(ShapePool target)
        {
            Shape removed = target[index];
            IMemento <ShapePool> inverse = new RemoveShapeMemento(index, removed);

            target.RemoveAt(index);
            return(inverse);
        }