Beispiel #1
0
            /// <inheritdoc />
            public override void OnMouseMove(Vector2 location)
            {
                _mousePos = location;

                // Moving view
                if (_rightMouseDown)
                {
                    Vector2 delta = location - _movingViewLastPos;
                    delta *= GetUseModeMask(_editor.EnablePanning) * _editor.ViewScale;
                    if (delta.LengthSquared > 0.01f)
                    {
                        _editor._mainPanel.ViewOffset += delta;
                        _movingViewLastPos             = location;
                        Cursor = CursorType.SizeAll;
                    }

                    return;
                }
                // Moving selection
                else if (_isMovingSelection)
                {
                    var viewRect          = _editor._mainPanel.GetClientArea();
                    var locationKeyframes = PointToKeyframes(location, ref viewRect);
                    var accessor          = _editor.Accessor;
                    var components        = accessor.GetCurveComponents();
                    for (var i = 0; i < _editor._points.Count; i++)
                    {
                        var p = _editor._points[i];
                        if (p.IsSelected)
                        {
                            var   k     = _editor.GetKeyframe(p.Index);
                            float time  = _editor.GetKeyframeTime(k);
                            float value = _editor.GetKeyframeValue(k, p.Component);

                            float minTime = p.Index != 0 ? _editor.GetKeyframeTime(_editor.GetKeyframe(p.Index - 1)) + Mathf.Epsilon : float.MinValue;
                            float maxTime = p.Index != _editor.KeyframesCount - 1 ? _editor.GetKeyframeTime(_editor.GetKeyframe(p.Index + 1)) - Mathf.Epsilon : float.MaxValue;

                            var offset = _movingSelectionOffsets[i];

                            if (!_editor.ShowCollapsed)
                            {
                                // Move on value axis
                                value = locationKeyframes.Y + offset.Y;
                            }

                            // Let the first selected point of this keyframe to edit time
                            bool isFirstSelected = false;
                            for (var j = 0; j < components; j++)
                            {
                                var idx = p.Index * components + j;
                                if (idx == i)
                                {
                                    isFirstSelected = true;
                                    break;
                                }
                                if (_editor._points[idx].IsSelected)
                                {
                                    break;
                                }
                            }
                            if (isFirstSelected)
                            {
                                time = locationKeyframes.X + offset.X;

                                if (_editor.FPS.HasValue)
                                {
                                    float fps = _editor.FPS.Value;
                                    time = Mathf.Floor(time * fps) / fps;
                                }
                                time = Mathf.Clamp(time, minTime, maxTime);
                            }

                            // TODO: snapping keyframes to grid when moving

                            _editor.SetKeyframeInternal(p.Index, time, value, p.Component);
                        }
                        _editor.UpdateKeyframes();
                        _editor.UpdateTooltips();
                        if (_editor.EnablePanning == UseMode.On)
                        {
                            //_editor._mainPanel.ScrollViewTo(PointToParent(_editor._mainPanel, location));
                        }
                        Cursor          = CursorType.SizeAll;
                        _movedKeyframes = true;
                    }
                    return;
                }
                // Moving tangent
                else if (_isMovingTangent)
                {
                    var viewRect  = _editor._mainPanel.GetClientArea();
                    var direction = _movingTangent.IsIn ? -1.0f : 1.0f;
                    var k         = _editor.GetKeyframe(_movingTangent.Index);
                    var kv        = _editor.GetKeyframeValue(k);
                    var value     = _editor.Accessor.GetCurveValue(ref kv, _movingTangent.Component);
                    _movingTangent.TangentValue = direction * (PointToKeyframes(location, ref viewRect).Y - value);
                    _editor.UpdateTangents();
                    Cursor          = CursorType.SizeNS;
                    _movedKeyframes = true;
                    return;
                }
                // Selecting
                else if (_leftMouseDown)
                {
                    UpdateSelectionRectangle();
                    return;
                }

                base.OnMouseMove(location);
            }
            internal void OnMove(Vector2 location)
            {
                var viewRect          = _editor._mainPanel.GetClientArea();
                var locationKeyframes = PointToKeyframes(location, ref viewRect);
                var accessor          = _editor.Accessor;
                var components        = accessor.GetCurveComponents();

                for (var i = 0; i < _editor._points.Count; i++)
                {
                    var p = _editor._points[i];
                    if (p.IsSelected)
                    {
                        var   k     = _editor.GetKeyframe(p.Index);
                        float time  = _editor.GetKeyframeTime(k);
                        float value = _editor.GetKeyframeValue(k, p.Component);

                        float minTime = p.Index != 0 ? _editor.GetKeyframeTime(_editor.GetKeyframe(p.Index - 1)) + Mathf.Epsilon : float.MinValue;
                        float maxTime = p.Index != _editor.KeyframesCount - 1 ? _editor.GetKeyframeTime(_editor.GetKeyframe(p.Index + 1)) - Mathf.Epsilon : float.MaxValue;

                        var offset = _movingSelectionOffsets[i];

                        if (!_editor.ShowCollapsed)
                        {
                            // Move on value axis
                            value = locationKeyframes.Y + offset.Y;
                        }

                        // Let the first selected point of this keyframe to edit time
                        bool isFirstSelected = false;
                        for (var j = 0; j < components; j++)
                        {
                            var idx = p.Index * components + j;
                            if (idx == i)
                            {
                                isFirstSelected = true;
                                break;
                            }
                            if (_editor._points[idx].IsSelected)
                            {
                                break;
                            }
                        }
                        if (isFirstSelected)
                        {
                            time = locationKeyframes.X + offset.X;

                            if (_editor.FPS.HasValue)
                            {
                                float fps = _editor.FPS.Value;
                                time = Mathf.Floor(time * fps) / fps;
                            }
                            time = Mathf.Clamp(time, minTime, maxTime);
                        }

                        // TODO: snapping keyframes to grid when moving

                        _editor.SetKeyframeInternal(p.Index, time, value, p.Component);
                    }
                    _editor.UpdateKeyframes();
                    _editor.UpdateTooltips();
                    if (_editor.EnablePanning == UseMode.On)
                    {
                        //_editor._mainPanel.ScrollViewTo(PointToParent(_editor._mainPanel, location));
                    }
                    Cursor          = CursorType.SizeAll;
                    _movedKeyframes = true;
                }
            }