Пример #1
0
            /// <inheritdoc />
            public override bool OnMouseDown(Vector2 location, MouseButton button)
            {
                if (base.OnMouseDown(location, button))
                {
                    // Clear flags
                    _isMovingSelection = false;
                    _isMovingTangent   = false;
                    _rightMouseDown    = false;
                    _leftMouseDown     = false;
                    return(true);
                }

                // Cache data
                _isMovingSelection = false;
                _isMovingTangent   = false;
                _mousePos          = location;
                if (button == MouseButton.Left)
                {
                    _leftMouseDown    = true;
                    _leftMouseDownPos = location;
                }
                if (button == MouseButton.Right)
                {
                    _rightMouseDown    = true;
                    _rightMouseDownPos = location;
                    _movingViewLastPos = location;
                }

                // Check if any node is under the mouse
                var underMouse = GetChildAt(location);

                if (underMouse is KeyframePoint keyframe)
                {
                    if (_leftMouseDown)
                    {
                        // Check if user is pressing control
                        if (Root.GetKey(KeyboardKeys.Control))
                        {
                            // Add to selection
                            keyframe.IsSelected = true;
                            _editor.UpdateTangents();
                        }
                        // Check if node isn't selected
                        else if (!keyframe.IsSelected)
                        {
                            // Select node
                            _editor.ClearSelection();
                            keyframe.IsSelected = true;
                            _editor.UpdateTangents();
                        }

                        // Start moving selected nodes
                        StartMouseCapture();
                        _isMovingSelection = true;
                        _movedKeyframes    = false;
                        var viewRect = _editor._mainPanel.GetClientArea();
                        _movingSelectionStart = PointToKeyframes(location, ref viewRect);
                        if (_movingSelectionOffsets == null || _movingSelectionOffsets.Length != _editor._points.Count)
                        {
                            _movingSelectionOffsets = new Vector2[_editor._points.Count];
                        }
                        for (int i = 0; i < _movingSelectionOffsets.Length; i++)
                        {
                            _movingSelectionOffsets[i] = _editor._points[i].Point - _movingSelectionStart;
                        }
                        _editor.OnEditingStart();
                        Focus();
                        Tooltip?.Hide();
                        return(true);
                    }
                }
                else if (underMouse is TangentPoint tangent && tangent.Visible)
                {
                    if (_leftMouseDown)
                    {
                        // Start moving tangent
                        StartMouseCapture();
                        _isMovingTangent = true;
                        _movedKeyframes  = false;
                        _movingTangent   = tangent;
                        _editor.OnEditingStart();
                        Focus();
                        Tooltip?.Hide();
                        return(true);
                    }
                }
Пример #2
0
            /// <inheritdoc />
            public override bool OnMouseDown(Vector2 location, MouseButton button)
            {
                if (base.OnMouseDown(location, button))
                {
                    // Clear flags
                    _isMovingSelection = false;
                    _isMovingTangent   = false;
                    _rightMouseDown    = false;
                    _leftMouseDown     = false;
                    return(true);
                }

                // Cache data
                _isMovingSelection = false;
                _isMovingTangent   = false;
                _mousePos          = location;
                if (button == MouseButton.Left)
                {
                    _leftMouseDown    = true;
                    _leftMouseDownPos = location;
                }
                if (button == MouseButton.Right)
                {
                    _rightMouseDown    = true;
                    _rightMouseDownPos = location;
                    _movingViewLastPos = location;
                }

                // Check if any node is under the mouse
                var underMouse = GetChildAt(location);

                if (underMouse is KeyframePoint keyframe)
                {
                    if (_leftMouseDown)
                    {
                        if (Root.GetKey(KeyboardKeys.Control))
                        {
                            // Toggle selection
                            keyframe.IsSelected = !keyframe.IsSelected;
                            _editor.UpdateTangents();
                        }
                        else if (Root.GetKey(KeyboardKeys.Shift))
                        {
                            // Select range
                            keyframe.IsSelected = true;
                            int selectionStart = 0;
                            for (; selectionStart < _editor._points.Count; selectionStart++)
                            {
                                if (_editor._points[selectionStart].IsSelected)
                                {
                                    break;
                                }
                            }
                            int selectionEnd = _editor._points.Count - 1;
                            for (; selectionEnd > selectionStart; selectionEnd--)
                            {
                                if (_editor._points[selectionEnd].IsSelected)
                                {
                                    break;
                                }
                            }
                            selectionStart++;
                            for (; selectionStart < selectionEnd; selectionStart++)
                            {
                                _editor._points[selectionStart].IsSelected = true;
                            }
                            _editor.UpdateTangents();
                        }
                        else if (!keyframe.IsSelected)
                        {
                            // Select node
                            if (_editor.KeyframesEditorContext != null)
                            {
                                _editor.KeyframesEditorContext.OnKeyframesDeselect(_editor);
                            }
                            else
                            {
                                _editor.ClearSelection();
                            }
                            keyframe.IsSelected = true;
                            _editor.UpdateTangents();
                        }
                        if (_editor.ShowCollapsed)
                        {
                            // Synchronize selection for curve points when collapsed so all points fo the keyframe are selected
                            for (var i = 0; i < _editor._points.Count; i++)
                            {
                                var p = _editor._points[i];
                                if (p.Index == keyframe.Index)
                                {
                                    p.IsSelected = keyframe.IsSelected;
                                }
                            }
                        }
                        StartMouseCapture();
                        Focus();
                        Tooltip?.Hide();
                        return(true);
                    }
                }
                else if (underMouse is TangentPoint tangent && tangent.Visible)
                {
                    if (_leftMouseDown)
                    {
                        // Start moving tangent
                        StartMouseCapture();
                        _isMovingTangent = true;
                        _movedKeyframes  = false;
                        _movingTangent   = tangent;
                        _editor.OnEditingStart();
                        Focus();
                        Tooltip?.Hide();
                        return(true);
                    }
                }