Ejemplo n.º 1
0
        /////////////////////////////////////////

        public override Vector2 GetSocketPositionInUnits(Component_FlowGraphNode.Representation.Item socket, bool input)
        {
            var rep  = socket.Owner;
            var node = rep.Owner;

            if (input)
            {
                return(node.Position.ToVector2() + new Vector2(0, (double)socket.Index + 0.5 + (double)rep.GetTextsOffsetY()));
            }
            else
            {
                return(node.Position.ToVector2() + new Vector2(rep.Size.X, (double)socket.Index + 0.5 + (double)rep.GetTextsOffsetY()));
            }
            //if( input )
            //	return node.NodePosition.ToVec2() + new Vec2( 0, (double)socket.Index + 1.5f + (double)rep.GetTextsOffsetY() );
            //else
            //	return node.NodePosition.ToVec2() + new Vec2( rep.Size.X, (double)socket.Index + 1.5f + (double)rep.GetTextsOffsetY() );
        }
Ejemplo n.º 2
0
        public override void RenderNodeReferences(Component_FlowGraph_DocumentWindow window, Component_FlowGraphNode node,
                                                  Dictionary <Component, List <Component_FlowGraphNode> > objectToNodes,
                                                  Dictionary <Component_FlowGraphNode.Representation.Item, EditorRenderSelectionState> referenceSelectionStates,
                                                  out Component_FlowGraphNode.Representation.Item outMouseOverReference)
        {
            outMouseOverReference = null;

            var representation = node.GetRepresentation();
            var renderer       = window.ViewportControl.Viewport.CanvasRenderer;

            for (int nItem = 0; nItem < representation.Items.Count; nItem++)
            {
                var item = representation.Items[nItem];

                //references from input
                if (item.Input != null)
                {
                    var itemProperty = item as Component_FlowGraphNode.Representation.ItemProperty;
                    if (itemProperty != null && ReferenceUtility.IsReferenceType(itemProperty.Property.Type.GetNetType()) &&
                        !MetadataManager.GetTypeOfNetType(typeof(FlowInput)).IsAssignableFrom(itemProperty.Property.TypeUnreferenced))
                    {
                        Component obj = itemProperty.Owner.Owner.ControlledObject;
                        if (obj != null)
                        {
                            var        v          = itemProperty.Property.GetValue(obj, null);
                            IReference iReference = v as IReference;
                            if (iReference != null && !string.IsNullOrEmpty(iReference.GetByReference))
                            {
                                iReference.GetMember(obj, out object destObject, out Metadata.Member destMember);
                                var destProperty = destMember as Metadata.Property;
                                if (destProperty != null)
                                {
                                    //reference to property

                                    //!!!!только компоненты? статичные свойства тоже нельзя?
                                    var destComponent = destObject as Component;
                                    if (destComponent != null && objectToNodes.TryGetValue(destComponent, out List <Component_FlowGraphNode> destNodes))
                                    {
                                        foreach (var destNode in destNodes)
                                        {
                                            var destRep = destNode.GetRepresentation();
                                            Component_FlowGraphNode.Representation.ItemProperty destSocket;
                                            if (destRep.ItemByProperty.TryGetValue(destProperty, out destSocket))
                                            {
                                                if (destSocket.Output != null)
                                                {
                                                    var from = GetSocketPositionInUnits(item, true);
                                                    var to   = GetSocketPositionInUnits(destSocket, false);

                                                    if (!referenceSelectionStates.TryGetValue(item, out EditorRenderSelectionState state))
                                                    {
                                                        state = EditorRenderSelectionState.None;
                                                    }

                                                    ColorValue color;
                                                    if (state != EditorRenderSelectionState.None)
                                                    {
                                                        color = GetColorMultiplierSelectionState(state);
                                                    }
                                                    else
                                                    {
                                                        color = new ColorValue(0.5, 0.5, 0.5);
                                                    }
                                                    //ColorValue color = GetColorMultiplierSelectionState( state );

                                                    window.GetFlowGraphStyle().RenderReference(window, from, true, to, color, out bool mouseOver);

                                                    if (mouseOver && outMouseOverReference == null)
                                                    {
                                                        outMouseOverReference = item;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //reference to Component

                                    var unrefValue    = ReferenceUtility.GetUnreferencedValue(iReference.GetValue(obj));
                                    var destComponent = unrefValue as Component;
                                    if (destComponent != null && objectToNodes.TryGetValue(destComponent, out List <Component_FlowGraphNode> destNodes))
                                    {
                                        foreach (var destNode in destNodes)
                                        {
                                            var destRep    = destNode.GetRepresentation();
                                            var destSocket = destRep.ItemObject;
                                            if (destSocket != null)
                                            {
                                                var from = GetSocketPositionInUnits(item, true);
                                                var to   = GetSocketPositionInUnits(destSocket, false);

                                                if (!referenceSelectionStates.TryGetValue(item, out EditorRenderSelectionState state))
                                                {
                                                    state = EditorRenderSelectionState.None;
                                                }

                                                ColorValue color;
                                                if (state != EditorRenderSelectionState.None)
                                                {
                                                    color = GetColorMultiplierSelectionState(state);
                                                }
                                                else
                                                {
                                                    color = new ColorValue(0.5, 0.5, 0.5);
                                                }
                                                //ColorValue color = GetColorMultiplierSelectionState( state );

                                                window.GetFlowGraphStyle().RenderReference(window, from, true, to, color, out bool mouseOver);

                                                if (mouseOver && outMouseOverReference == null)
                                                {
                                                    outMouseOverReference = item;
                                                }
                                            }
                                        }
                                    }

                                    //!!!!invalid reference
                                }
                            }
                        }
                    }
                }

                //references from output (FlowInput)
                if (item.Output != null)
                {
                    var itemProperty = item as Component_FlowGraphNode.Representation.ItemProperty;
                    if (itemProperty != null && ReferenceUtility.IsReferenceType(itemProperty.Property.Type.GetNetType()) &&
                        MetadataManager.GetTypeOfNetType(typeof(FlowInput)).IsAssignableFrom(itemProperty.Property.TypeUnreferenced))
                    {
                        Component obj = itemProperty.Owner.Owner.ControlledObject;
                        if (obj != null)
                        {
                            var        v          = itemProperty.Property.GetValue(obj, null);
                            IReference iReference = v as IReference;
                            if (iReference != null && !string.IsNullOrEmpty(iReference.GetByReference))
                            {
                                iReference.GetMember(obj, out object destObject, out Metadata.Member destMember);

                                var destProperty = destMember as Metadata.Property;
                                if (destProperty != null)
                                {
                                    //!!!!только компоненты? статичные свойства тоже нельзя?
                                    var destComponent = destObject as Component;
                                    if (destComponent != null && objectToNodes.TryGetValue(destComponent, out List <Component_FlowGraphNode> destNodes))
                                    {
                                        foreach (var destNode in destNodes)
                                        {
                                            var destRep = destNode.GetRepresentation();
                                            Component_FlowGraphNode.Representation.ItemProperty destSocket;
                                            if (destRep.ItemByProperty.TryGetValue(destProperty, out destSocket))
                                            {
                                                if (destSocket.Input != null)
                                                {
                                                    var from = GetSocketPositionInUnits(item, false);
                                                    var to   = GetSocketPositionInUnits(destSocket, true);

                                                    if (!referenceSelectionStates.TryGetValue(item, out EditorRenderSelectionState state))
                                                    {
                                                        state = EditorRenderSelectionState.None;
                                                    }

                                                    ColorValue color;
                                                    if (state != EditorRenderSelectionState.None)
                                                    {
                                                        color = GetColorMultiplierSelectionState(state);
                                                    }
                                                    else
                                                    {
                                                        color = new ColorValue(0.3, 0.3, 1);
                                                    }
                                                    //ColorValue color = GetColorMultiplierSelectionState( state );

                                                    window.GetFlowGraphStyle().RenderReference(window, from, false, to, color, out bool mouseOver);

                                                    if (mouseOver && outMouseOverReference == null)
                                                    {
                                                        outMouseOverReference = item;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //!!!!invalid reference
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 //EditorRenderSelectionState.Selected
 public abstract void RenderNodeReferences(Component_FlowGraph_DocumentWindow window, Component_FlowGraphNode node,
                                           Dictionary <Component, List <Component_FlowGraphNode> > objectToNodes,
                                           Dictionary <Component_FlowGraphNode.Representation.Item, EditorRenderSelectionState> referenceSelectionStates,
                                           out Component_FlowGraphNode.Representation.Item outMouseOverReference);
Ejemplo n.º 4
0
 public abstract Vector2 GetSocketPositionInUnits(Component_FlowGraphNode.Representation.Item socket, bool input);