Пример #1
0
        public void Add(IAction action)
        {
            if(action.GetType() == typeof(SelectionAction) && firstSelectionAction == null)
                firstSelectionAction = (SelectionAction)action;
            else if (action.GetType() == typeof(BiomeAction) && firstBiomeAction == null)
                firstBiomeAction = (BiomeAction)action;
            else if (action.GetType() == typeof(PopulateAction) && firstPopulateAction == null)
                firstPopulateAction = (PopulateAction)action;

            //ensure the first action of each type isn't lost when the redo stack is emptied
            if(firstSelectionAction != null && action != firstSelectionAction && redoStack.Contains(firstSelectionAction))
            {
                redoStack.Remove(firstSelectionAction);
                undoStack.AddLast(firstSelectionAction);
            }
            if (firstBiomeAction != null && action != firstBiomeAction && redoStack.Contains(firstBiomeAction))
            {
                redoStack.Remove(firstBiomeAction);
                undoStack.AddLast(firstBiomeAction);
            }
            if (firstPopulateAction != null && action != firstPopulateAction && redoStack.Contains(firstPopulateAction))
            {
                redoStack.Remove(firstPopulateAction);
                undoStack.AddLast(firstPopulateAction);
            }

            action.PreviousAction = GetPreviousAction(undoStack.Last, action.GetType());
            undoStack.AddLast(action);
            foreach (IAction a in redoStack)
                a.Dispose();
            redoStack.Clear();
        }
Пример #2
0
 private void ApplySelectionState(SelectionAction action, Bitmap selection)
 {
     using (Graphics g = Graphics.FromImage(selection))
     {
         g.CompositingMode = CompositingMode.SourceCopy;
         g.DrawImage(action.Image, 0, 0);
     }
 }
Пример #3
0
        public void FilterOutType(Type type)
        {
            LinkedList <IAction> newUndo = new LinkedList <IAction>();

            foreach (IAction action in undoStack)
            {
                if (type.Equals(action.GetType()))
                {
                    action.Dispose();
                }
                else
                {
                    newUndo.AddLast(action);
                }
            }

            undoStack = newUndo;

            LinkedList <IAction> newRedo = new LinkedList <IAction>();

            foreach (IAction action in redoStack)
            {
                if (type.Equals(action.GetType()))
                {
                    action.Dispose();
                }
                else
                {
                    newRedo.AddLast(action);
                }
            }

            if (firstBiomeAction != null && type == typeof(BiomeAction))
            {
                firstBiomeAction = null;
            }
            if (firstPopulateAction != null && type == typeof(PopulateAction))
            {
                firstPopulateAction = null;
            }
            if (firstSelectionAction != null && type == typeof(SelectionAction))
            {
                firstSelectionAction = null;
            }

            redoStack = newRedo;
        }
Пример #4
0
        public void Add(IAction action)
        {
            if (action.GetType() == typeof(SelectionAction) && firstSelectionAction == null)
            {
                firstSelectionAction = (SelectionAction)action;
            }
            else if (action.GetType() == typeof(BiomeAction) && firstBiomeAction == null)
            {
                firstBiomeAction = (BiomeAction)action;
            }
            else if (action.GetType() == typeof(PopulateAction) && firstPopulateAction == null)
            {
                firstPopulateAction = (PopulateAction)action;
            }

            //ensure the first action of each type isn't lost when the redo stack is emptied
            if (firstSelectionAction != null && action != firstSelectionAction && redoStack.Contains(firstSelectionAction))
            {
                redoStack.Remove(firstSelectionAction);
                undoStack.AddLast(firstSelectionAction);
            }
            if (firstBiomeAction != null && action != firstBiomeAction && redoStack.Contains(firstBiomeAction))
            {
                redoStack.Remove(firstBiomeAction);
                undoStack.AddLast(firstBiomeAction);
            }
            if (firstPopulateAction != null && action != firstPopulateAction && redoStack.Contains(firstPopulateAction))
            {
                redoStack.Remove(firstPopulateAction);
                undoStack.AddLast(firstPopulateAction);
            }

            action.PreviousAction = GetPreviousAction(undoStack.Last, action.GetType());
            undoStack.AddLast(action);
            foreach (IAction a in redoStack)
            {
                a.Dispose();
            }
            redoStack.Clear();
        }
Пример #5
0
        public void FilterOutType(Type type)
        {
            LinkedList<IAction> newUndo = new LinkedList<IAction>();

            foreach (IAction action in undoStack)
            {
                if (type.Equals(action.GetType()))
                    action.Dispose();
                else
                    newUndo.AddLast(action);
            }

            undoStack = newUndo;

            LinkedList<IAction> newRedo = new LinkedList<IAction>();

            foreach (IAction action in redoStack)
            {
                if (type.Equals(action.GetType()))
                    action.Dispose();
                else
                    newRedo.AddLast(action);
            }

            if (firstBiomeAction != null && type == typeof(BiomeAction))
                firstBiomeAction = null;
            if (firstPopulateAction != null && type == typeof(PopulateAction))
                firstPopulateAction = null;
            if (firstSelectionAction != null && type == typeof(SelectionAction))
                firstSelectionAction = null;

            redoStack = newRedo;
        }
Пример #6
0
 private void ApplySelectionState(SelectionAction action, Bitmap selection)
 {
     using (Graphics g = Graphics.FromImage(selection))
     {
         g.CompositingMode = CompositingMode.SourceCopy;
         g.DrawImage(action.Image, 0, 0);
     }
 }