private void curveListView_AfterLabelEdit(object sender, LabelEditEventArgs e) { if (disableUIEvents > 0) { return; } // Label edit has been canceled. if (String.IsNullOrEmpty(e.Label)) { return; } // commandHistory.BeginRecordCommands(); curveControl.BeginUpdate(); string newName = EnsureUniqueName(e.Label); e.CancelEdit = String.Compare(newName, e.Label) != 0; curveListView.Items[e.Item].Text = newName; EditCurve curve = CurveFileInfo.GetCurve(curveListView.Items[e.Item]); curve.Name = newName; curveControl.EndUpdate(); commandHistory.EndRecordCommands(); }
private ListViewItem CreateCurve(EditCurve editCurve, string name) { editCurve.Id = GenerateUniqueCurveId(); editCurve.StateChanged += new EventHandler(editCurve_StateChanged); ListViewItem item = new ListViewItem(name); item.Checked = true; CurveFileInfo.AssignCurve(item, editCurve); idToItemMap.Add(editCurve.Id, item); ArrayList oldItems = new ArrayList(curveListView.Items); ArrayList oldSelection = new ArrayList(curveListView.SelectedItems); ArrayList newItems = new ArrayList(curveListView.Items); ListViewItem[] newSelection = { item }; newItems.Add(item); //curveListView.Items.Add(item); //curveListView.SelectedItems.Clear(); //item.Selected = true; commandHistory.BeginRecordCommands(); commandHistory.Do(new CurveAddRemoveCommand(this, oldItems, newItems, oldSelection, newSelection)); UpdateCurveEditables(); commandHistory.EndRecordCommands(); return(item); }
public SelectCommand(EditCurve curve, EditCurveKeySelection newSelection, EditCurveKeySelection oldSelection) { this.curve = curve; this.oldSelection = oldSelection; this.newSelection = newSelection; }
protected override void OnFormClosing(FormClosingEventArgs e) { foreach (ListViewItem item in curveListView.Items) { EditCurve curve = CurveFileInfo.GetCurve(item); if (curve.Dirty) { DialogResult dr = MessageBox.Show( String.Format(CurveEditorResources.SaveMessage, curve.Name), CurveEditorResources.CurveEditorTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation); if (dr == DialogResult.Yes) { dr = SaveCurve(item, false); } if (dr == DialogResult.Cancel) { e.Cancel = true; break; } } } base.OnFormClosing(e); }
public SelectCommand(EditCurve curve, EditCurveKeySelection newSelection, EditCurveKeySelection oldSelection) { this.curve = curve; this.oldSelection = oldSelection; this.newSelection = newSelection; }
public EditCurveKeyUpdateCommand(EditCurve curve, ICollection <EditCurveKey> oldKeyValues, ICollection <EditCurveKey> newKeyValues) { this.curve = curve; this.oldKeyValues = oldKeyValues; this.newKeyValues = newKeyValues; }
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 EditCurveKeyAddRemoveCommand(EditCurve curve, ICollection<EditCurveKey> deleteKeys) { this.curve = curve; addKey = false; keys = new List<EditCurveKey>(deleteKeys.Count); foreach ( EditCurveKey key in deleteKeys ) keys.Add(key.Clone()); }
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 EditCurveKeyAddRemoveCommand(EditCurve curve, ICollection <EditCurveKey> deleteKeys) { this.curve = curve; addKey = false; keys = new List <EditCurveKey>(deleteKeys.Count); foreach (EditCurveKey key in deleteKeys) { keys.Add(key.Clone()); } }
private void editCurve_StateChanged(object sender, EventArgs e) { disableUIEvents++; curveListView.BeginUpdate(); EditCurve curve = sender as EditCurve; ListViewItem item = idToItemMap[curve.Id]; item.Text = curve.Name; disableUIEvents--; curveListView.EndUpdate(); }
private ListViewItem CreateCurve() { string name = EnsureUniqueName("Curve"); Curve curve = new Curve(); curve.Keys.Add(new CurveKey(0, 0)); EditCurve editCurve = new EditCurve(name, NextCurveColor(), curve, commandHistory); editCurve.Dirty = true; return(CreateCurve(editCurve, name)); }
/// <summary> /// Load a Curve from given filename. /// </summary> /// <param name="filename"></param> /// <param name="name"></param> /// <param name="color"></param> /// <param name="commandHistory"></param> /// <returns></returns> public static EditCurve LoadFromFile(string filename, string name, System.Drawing.Color color, CommandHistory commandHistory) { EditCurve editCurve = null; using (XmlReader xr = XmlReader.Create(filename)) { Curve curve = IntermediateSerializer.Deserialize <Curve>(xr, Path.GetDirectoryName(filename)); editCurve = new EditCurve(name, color, curve, commandHistory); } return(editCurve); }
/// <summary> /// Create new instance of EditCurveKeyCollection from Curve instance. /// </summary> /// <param name="curve"></param> internal EditCurveKeyCollection(EditCurve owner) { // Generate EditCurveKey list from Curve class. this.owner = owner; foreach (CurveKey key in owner.OriginalCurve.Keys) { // Add EditCurveKey to keys. int index = owner.OriginalCurve.Keys.IndexOf(key); EditCurveKey newKey = new EditCurveKey(EditCurveKey.GenerateUniqueId(), key); keys.Insert(index, newKey); idToKeyMap.Add(newKey.Id, newKey); } }
/// <summary> /// Load a Curve from given filename. /// </summary> /// <param name="filename"></param> /// <param name="name"></param> /// <param name="color"></param> /// <param name="commandHistory"></param> /// <returns></returns> public static EditCurve LoadFromFile(string filename, string name, System.Drawing.Color color, CommandHistory commandHistory) { EditCurve editCurve = null; using (XmlReader xr = XmlReader.Create(filename)) { throw new NotImplementedException("IntermediateSerializer.Deserialize<Curve>() has not been implemented in this fork."); //Curve curve = IntermediateSerializer.Deserialize<Curve>(xr, // Path.GetDirectoryName(filename)); //editCurve = new EditCurve(name, color, curve, commandHistory); } return(editCurve); }
public EditCurveStateChangeCommand(EditCurve curve, EditCurveState oldState, EditCurveState newState) { if (oldState == null) { throw new ArgumentNullException("oldState"); } if (newState == null) { throw new ArgumentNullException("newState"); } this.curve = curve; this.oldState = (EditCurveState)oldState.Clone(); this.newState = (EditCurveState)newState.Clone(); }
private void DrawTangents(Graphics g, EditCurve curve) { System.Drawing.Color[] colors = new System.Drawing.Color[] { System.Drawing.Color.Yellow, System.Drawing.Color.Brown }; float len = 50.0f; Vector2 pt1 = new Vector2(); EditCurveSelections tangentSelection = EditCurveSelections.Key | EditCurveSelections.TangentIn | EditCurveSelections.TangentOut; for (int i = 0; i < curve.Keys.Count; ++i) { EditCurveKey editKey = curve.Keys[i]; CurveKey key = editKey.OriginalKey; EditCurveSelections selection = editKey.Selection; bool isSelecting = (selection & tangentSelection) != 0; if (((isSelecting && curve.Editable) || curveTangentsViewMode == EditCurveView.Always) && key.Continuity == CurveContinuity.Smooth) { pt1 = curveView.ToPixelCoordinate(key.Position, key.Value); int colIdx = 0; float screen_tangent; // tan-in. colIdx = (selection & EditCurveSelections.TangentIn) != 0 ? 0 : 1; screen_tangent = curveView.UnitToScreenTangentAngle( key.TangentIn / curve.GetDistanceOfKeys(i, 0)); DrawArrow(g, pt1, (float)Math.PI + (float)Math.Atan(screen_tangent), len, colors[colIdx]); // tan-out. colIdx = (selection & EditCurveSelections.TangentOut) != 0 ? 0 : 1; screen_tangent = curveView.UnitToScreenTangentAngle( key.TangentOut / curve.GetDistanceOfKeys(i, 1)); DrawArrow(g, pt1, (float)Math.Atan(screen_tangent), len, colors[colIdx]); } } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() != DialogResult.OK) { return; } foreach (string filename in openFileDialog1.FileNames) { string name = EnsureUniqueName(Path.GetFileNameWithoutExtension(filename)); EditCurve editCurve = EditCurve.LoadFromFile(filename, name, NextCurveColor(), commandHistory); ListViewItem item = CreateCurve(editCurve, name); CurveFileInfo.AssignFilename(item, filename); } }
private void DrawCurveSections(Graphics g, Pen pen, EditCurve curve, double t0, double t1, double step) { Vector2[] p = new Vector2[2] { new Vector2(), new Vector2() }; int pIdx = 0; p[pIdx] = curveView.ToPixelCoordinate((float)t0, curve.Evaluate((float)t0)); for (double t = t0; t < t1;) { double nextT = t + step; t = nextT; pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate((float)t, curve.Evaluate((float)t)); DrawLine(g, pen, p[0], p[1]); t = nextT; } }
public EditCurveKeyUpdateCommand(EditCurve curve, ICollection<EditCurveKey> oldKeyValues, ICollection<EditCurveKey> newKeyValues) { this.curve = curve; this.oldKeyValues = oldKeyValues; this.newKeyValues = newKeyValues; }
private void curveView_MouseUp(object sender, MouseEventArgs e) { if ((e.Button & MouseButtons.Left) != MouseButtons.Left) { return; } if (!mousePressing) { return; } mousePressing = false; // Quit if edtable is false. if (!editable) { return; } EditMode em = (quickEditMode != EditMode.None) ? quickEditMode : editMode; switch (em) { case EditMode.Add: Vector2 pos_us = curveView.ToUnitCoordinate(prevMousePos); MathHelper.Clamp(pos_us.X, -1f * MaximumCurveKeyEntry, MaximumCurveKeyEntry); MathHelper.Clamp(pos_us.Y, -1f * MaximumCurveKeyEntry, MaximumCurveKeyEntry); UpdateCurves(delegate(EditCurve curve) { curve.AddKey(pos_us); }); break; case EditMode.Move: // Finish move curves. BeginCaptureCommands(); EndUpdateCurves(); EndCaptureCommands(); RequestRender(); break; case EditMode.Select: bool singleSelect = false; // adjust selecting box if select area is too small. if (selectingBox.Width < MinSelectSize || selectingBox.Height < MinSelectSize) { selectingBox.X += (selectingBox.Width - MinSelectSize) * 0.5f; selectingBox.Y += (selectingBox.Height - MinSelectSize) * 0.5f; selectingBox.Width = selectingBox.Height = MinSelectSize; singleSelect = true; } BoundingBox selectRegion = new BoundingBox( new Vector3(curveView.ToUnitCoordinate(selectingBox.Left, selectingBox.Bottom), -1), new Vector3(curveView.ToUnitCoordinate(selectingBox.Right, selectingBox.Top), 1)); Vector2 tangentScale = new Vector2( (float)curveView.ScaleX * TangentManipulatorLength, (float)curveView.ScaleY * TangentManipulatorLength); // Check selection front to back. bool selected = false; int curveCount = curves.Count; while (curveCount-- > 0) { EditCurve curve = curves[curveCount]; if (!curve.Editable || !curve.Visible) { continue; } if (singleSelect && selected) { curve.ClearSelection(); } else { curve.Select(selectRegion, tangentScale, curveKeyViewMode, curveTangentsViewMode, ModifierKeys == Keys.Shift, singleSelect); selected = (singleSelect && curve.Selection.Count != 0); } } selectingBox = RectangleF.Empty; CheckSelection(); RequestRender(); break; } }
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; }
/// <summary> /// Load a Curve from given filename. /// </summary> /// <param name="filename"></param> /// <param name="name"></param> /// <param name="color"></param> /// <param name="commandHistory"></param> /// <returns></returns> public static EditCurve LoadFromFile(string filename, string name, System.Drawing.Color color, CommandHistory commandHistory) { EditCurve editCurve = null; using (XmlReader xr = XmlReader.Create(filename)) { Curve curve = IntermediateSerializer.Deserialize<Curve>(xr, Path.GetDirectoryName(filename)); editCurve = new EditCurve(name, color, curve, commandHistory); } return editCurve; }
public EditCurveEventArgs(EditCurve curve) { Curve = curve; }
public static void AssignCurve( ListViewItem item, EditCurve curve ) { CurveFileInfo cfi = EnsureFileInfo(item); cfi.Curve = curve; }
private ListViewItem CreateCurve() { string name = EnsureUniqueName("Curve"); Curve curve = new Curve(); curve.Keys.Add(new CurveKey(0, 0)); EditCurve editCurve = new EditCurve(name, NextCurveColor(), curve, commandHistory); editCurve.Dirty = true; return CreateCurve(editCurve, name); }
private ListViewItem CreateCurve(EditCurve editCurve, string name) { editCurve.Id = GenerateUniqueCurveId(); editCurve.StateChanged += new EventHandler(editCurve_StateChanged); ListViewItem item = new ListViewItem(name); item.Checked = true; CurveFileInfo.AssignCurve(item, editCurve); idToItemMap.Add(editCurve.Id, item); ArrayList oldItems = new ArrayList(curveListView.Items); ArrayList oldSelection = new ArrayList(curveListView.SelectedItems); ArrayList newItems = new ArrayList(curveListView.Items); ListViewItem[] newSelection = { item }; newItems.Add(item); //curveListView.Items.Add(item); //curveListView.SelectedItems.Clear(); //item.Selected = true; commandHistory.BeginRecordCommands(); commandHistory.Do( new CurveAddRemoveCommand(this, oldItems, newItems, oldSelection, newSelection)); UpdateCurveEditables(); commandHistory.EndRecordCommands(); return item; }
public EditCurveStateChangeCommand(EditCurve curve, EditCurveState oldState, EditCurveState newState) { if (oldState == null) throw new ArgumentNullException("oldState"); if (newState == null) throw new ArgumentNullException("newState"); this.curve = curve; this.oldState = (EditCurveState)oldState.Clone(); this.newState = (EditCurveState)newState.Clone(); }
/// <summary> /// Draw actual part of curve. /// </summary> /// <param name="g"></param> /// <param name="pen"></param> /// <param name="curve"></param> /// <param name="t0"></param> /// <param name="t1"></param> /// <param name="step"></param> private void DrawCurve(Graphics g, Pen pen, EditCurve curve, double t0, double t1, double step) { Vector2[] p = new Vector2[2] { new Vector2(), new Vector2() }; // Search key and next key that includes t0 position. int keyIndex = 0; EditCurveKey key = null, nextKey = null; for (; keyIndex < curve.Keys.Count; ++keyIndex) { key = nextKey; nextKey = curve.Keys[keyIndex]; if (nextKey.Position > t0) break; } int pIdx = 0; p[pIdx] = curveView.ToPixelCoordinate((float)t0, curve.Evaluate((float)t0)); for (double t = t0; t < t1;) { double nextT = t1 + step; if (nextKey != null) nextT = Math.Min(t1, nextKey.Position); // Draw current key and next key section. if (key.Continuity == CurveContinuity.Smooth) { while (t < nextT) { // If this line crosses next key position, draw line from // current position to next key position. t = ( t < nextT && t + step > nextT )? nextT: t + step; pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate( (float)t, curve.Evaluate((float)t)); DrawLine(g, pen, p[0], p[1]); } } else { // Step case, // Draw, horizontal line. pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate(nextKey.Position, key.Value); DrawLine(g, pen, p[0], p[1]); // Draw vertical line. pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate( nextKey.Position, nextKey.Value); DrawLine(g, pen, p[0], p[1]); t = nextT; } // Advance to next key. key = nextKey; nextKey = (++keyIndex < curve.Keys.Count) ? curve.Keys[keyIndex] : null; } }
private void DrawTangents(Graphics g, EditCurve curve) { System.Drawing.Color[] colors = new System.Drawing.Color[] { System.Drawing.Color.Yellow, System.Drawing.Color.Brown }; float len = 50.0f; Vector2 pt1 = new Vector2(); EditCurveSelections tangentSelection = EditCurveSelections.Key | EditCurveSelections.TangentIn | EditCurveSelections.TangentOut; for (int i = 0; i < curve.Keys.Count; ++i) { EditCurveKey editKey = curve.Keys[i]; CurveKey key = editKey.OriginalKey; EditCurveSelections selection = editKey.Selection; bool isSelecting = (selection & tangentSelection) != 0; if (((isSelecting && curve.Editable) || curveTangentsViewMode == EditCurveView.Always) && key.Continuity == CurveContinuity.Smooth) { pt1 = curveView.ToPixelCoordinate(key.Position, key.Value); int colIdx = 0; float screen_tangent; // tan-in. colIdx = (selection & EditCurveSelections.TangentIn) != 0 ? 0 : 1; screen_tangent = curveView.UnitToScreenTangentAngle( key.TangentIn / curve.GetDistanceOfKeys(i, 0)); DrawArrow(g, pt1, (float)Math.PI + (float)Math.Atan(screen_tangent), len, colors[colIdx]); // tan-out. colIdx = (selection & EditCurveSelections.TangentOut) != 0 ? 0 : 1; screen_tangent = curveView.UnitToScreenTangentAngle( key.TangentOut / curve.GetDistanceOfKeys(i, 1)); DrawArrow(g, pt1, (float)Math.Atan(screen_tangent), len, colors[colIdx]); } } }
private void DrawCurveSections(Graphics g, Pen pen, EditCurve curve, double t0, double t1, double step) { Vector2[] p = new Vector2[2] { new Vector2(), new Vector2() }; int pIdx = 0; p[pIdx] = curveView.ToPixelCoordinate((float)t0, curve.Evaluate((float)t0)); for (double t = t0; t < t1; ) { double nextT = t + step; t = nextT; pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate((float)t, curve.Evaluate((float)t)); DrawLine(g, pen, p[0], p[1]); t = nextT; } }
/// <summary> /// Draw actual part of curve. /// </summary> /// <param name="g"></param> /// <param name="pen"></param> /// <param name="curve"></param> /// <param name="t0"></param> /// <param name="t1"></param> /// <param name="step"></param> private void DrawCurve(Graphics g, Pen pen, EditCurve curve, double t0, double t1, double step) { Vector2[] p = new Vector2[2] { new Vector2(), new Vector2() }; // Search key and next key that includes t0 position. int keyIndex = 0; EditCurveKey key = null, nextKey = null; for (; keyIndex < curve.Keys.Count; ++keyIndex) { key = nextKey; nextKey = curve.Keys[keyIndex]; if (nextKey.Position > t0) { break; } } int pIdx = 0; p[pIdx] = curveView.ToPixelCoordinate((float)t0, curve.Evaluate((float)t0)); for (double t = t0; t < t1;) { double nextT = t1 + step; if (nextKey != null) { nextT = Math.Min(t1, nextKey.Position); } // Draw current key and next key section. if (key.Continuity == CurveContinuity.Smooth) { while (t < nextT) { // If this line crosses next key position, draw line from // current position to next key position. t = (t <nextT && t + step> nextT)? nextT: t + step; pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate( (float)t, curve.Evaluate((float)t)); DrawLine(g, pen, p[0], p[1]); } } else { // Step case, // Draw, horizontal line. pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate(nextKey.Position, key.Value); DrawLine(g, pen, p[0], p[1]); // Draw vertical line. pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate( nextKey.Position, nextKey.Value); DrawLine(g, pen, p[0], p[1]); t = nextT; } // Advance to next key. key = nextKey; nextKey = (++keyIndex < curve.Keys.Count) ? curve.Keys[keyIndex] : null; } }
public static void AssignCurve(ListViewItem item, EditCurve curve) { CurveFileInfo cfi = EnsureFileInfo(item); cfi.Curve = curve; }