예제 #1
0
 public SelectCommand(EditCurve curve, EditCurveKeySelection newSelection,
                      EditCurveKeySelection oldSelection)
 {
     this.curve        = curve;
     this.oldSelection = oldSelection;
     this.newSelection = newSelection;
 }
예제 #2
0
 public EditCurveKeyUpdateCommand(EditCurve curve,
                                  ICollection <EditCurveKey> oldKeyValues,
                                  ICollection <EditCurveKey> newKeyValues)
 {
     this.curve        = curve;
     this.oldKeyValues = oldKeyValues;
     this.newKeyValues = newKeyValues;
 }
예제 #3
0
        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());
        }
예제 #6
0
        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());
            }
        }
예제 #7
0
        /// <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);
        }
예제 #8
0
 /// <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);
     }
 }
예제 #9
0
        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();
        }
예제 #10
0
        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]);
                }
            }
        }
예제 #11
0
        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;
            }
        }
예제 #12
0
        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;
        }
 public SelectCommand(EditCurve curve, EditCurveKeySelection newSelection,
                                         EditCurveKeySelection oldSelection)
 {
     this.curve = curve;
     this.oldSelection = oldSelection;
     this.newSelection = newSelection;
 }
        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();
        }
 public EditCurveKeyUpdateCommand(EditCurve curve,
                                     ICollection<EditCurveKey> oldKeyValues,
                                     ICollection<EditCurveKey> newKeyValues)
 {
     this.curve = curve;
     this.oldKeyValues = oldKeyValues;
     this.newKeyValues = newKeyValues;
 }
예제 #16
0
        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]);
                }
            }
        }
예제 #17
0
        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;
            }
        }
예제 #18
0
        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;
            }
        }
예제 #19
0
        /// <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;
            }
        }
예제 #20
0
 public EditCurveEventArgs(EditCurve curve)
 {
     Curve = curve;
 }
예제 #21
0
        /// <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;
            }
        }
예제 #22
0
        /// <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;
        }
예제 #23
0
        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;
        }