Exemplo n.º 1
0
        private ConnectionLine TryPickingConnectionLineForSplitting()
        {
            var numConnectedInputs = Inputs.Count(input => input.Connections.Any());

            ConnectionLine connectionToHighlight = null;

            if (numConnectedInputs == 0)
            {
                var mousePos   = Mouse.GetPosition(CV.XCompositionGraphView.XOperatorCanvas);
                var hitResults = UIHelper.HitTestFor <Path>(CV.XCompositionGraphView.XOperatorCanvas, mousePos, 3.0);
                foreach (var r in hitResults)
                {
                    foreach (UIElement child in CV.XCompositionGraphView.XOperatorCanvas.Children)
                    {
                        var cl = child as ConnectionLine;
                        if (cl != null && cl.ConnectionPath == r.VisualHit as Path)
                        {
                            if (cl.Output.Parent != Operator)
                            {
                                connectionToHighlight = cl;
                            }
                        }
                    }
                }
            }
            return(connectionToHighlight);
        }
Exemplo n.º 2
0
        private void XWidgetThumb_DragDeltaHandler(object sender, DragDeltaEventArgs e)
        {
            e.Handled = true;

            var offset = _dragStartPositionOnCanvas - Mouse.GetPosition(_visualParent);

            if (_isDraggingNewConnection)
            {
                return;
            }


            if (_isDraggingRightEdge)
            {
                var orginalPositionInsideWidget = _visualParent.TranslatePoint(_dragStartPositionOnCanvas, this);
                var currentPositionInsideWidget = _visualParent.TranslatePoint(Mouse.GetPosition(_visualParent), this);
                var delta = currentPositionInsideWidget - orginalPositionInsideWidget;

                if ((_dragStartWidth + delta.X) > 2 * CompositionGraphView.GRID_SIZE)
                {
                    Width = Math.Round((_dragStartWidth + delta.X) / CompositionGraphView.GRID_SIZE) * CompositionGraphView.GRID_SIZE;
                    _updateWidthCommand.ChangeEntries[0].Width = Width;
                    _updateWidthCommand.Do();
                    GetAndDrawInputZones();
                    UpdateConnections();
                    UpdateCornerRadius();
                }
            }
            else
            {
                _snapHandler.UpdateBeforeMoving(offset);

                if (ShakeDetector.TestForShaking(Operator.Position))
                {
                    Logger.Debug("Disconnected with shake gesture.");
                    DisconnectGroupAfterShakingOff(_snapHandler.DragGroup);
                }

                // Check for connections that would be dropped on release
                ConnectionLine connectionToHighlight = null;
                if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
                {
                    connectionToHighlight = TryPickingConnectionLineForSplitting();
                }

                if (_connectionHighlightedForSplitting != null && _connectionHighlightedForSplitting != connectionToHighlight)
                {
                    _connectionHighlightedForSplitting.IsSelected = false;
                }

                if (connectionToHighlight != null)
                {
                    connectionToHighlight.IsSelected = true;
                }
                _connectionHighlightedForSplitting = connectionToHighlight;
            }
        }
Exemplo n.º 3
0
        private void SplitConnection()
        {
            var index   = _connectionHighlightedForSplitting.GetMultiInputIndex();
            var command = new InsertOperatorCommand(_connectionHighlightedForSplitting.Output,
                                                    _connectionHighlightedForSplitting.Input,
                                                    CV.CompositionGraphView.CompositionOperator, Operator, index);

            App.Current.UndoRedoStack.AddAndExecute(command);
            App.Current.UpdateRequiredAfterUserInteraction = true;

            _connectionHighlightedForSplitting = null;
        }
Exemplo n.º 4
0
        public void DoDragDropRewireConnection(ConnectionLine cl)
        {
            _dragStartPositionOnCanvas = Win32RawInput.MousePointInUiElement(_cgv.XOperatorCanvas);
            _snappedToValidInput       = false;

            var dragData = new DataObject(CONNECTION_LINE_OUTPUT_IDENTIFIER, cl.Output);

            // We have to restart the temp connection, because DoDragDrop triggers DragCompleted
            cl.HitTestDisabledDuringDrag = false;

            RewireExistingConnection(cl, _dragStartPositionOnCanvas, cl.Output.Func.EvaluationIndex);
            DragDrop.AddGiveFeedbackHandler(_cgv, GiveFeedbackHandler);
            DragDrop.DoDragDrop(_cgv, dragData, DragDropEffects.All);

            // Important! This line is not reached until drop is completed.

            DragDrop.RemoveGiveFeedbackHandler(_cgv, GiveFeedbackHandler);
            Stop(new Vector(), null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Start drag a new connection. Called from InputWidget and OperatorWidget when staring to drag from output thumb
        /// </summary>
        public void Start(Point p, IConnectionLineSource src, int outputIdx)
        {
            _sourceOutputIndex = -1;
            if (outputIdx < 0 || outputIdx >= src.Outputs.Count)
            {
                return;
            }

            _sourceOutputIndex = outputIdx;
            _sourceWidget      = src;
            _startPosition     = p;

            // NOTE: In the long term, this should be capable of handling simultaneously creating multiple connection
            _lastPosition = _startPosition;

            var cl = new ConnectionLine(_sourceWidget.CV.CompositionGraphView.CompositionOperator, _sourceWidget, _sourceWidget.Outputs[outputIdx]);

            _sourceWidget.CV.CompositionGraphView.UnfinishedConnections.Add(cl);
            _sourceWidget.CV.CompositionGraphView.XOperatorCanvas.Children.Add(cl);

            cl.UpdateDuringConstruction(_lastPosition);
        }
Exemplo n.º 6
0
        public void RewireExistingConnection(ConnectionLine cl, Point startPoint, int outputIdx)
        {
            _sourceOutputIndex = -1;
            if (outputIdx < 0 || outputIdx >= cl.Source.Outputs.Count)
            {
                return;
            }

            _sourceWidget      = cl.Source;
            _sourceOutputIndex = outputIdx;

            _startPosition = startPoint;
            _lastPosition  = _startPosition;

            // Delete old connection from model...
            cl.Remove();
            cl.Target.UpdateConnections();

            // ...and restart as unfinished connection line
            _sourceWidget.CV.CompositionGraphView.UnfinishedConnections.Add(cl);
            _sourceWidget.CV.CompositionGraphView.XOperatorCanvas.Children.Add(cl);
            cl.UpdateDuringConstruction(_lastPosition);
            cl.IsSelected = true;
        }