예제 #1
0
        private void OnAddOutput(object sender, RoutedEventArgs e)
        {
            var cv         = UIHelper.FindParent <CompositionView>(this);
            var metaOutput = new MetaOutput(Guid.NewGuid(), "Output", BasicMetaTypes.GenericMeta);
            var metaOp     = cv.CompositionGraphView.CompositionOperator.Definition;

            metaOp.AddOutput(metaOutput);
        }
예제 #2
0
        private void AddInputToComposition(MetaInput inputToAdd)
        {
            var compositionView = UIHelper.FindParent <CompositionView>(this);
            var compOp          = compositionView.CompositionGraphView.CompositionOperator;

            var command = new AddInputCommand(compOp, inputToAdd);

            App.Current.UndoRedoStack.AddAndExecute(command);
        }
예제 #3
0
 private void ButtonKeyUp_Handler(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         var o = UIHelper.FindParent <TextButtonEdit>(sender as UIElement);
         if (o != null)
         {
             o.EnableTextEdit();
         }
     }
 }
예제 #4
0
        private void OperatorButton_ClickHandler(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;

            if (button != null)
            {
                var compoGraphView = App.Current.MainWindow.CompositionView.CompositionGraphView;
                compoGraphView.AddOperatorAtCenter(MetaOp);
                var qcw = UIHelper.FindParent <QuickCreateWindow>(this);
                if (qcw != null)
                {
                    qcw.Close();
                }
            }
        }
예제 #5
0
 private void OnMouseMove(object sender, MouseEventArgs e)
 {
     if (m_IsRightMouseDragging)
     {
         double deltaX = -(m_DragStartPosition.X - e.GetPosition(this).X);
         double deltaY = 0;//-(m_DragStartPosition.Y - e.GetPosition(this).Y);
         Matrix m      = m_MatrixOnDragStart;
         m.Translate(deltaX, deltaY);
         this.ViewTransform.Matrix = m;
         CompositionGraphView cgv = UIHelper.FindParent <CompositionGraphView>(this);
         if (cgv != null)
         {
             cgv.UpdateConnectionsToOutputs();
         }
     }
 }
예제 #6
0
        private void AddInputToComposition(MetaInput[] inputsToAdd)
        {
            var compositionView = UIHelper.FindParent <CompositionView>(this);
            var compOp          = compositionView.CompositionGraphView.CompositionOperator;

            var commands = new AddInputCommand[inputsToAdd.Length];

            for (var i = 0; i < inputsToAdd.Length; i++)
            {
                var command = new AddInputCommand(compOp, inputsToAdd[i]);
                commands[i] = command;
            }
            var macroCommand = new MacroCommand("Add input paramter group", commands);

            App.Current.UndoRedoStack.AddAndExecute(macroCommand);
        }
 CompositionView GetCompositionView()
 {
     return(UIHelper.FindParent <CompositionView>(this));
 }
예제 #8
0
 private TimeView GetTimeView()
 {
     return(UIHelper.FindParent <TimeView>(this));
 }
예제 #9
0
        /**
         * This is called from OperatorWidget while dragging from OperatorWidget during onDragConnectionDelta
         */
        public void UpdateDuringConstruction(Point endPoint)
        {
            if (Source.Outputs.Count <= 0)
            {
                return;
            }

            var sourceUI = Source as UIElement;

            if (UIHelper.FindParent <CompositionGraphView>(sourceUI) == null)
            {
                Logger.Warn("Tried to connect to source that is not in current view (" + Output.Parent.Name + ").");
                return;
            }

            Point  sourcePointInMainPanel = Source.PositionOnCanvas;
            double targetY = endPoint.Y;
            double sourceY = sourcePointInMainPanel.Y;

            double targetXmin, targetXmax;

            targetXmin = endPoint.X;
            targetXmax = endPoint.X;
            IsSelected = false;

            int    outputCount = Source.Outputs.Count;
            int    outputIndex = Output.Func.EvaluationIndex;
            double outputWidth = Source.Width / outputCount;
            double sourceXmin  = sourcePointInMainPanel.X + (double)outputIndex * outputWidth;
            double sourceXmax  = sourceXmin + outputWidth;

            // Calculate straight factor from overlap
            double BLEND_RANGE    = 40;
            double BLEND_BORDER   = 10;
            double overlapp       = Math.Min(sourceXmax, targetXmax) - Math.Max(sourceXmin, targetXmin);
            double straightFactor = Math.Min(BLEND_RANGE, Math.Max(0, overlapp - BLEND_BORDER)) / BLEND_RANGE;

            // limit straight connection to a certain y range...
            double STRAIGHT_MIN_DISTANCE   = 50;
            double STRAIGHT_DISTANCE_BLEND = 50;
            double dy = sourceY - targetY;

            if (dy < -2)
            {
                straightFactor = 0.0;
            }
            else
            {
                straightFactor *= 1 - (Utilities.Clamp(dy, STRAIGHT_MIN_DISTANCE, STRAIGHT_MIN_DISTANCE + STRAIGHT_DISTANCE_BLEND) - STRAIGHT_MIN_DISTANCE) / STRAIGHT_DISTANCE_BLEND;
            }

            // Calculate curviness
            const double MIN_TANGENT_LENGTH = 80.0;
            const double MAX_TANGENT_LENGTH = 200.0;
            double       tangent            = Utilities.Clamp(((sourceY - targetY) * 0.4), MIN_TANGENT_LENGTH, MAX_TANGENT_LENGTH) * (1 - straightFactor);

            // Blend X depending on straightfactor
            double sourceXcenter = sourceXmin + 0.5 * (sourceXmax - sourceXmin);
            double targetXcenter = targetXmin + 0.5 * (targetXmax - targetXmin);
            double averageX      = Math.Max(sourceXmin, targetXmin) + 0.5 * overlapp;

            double sourceX = sourceXcenter * (1 - straightFactor) + straightFactor * averageX;
            double targetX = targetXcenter * (1 - straightFactor) + straightFactor * averageX;

            m_TargetPoint = new Point(targetX, targetY);
            m_SourcePoint = new Point(sourceX, sourceY);

            m_PathFigure.StartPoint = new Point(sourceX, sourceY);
            m_CurveSegment.Point1   = new Point(sourceX, sourceY - tangent);
            m_CurveSegment.Point2   = new Point(targetX, targetY + tangent);
            m_CurveSegment.Point3   = new Point(targetX, targetY);

            m_ArrowHeadPathFigure.StartPoint = new Point(targetX, targetY + 2.02);
            m_ArrowHeadLineSegment.Point     = new Point(targetX, targetY + 2);
        }
예제 #10
0
        /*
         * Calculates connection curve as described in http://streber.pixtur.de/index.php?go=fileDownloadAsImage&file=4964
         */
        public void Update()
        {
            if (Target == null)
            {
                return;
            }

            if (Source.Outputs.Count <= 0)
            {
                return;
            }
            if (Target.Inputs.Count <= 0)
            {
                return;
            }

            var targetUI = Target as UIElement;

            if (UIHelper.FindParent <CompositionGraphView>(targetUI) == null)
            {
                Logger.Warn("Tried to connect to TargetWidget that is not in current view (" + Input.Parent.Name + "). Please report this bug.");
                return;
            }
            var sourceUI = Source as UIElement;

            if (UIHelper.FindParent <CompositionGraphView>(sourceUI) == null)
            {
                Logger.Warn("Tried to connect to source that is not in current view (" + Output.Parent.Name + "). Please report this bug.");
                return;
            }

            Point targetPositionOnCanvas = Target.PositionOnCanvas;
            Point sourcePointInMainPanel = Source.PositionOnCanvas;

            double targetY = targetPositionOnCanvas.Y + Target.Height + 1.0;
            double sourceY = sourcePointInMainPanel.Y + 1.0;

            int    index         = this.GetMultiInputIndex();
            Rect   range         = Target.GetRangeForInputConnectionLine(Input, index, false);
            double targetXmin    = targetPositionOnCanvas.X + range.Left;
            double targetXmax    = targetPositionOnCanvas.X + range.Right;
            double targetXcenter = targetXmin + 0.5 * (targetXmax - targetXmin);

            int    outputCount   = Source.Outputs.Count;
            int    outputIndex   = Output.Func.EvaluationIndex;
            double outputWidth   = Source.Width / outputCount;
            double sourceXmin    = sourcePointInMainPanel.X + (double)outputIndex * outputWidth;
            double sourceXmax    = sourceXmin + outputWidth;
            double sourceXcenter = sourceXmin + 0.5 * (sourceXmax - sourceXmin);

            // Calculate straight factor from overlap
            const double BLEND_RANGE    = 20;
            const double BLEND_BORDER   = 10;
            double       overlapp       = Math.Min(sourceXmax, targetXmax) - Math.Max(sourceXmin, targetXmin);
            double       straightFactor = Math.Min(BLEND_RANGE, Math.Max(0, overlapp - BLEND_BORDER)) / BLEND_RANGE;

            // limit straight connection to a certain y range...
            const double STRAIGHT_MIN_DISTANCE   = 80;
            const double STRAIGHT_DISTANCE_BLEND = 50;
            double       dy = sourceY - targetY;

            if (dy < -2)
            {
                straightFactor = 0.0;
            }
            else
            {
                straightFactor *= 1 - (Utilities.Clamp(dy, STRAIGHT_MIN_DISTANCE, STRAIGHT_MIN_DISTANCE + STRAIGHT_DISTANCE_BLEND) - STRAIGHT_MIN_DISTANCE) / STRAIGHT_DISTANCE_BLEND;
            }

            // Calculate curviness
            double MIN_TANGENT_LENGTH = 80.0;
            double MAX_TANGENT_LENGTH = 200.0;
            double tangent            = Utilities.Clamp((sourceY - targetY) * 0.4, MIN_TANGENT_LENGTH, MAX_TANGENT_LENGTH) * (1 - straightFactor);

            // Blend X depending on straight factor
            double averageX = Math.Max(sourceXmin, targetXmin) + 0.5 * overlapp;

            double sourceX = sourceXcenter * (1 - straightFactor) + straightFactor * averageX;
            double targetX = targetXcenter * (1 - straightFactor) + straightFactor * averageX;

            m_PathFigure.StartPoint = new Point(sourceX, sourceY);
            m_CurveSegment.Point1   = new Point(sourceX, sourceY - tangent);
            m_CurveSegment.Point2   = new Point(targetX, targetY + tangent);
            m_CurveSegment.Point3   = new Point(targetX, targetY);

            m_ArrowHeadPathFigure.StartPoint = new Point(targetX, targetY + 2.02);
            m_ArrowHeadLineSegment.Point     = new Point(targetX, targetY + 2);

            m_TargetPoint = new Point(targetX, targetY);
            m_SourcePoint = new Point(sourceX, sourceY);

            Canvas.SetLeft(_thumb, targetX - 0.5 * CONNECTION_ARROW_THUMB_SIZE);
            Canvas.SetTop(_thumb, targetY - 0.5 * CONNECTION_ARROW_THUMB_SIZE);
        }