Beispiel #1
0
        /// <summary>
        /// Attempts to find a keyframe under the provided coordinates.
        /// </summary>
        /// <param name="pixelCoords">Coordinates relative to this GUI element in pixels.</param>
        /// <param name="keyframe">Output object containing keyframe index and index of the curve it belongs to. Only valid
        ///                        if method returns true.</param>
        /// <returns>True if there is a keyframe under the coordinates, false otherwise.</returns>
        public bool FindKeyFrame(Vector2I pixelCoords, out KeyframeRef keyframe)
        {
            keyframe = new KeyframeRef();

            float nearestDistance = float.MaxValue;

            for (int i = 0; i < curveInfos.Length; i++)
            {
                EdAnimationCurve curve     = curveInfos[i].curve;
                KeyFrame[]       keyframes = curve.KeyFrames;

                for (int j = 0; j < keyframes.Length; j++)
                {
                    Vector2  keyframeCurveCoords = new Vector2(keyframes[j].time, keyframes[j].value);
                    Vector2I keyframeCoords      = CurveToPixelSpace(keyframeCurveCoords);

                    float distanceToKey = Vector2I.Distance(pixelCoords, keyframeCoords);
                    if (distanceToKey < nearestDistance)
                    {
                        nearestDistance   = distanceToKey;
                        keyframe.keyIdx   = j;
                        keyframe.curveIdx = i;
                    }
                }
            }

            // We're not near any keyframe
            if (nearestDistance > 5.0f)
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Checks is the provided keyframe currently selected.
        /// </summary>
        /// <param name="keyframeRef">Keyframe to check.</param>
        /// <returns>True if selected, false otherwise.</returns>
        private bool IsSelected(KeyframeRef keyframeRef)
        {
            int curveIdx = selectedKeyframes.FindIndex(x =>
            {
                return(x.curveIdx == keyframeRef.curveIdx);
            });

            if (curveIdx == -1)
            {
                return(false);
            }

            int keyIdx = selectedKeyframes[curveIdx].keyIndices.FindIndex(x =>
            {
                return(x == keyframeRef.keyIdx);
            });

            return(keyIdx != -1);
        }
Beispiel #3
0
        /// <summary>
        /// Marks the specified key-frame as selected, changing the way it is displayed.
        /// </summary>
        /// <param name="keyframeRef">Keyframe reference containing the curve and keyframe index.</param>
        /// <param name="selected">True to select it, false to deselect it.</param>
        public void SelectKeyframe(KeyframeRef keyframeRef, bool selected)
        {
            if (selectedKeyframes == null)
            {
                return;
            }

            if (keyframeRef.curveIdx < 0 || keyframeRef.curveIdx >= selectedKeyframes.Length)
            {
                return;
            }

            if (keyframeRef.keyIdx < 0 || keyframeRef.keyIdx >= selectedKeyframes[keyframeRef.curveIdx].Length)
            {
                return;
            }

            selectedKeyframes[keyframeRef.curveIdx][keyframeRef.keyIdx] = selected;
        }
Beispiel #4
0
        /// <summary>
        /// Adds the provided keyframe to the selection list (doesn't clear existing ones).
        /// </summary>
        /// <param name="keyframeRef">Keyframe to select.</param>
        private void SelectKeyframe(KeyframeRef keyframeRef)
        {
            guiCurveDrawing.SelectKeyframe(keyframeRef, true);

            if (!IsSelected(keyframeRef))
            {
                int curveIdx = selectedKeyframes.FindIndex(x =>
                {
                    return(x.curveIdx == keyframeRef.curveIdx);
                });

                if (curveIdx == -1)
                {
                    curveIdx = selectedKeyframes.Count;

                    SelectedKeyframes newKeyframes = new SelectedKeyframes();
                    newKeyframes.curveIdx = keyframeRef.curveIdx;

                    selectedKeyframes.Add(newKeyframes);
                }

                selectedKeyframes[curveIdx].keyIndices.Add(keyframeRef.keyIdx);
            }
        }
 public TangentRef(KeyframeRef keyframeRef, TangentType type)
 {
     this.keyframeRef = keyframeRef;
     this.type        = type;
 }
 private static extern void Internal_selectKeyframe(IntPtr thisPtr, ref KeyframeRef keyframeRef, TangentMode tangentMode, bool selected);
 private static extern bool Internal_findKeyFrame(IntPtr thisPtr, ref Vector2I pixelCoords, out KeyframeRef keyframe);
 /// <summary>Marks the specified key-frame as selected, changing the way it is displayed.</summary>
 /// <param name="keyframeRef">Keyframe reference containing the curve and keyframe index.</param>
 /// <param name="tangentMode">Type of tangent to display on the selected keyframe.</param>
 /// <param name="selected">True to select it, false to deselect it.</param>
 public void SelectKeyframe(KeyframeRef keyframeRef, TangentMode tangentMode, bool selected)
 {
     Internal_selectKeyframe(mCachedPtr, ref keyframeRef, tangentMode, selected);
 }
 /// <summary>Attempts to find a keyframe under the provided coordinates.</summary>
 /// <param name="pixelCoords">Coordinates relative to this GUI element in pixels.</param>
 /// <param name="keyframe">
 /// Output object containing keyframe index and index of the curve it belongs to. Only  valid if method returns true.
 /// </param>
 /// <returns>True if there is a keyframe under the coordinates, false otherwise.</returns>
 public bool FindKeyFrame(Vector2I pixelCoords, out KeyframeRef keyframe)
 {
     return(Internal_findKeyFrame(mCachedPtr, ref pixelCoords, out keyframe));
 }