private WUndoCommand CreateUndoActionForGizmo(bool isDone) { WUndoCommand undoAction = null; WActorNode[] actors = new WActorNode[m_selectionList.Count]; for (int i = 0; i < m_selectionList.Count; i++) { actors[i] = m_selectionList[i]; } switch (m_transformGizmo.Mode) { case FTransformMode.Translation: undoAction = new WTranslateActorAction(actors, this, m_transformGizmo.DeltaTranslation, m_transformGizmo.TransformSpace, isDone); break; case FTransformMode.Rotation: undoAction = new WRotateActorAction(actors, this, m_transformGizmo.DeltaRotation, m_transformGizmo.TransformSpace, isDone); break; case FTransformMode.Scale: undoAction = new WScaleActorAction(actors, this, m_transformGizmo.DeltaScale, isDone); Console.WriteLine(m_transformGizmo.DeltaScale); break; default: break; } return(undoAction); }
public override bool MergeWith(WUndoCommand withAction) { WRotateActorAction otherAction = withAction as WRotateActorAction; if (m_isDone || otherAction == null) { return(false); } bool arrayEquals = m_affectedActors.Count == otherAction.m_affectedActors.Count; if (arrayEquals) { for (int i = 0; i < m_affectedActors.Count; i++) { if (!otherAction.m_affectedActors.Contains(m_affectedActors[i])) { arrayEquals = false; break; } } } if (arrayEquals) { m_delta *= otherAction.m_delta; m_isDone = otherAction.m_isDone; return(true); } return(false); }
private WUndoCommand CreateUndoActionForGizmo(bool isDone) { WUndoCommand undoAction = null; var actors = EditorSelection.SelectedObjects; switch (m_transformGizmo.Mode) { case FTransformMode.Translation: undoAction = new WTranslateActorAction(actors, this, m_transformGizmo.DeltaTranslation, m_transformGizmo.TransformSpace, isDone); break; case FTransformMode.Rotation: undoAction = new WRotateActorAction(actors, this, m_transformGizmo.DeltaRotation, m_transformGizmo.TransformSpace, isDone); break; case FTransformMode.Scale: undoAction = new WScaleActorAction(actors, this, m_transformGizmo.DeltaScale, isDone); Console.WriteLine(m_transformGizmo.DeltaScale); break; default: break; } return(undoAction); }
/// <summary> /// Push a new <see cref="IAction"/> onto the <see cref="WUndoStack"/>, or merges it with the most recently executed command. /// This function executes the <see cref="IAction.Redo"/> function in either case. Calling this will clear the <see cref="WUndoStack"/>'s /// Redo stack, so the command will always end up being the top-most on the stack. /// </summary> /// <param name="command"></param> public void Push(WUndoCommand command) { // If we have an open macro, we push it to the macro instead of the stack, and when the macro is ended, that is when it is finally pushed to the stack. // command.GetType().IsSubclassOf(typeof(WUndoCommand)) will return false if we're pushing a WUndoCommand, ie: the end of a macro. if (m_macroParent != null && command.GetType().IsSubclassOf(typeof(WUndoCommand))) { command.SetParent(m_macroParent); return; } // Clear the redo stack when we add a new item to the undo stack. m_redoStack.Clear(); // Call the Redo function to apply the state change encapsulated by the IAction. command.Redo(); // Attempt to merge with our new action. If this fails, add our new action to the undo stack. WUndoCommand latestAction = m_undoStack.Peek(); if (latestAction == null) { m_undoStack.Push(command); } else if (!latestAction.MergeWith(command)) { m_undoStack.Push(command); } }
public void Redo() { if (!CanRedo) { return; } WUndoCommand action = m_redoStack.Pop(); action.Redo(); m_undoStack.Push(action); }
/// <summary> /// This ends the composition of the lastest macro created by <see cref="BeginMacro(string)"/>. /// </summary> public void EndMacro() { if (m_macroParent == null) { Console.WriteLine("WUndoStack: EndMacro called but no previous call to BeginMacro!"); return; } Push(m_macroParent); // Grab the parent, which will either be the next macro we want to end, or null meaning we have no macros left. m_macroParent = m_macroParent.Parent; }
public void SetParent(WUndoCommand parent) { // Remove us from the old parent if (m_parent != null) { m_parent.m_commandChildren.Remove(this); } m_parent = parent; if (m_parent != null) { m_parent.m_commandChildren.Add(this); } }
public void Redo() { if (!CanRedo) { return; } WUndoCommand action = m_redoStack.Pop(); m_isUndoingOrRedoing = true; action.Redo(); m_isUndoingOrRedoing = false; m_undoStack.Push(action); }
public WScaleActorAction(IEnumerable <WDOMNode> actors, IEditorModeGizmo mode, Vector3 delta, bool isDone, WUndoCommand parent = null) : base("Scale", parent) { m_affectedActors = new List <WDOMNode>(actors); m_mode = mode; m_delta = delta; m_isDone = isDone; }
public WTranslateActorAction(IEnumerable <WDOMNode> actors, IEditorModeGizmo mode, Vector3 delta, FTransformSpace transformSpace, bool isDone, WUndoCommand parent = null) : base("Move", parent) { m_affectedActors = new List <WDOMNode>(actors); m_mode = mode; m_delta = delta; m_isDone = isDone; m_transformSpace = transformSpace; }
public WTranslateCameraPropertyAction(IEnumerable <BindingVector3> properties, IEditorModeGizmo mode, Vector3 delta, FTransformSpace transformSpace, bool isDone, WUndoCommand parent = null) : base("Move", parent) { m_affectedProperties = new List <BindingVector3>(properties); m_mode = mode; m_delta = delta; m_isDone = isDone; m_transformSpace = transformSpace; }
public WTranslateActorAction(WDOMNode[] actors, WActorEditor actorEditor, Vector3 delta, FTransformSpace transformSpace, bool isDone, WUndoCommand parent = null) : base("Move", parent) { m_affectedActors = new List <WDOMNode>(actors); m_actorEditor = actorEditor; m_delta = delta; m_isDone = isDone; m_transformSpace = transformSpace; }
public virtual bool MergeWith(WUndoCommand withAction) { return(false); }
public WUndoCommand(string text, WUndoCommand parent = null) { SetParent(parent); m_text = text; m_commandChildren = new List <WUndoCommand>(); }
public override bool MergeWith(WUndoCommand withAction) { return(false); }
public WRotateActorAction(IEnumerable <WDOMNode> actors, WActorEditor actorEditor, Quaternion delta, FTransformSpace transformSpace, bool isDone, WUndoCommand parent = null) : base("Rotate", parent) { m_affectedActors = new List <WDOMNode>(actors); m_actorEditor = actorEditor; m_delta = delta; m_isDone = isDone; m_transformSpace = transformSpace; }
private void UpdateSelectionGizmo(WSceneView view) { if (!m_transformGizmo.Enabled && m_selectionList.Count > 0) { // Show the Transform Gizmo. m_transformGizmo.Enabled = true; m_transformGizmo.SetPosition(m_selectionList[0].Transform.Position); m_transformGizmo.SetLocalRotation(m_selectionList[0].Transform.Rotation); } else if (m_transformGizmo.Enabled && m_selectionList.Count == 0) { // Hide the Transform Gizmo. m_transformGizmo.Enabled = false; } if (!m_transformGizmo.Enabled) { return; } if (WInput.GetKeyDown(Key.Q) && !WInput.GetMouseButton(1)) { m_transformGizmo.SetMode(FTransformMode.None); } if (WInput.GetKeyDown(Key.W) && !WInput.GetMouseButton(1)) { m_transformGizmo.SetMode(FTransformMode.Translation); } if (WInput.GetKeyDown(Key.E) && !WInput.GetMouseButton(1)) { m_transformGizmo.SetMode(FTransformMode.Rotation); } if (WInput.GetKeyDown(Key.R) && !WInput.GetMouseButton(1)) { m_transformGizmo.SetMode(FTransformMode.Scale); } if (WInput.GetKeyDown(Key.OemOpenBrackets)) { m_transformGizmo.DecrementSize(); } if (WInput.GetKeyDown(Key.OemCloseBrackets)) { m_transformGizmo.IncrementSize(); } if (WInput.GetKeyDown(Key.OemTilde)) { if (m_transformGizmo.TransformSpace == FTransformSpace.World) { m_transformGizmo.SetTransformSpace(FTransformSpace.Local); } else { m_transformGizmo.SetTransformSpace(FTransformSpace.World); } UpdateGizmoTransform(); } if (WInput.GetMouseButtonDown(0)) { FRay mouseRay = view.ProjectScreenToWorld(WInput.MousePosition); if (m_transformGizmo.CheckSelectedAxes(mouseRay)) { m_transformGizmo.StartTransform(); } } if (WInput.GetMouseButtonUp(0)) { if (m_transformGizmo.IsTransforming) { // When we end let go of the gizmo, we want to make one last action which specifies that it is done, // so that the next gizmo move doesn't merge with the previous. WUndoCommand undoAction = CreateUndoActionForGizmo(true); if (undoAction != null) { m_world.UndoStack.Push(undoAction); } m_transformGizmo.EndTransform(); } } if (m_transformGizmo.IsTransforming) { FRay mouseRay = view.ProjectScreenToWorld(WInput.MousePosition); if (m_transformGizmo.TransformFromInput(mouseRay, view)) { WUndoCommand undoAction = CreateUndoActionForGizmo(false); if (undoAction != null) { m_world.UndoStack.Push(undoAction); } } } m_transformGizmo.UpdateForSceneView(view); }
public WScaleActorAction(WDOMNode[] actors, WActorEditor actorEditor, Vector3 delta, bool isDone, WUndoCommand parent = null) : base("Scale", parent) { m_affectedActors = new List <WDOMNode>(actors); m_actorEditor = actorEditor; m_delta = delta; m_isDone = isDone; }
/// <summary> /// Pushes an empty command with the specified actionText onto the Undo/Redo stack. Any subsequent commands /// pushed onto the stack will be appended to the empty command's children until <see cref="EndMacro"/> is called. /// /// You can nestle BeginMacro/EndMacro calls, but every Begin must have an End, and while a macro is being composed /// the stack is disabled. Disabling the stack means that CanUndo and CanRedo return false, and attempting to Undo /// or Redo will fail. /// </summary> /// <param name="actionText"></param> public void BeginMacro(string actionText) { WUndoCommand macroCommand = new WUndoCommand(actionText, m_macroParent); m_macroParent = macroCommand; }
public WUndoCommand(WUndoCommand parent = null) { SetParent(parent); m_text = string.Empty; m_commandChildren = new List <WUndoCommand>(); }
public WEditPropertyValueAction(Action onUndo, Action onRedo, Action onPropertyChanged, WUndoCommand parent = null) : base("Value", parent) { if (onUndo == null) { throw new ArgumentNullException("onUndo", "Undo callback cannot be null."); } if (onRedo == null) { throw new ArgumentNullException("onRedo", "Redo callback cannot be null."); } if (onPropertyChanged == null) { throw new ArgumentNullException("onPropertyChanged", "On Property Changed callback cannot be null."); } m_undoAction = onUndo; m_redoAction = onRedo; m_onPropertyChanged = onPropertyChanged; }