Example #1
0
 private UndoRedoAction CreateItemUndoMoveAction(BoardItem item, Point posChange)
 {
     if (item is BackgroundInstance)
     {
         return(UndoRedoManager.BackgroundMoved((BackgroundInstance)item, new Point(((BackgroundInstance)item).BaseX + posChange.X, ((BackgroundInstance)item).BaseY + posChange.Y), new Point(((BackgroundInstance)item).BaseX, ((BackgroundInstance)item).BaseY)));
     }
     else
     {
         return(UndoRedoManager.ItemMoved(item, new Point(item.X + posChange.X, item.Y + posChange.Y), new Point(item.X, item.Y)));
     }
 }
Example #2
0
        public static void ClearBoundItems(Board board)
        {
            object[] keys = new object[board.Mouse.BoundItems.Count];
            //int i = 0;
            board.Mouse.BoundItems.Keys.CopyTo(keys, 0);

            /*foreach (DictionaryEntry entry in board.Mouse.BoundItems)
             * {
             *  keys[i] = entry.Key;
             *  i++;
             * }*/
            List <UndoRedoAction> undoActions = new List <UndoRedoAction>();
            bool addUndo;

            foreach (object key in keys)
            {
                BoardItem item = (BoardItem)key;
                addUndo = item.tempParent == null || !(item.tempParent.Parent is Mouse);
                board.Mouse.ReleaseItem(item);
                if (addUndo)
                {
                    if ((item is BackgroundInstance) && (((BackgroundInstance)item).BaseX != item.moveStartPos.X || ((BackgroundInstance)item).BaseY != item.moveStartPos.Y))
                    {
                        undoActions.Add(UndoRedoManager.BackgroundMoved((BackgroundInstance)item, new Point(item.moveStartPos.X, item.moveStartPos.Y), new Point(((BackgroundInstance)item).BaseX, ((BackgroundInstance)item).BaseY)));
                    }
                    else if (!(item is BackgroundInstance) && (item.X != item.moveStartPos.X || item.Y != item.moveStartPos.Y))
                    {
                        undoActions.Add(UndoRedoManager.ItemMoved(item, new Point(item.moveStartPos.X, item.moveStartPos.Y), new Point(item.X, item.Y)));
                    }
                }
            }
            if (undoActions.Count > 0)
            {
                board.UndoRedoMan.AddUndoBatch(undoActions);
            }
        }