public bool Equals(EditCurveKeySelection other) { if (other == null) { return(false); } if (this.Count != other.Count) { return(false); } foreach (long key in Keys) { if (!other.ContainsKey(key)) { return(false); } if (this[key] != other[key]) { return(false); } } return(true); }
/// <summary> /// Create new selection that result of toggle selection given two selections. /// </summary> /// <param name="selection">Current selection</param> /// <param name="newSelection">New selection</param> /// <returns>Toggle selection result.</returns> public static EditCurveKeySelection ToggleSelection( EditCurveKeySelection selection, EditCurveKeySelection newSelection) { EditCurveKeySelection result = selection.Clone(); foreach (long key in newSelection.Keys) { EditCurveSelections s; if (result.TryGetValue(key, out s)) { // Both selection contains same key, toggle selections value. s = s ^ newSelection[key]; if (s != EditCurveSelections.None) { result[key] = s; } else { result.Remove(key); } } else { result.Add(key, newSelection[key]); } } return(result); }
public SelectCommand(EditCurve curve, EditCurveKeySelection newSelection, EditCurveKeySelection oldSelection) { this.curve = curve; this.oldSelection = oldSelection; this.newSelection = newSelection; }
public EditCurveKeyAddRemoveCommand(EditCurve curve, EditCurveKey addKey, EditCurveKeySelection selection) { this.curve = curve; this.addKey = true; this.selection = selection.Clone(); keys = new List <EditCurveKey>(); keys.Add(addKey.Clone()); }
public override bool Equals(object obj) { bool isSame = false; EditCurveKeySelection other = obj as EditCurveKeySelection; if (other != null) { isSame = Equals(other); } return(isSame); }
/// <summary> /// Create clone of a selection. /// </summary> /// <param name="selection"></param> /// <returns></returns> public EditCurveKeySelection Clone() { EditCurveKeySelection newSelection = new EditCurveKeySelection(); foreach (long keyId in Keys) { newSelection.Add(keyId, this[keyId]); } return(newSelection); }
/// <summary> /// Select keys and key tangents. /// </summary> /// <param name="selectRegion">Selection region in unit coordinate.</param> /// <param name="tangentScale">Tangent scale in unit coordinate.</param> /// <param name="keyView"></param> /// <param name="tangentView"></param> /// <param name="toggleSelection"></param> /// <param name="singleSelection"></param> public void Select(BoundingBox selectRegion, Vector2 tangentScale, EditCurveView keyView, EditCurveView tangentView, bool toggleSelection, bool singleSelect) { if (!Editable) { return; } EditCurveKeySelection newSelection = new EditCurveKeySelection(); // Check Intersection of Keys and Tangents. if (keyView != EditCurveView.Never) { ICollection <EditCurveKey> targetKeys = (keyView == EditCurveView.Always) ? (ICollection <EditCurveKey>)keys : (ICollection <EditCurveKey>)selectedKeys.Values; newSelection.SelectKeys(targetKeys, selectRegion, singleSelect); } // Check Tangents if any keys are not selected. if (newSelection.Count == 0 && tangentView != EditCurveView.Never) { ICollection <EditCurveKey> targetKeys = (tangentView == EditCurveView.Always) ? (ICollection <EditCurveKey>)keys : (ICollection <EditCurveKey>)selectedKeys.Values; newSelection.SelectTangents(targetKeys, selectRegion, tangentScale, singleSelect); } if (toggleSelection) { newSelection = EditCurveKeySelection.ToggleSelection( selection, newSelection); } ApplySelection(newSelection, true); }
/// <summary> /// Apply key selection. /// </summary> /// <param name="newSelection"></param> /// <param name="generateCommand"></param> public void ApplySelection(EditCurveKeySelection newSelection, bool generateCommand) { // Re-create selected keys and store selection information from // new selection. selectedKeys.Clear();; foreach (long id in newSelection.Keys) { EditCurveKey key = keys.GetValue(id); key.Selection = newSelection[id]; selectedKeys.Add(key.Id, key); } // Clear de-selected keys selection information. foreach (long id in selection.Keys) { if (!newSelection.ContainsKey(id)) { EditCurveKey key; if (keys.TryGetValue(id, out key)) { key.Selection = EditCurveSelections.None; } } } // Invoke selection change event. if (generateCommand == true && !newSelection.Equals(selection) && commandHistory != null) { commandHistory.Add(new SelectCommand(this, newSelection, selection)); } // Update selection. selection = newSelection; }
private void CheckSelection() { // Make sure it selected single key. CommonState <CurveLoopType> preLoop = new CommonState <CurveLoopType>(); CommonState <CurveLoopType> postLoop = new CommonState <CurveLoopType>(); CommonState <EditCurveTangent> tangentInType = new CommonState <EditCurveTangent>(); CommonState <EditCurveTangent> tangentOutType = new CommonState <EditCurveTangent>(); int totalSelectCount = 0; EditCurve lastSelectedCurve = null; foreach (EditCurve curve in curves) { if (!curve.Editable || !curve.Visible || curve.Selection.Count == 0) { continue; } EditCurveKeySelection selection = curve.Selection; totalSelectCount += selection.Count; lastSelectedCurve = curve; preLoop.Add(curve.PreLoop); postLoop.Add(curve.PostLoop); foreach (long id in selection.Keys) { EditCurveKey key; if (curve.Keys.TryGetValue(id, out key)) { if (key.Continuity == CurveContinuity.Smooth) { tangentInType.Add(key.TangentInType); tangentOutType.Add(key.TangentOutType); } else { tangentInType.Add(EditCurveTangent.Stepped); tangentOutType.Add(EditCurveTangent.Stepped); } } } } // Update Menus. CheckMenuItem(preInfinityToolStripMenuItem, preLoop.ValueString); CheckMenuItem(postInfinityToolStripMenuItem, postLoop.ValueString); bool sameValueString = String.Compare(tangentInType.ValueString, tangentOutType.ValueString) == 0; string tangentsString = sameValueString? tangentInType.ValueString : String.Empty; CheckMenuItem(tangentsToolStripMenuItem, tangentsString); CheckMenuItem(inTangentToolStripMenuItem, tangentInType.ValueString); CheckMenuItem(outTangentToolStripMenuItem, tangentOutType.ValueString); // Are we just select one key? singleEditUpdating = true; if (totalSelectCount == 1) { singleEditCurve = lastSelectedCurve; EditCurveKey[] keys = lastSelectedCurve.GetSelectedKeys(); singleEditKey = keys[0]; keyPositionTextBox.Text = String.Format("{0:F3}", singleEditKey.Position); keyValueTextBox.Text = String.Format("{0:F3}", singleEditKey.Value); keyPositionLabel.Enabled = keyValueLabel.Enabled = keyPositionTextBox.Enabled = keyValueTextBox.Enabled = true; } else { singleEditKey = null; singleEditCurve = null; keyPositionTextBox.Text = keyValueTextBox.Text = String.Empty; keyPositionLabel.Enabled = keyValueLabel.Enabled = keyPositionTextBox.Enabled = keyValueTextBox.Enabled = false; } singleEditUpdating = false; }