Esempio n. 1
0
        public override void RenderNode(Component_FlowGraph_DocumentWindow window, Component_FlowGraphNode node,
                                        EditorRenderSelectionState selectionStateNode, EditorRenderSelectionState selectionStateControlledObject, object mouseOverObject,
                                        Component_FlowGraphNode.Representation.Connector referenceCreationSocketFrom, DragDropSetReferenceData dragDropSetReferenceData)
        {
            var representation = node.GetRepresentation();
            var viewport       = window.ViewportControl.Viewport;
            var mouse          = viewport.MousePosition;
            var renderer       = viewport.CanvasRenderer;

            FlowGraphRepresentationData representationData = new FlowGraphRepresentationData();
            {
                var iRepresentationData = node.ControlledObject.Value as IFlowGraphRepresentationData;
                if (iRepresentationData != null)
                {
                    iRepresentationData.GetFlowGraphRepresentationData(representationData);
                }
            }

            Vector2I   nodeSize = representation.Size;
            RectangleI nodeRectWithOneBorder = new RectangleI(node.Position - new Vector2I(1, 1), node.Position + nodeSize + new Vector2I(1, 1));

            //!!!!slowly
            var visibleCells = window.GetVisibleCells();

            if (!visibleCells.Intersects(nodeRectWithOneBorder))
            {
                return;
            }

            window.GetFontSizes(renderer, out var nodeFontSize, out var nodeFontSizeComment);

            Rectangle nodeRectInUnits = new RectangleI(node.Position, node.Position + nodeSize).ToRectangle();
            Rectangle nodeRect        = window.ConvertUnitToScreen(nodeRectInUnits);
            double    cellHeight      = window.ConvertUnitToScreenY(node.Position.Y + 1) - window.ConvertUnitToScreenY(node.Position.Y);



            //ColorValue totalNodeColorMultiplier = new ColorValue( 1, 1, 1 );
            //{
            //	//if( settings.Error != null )
            //	//	nodeColorMultiplier *= new ColorValue( 1, 0, 0 );

            //	//BlueprintGraphNodeObjectsEvent event_ = node as BlueprintGraphNodeObjectsEvent;
            //	//if( event_ != null && !event_.Enabled )
            //	//	nodeColorMultiplier = new ColorValue( .5f, .5f, .5f );
            //}

            ColorValue nodeColorMultiplierWithSelection = /*totalNodeColorMultiplier*/ GetColorMultiplierSelectionState(selectionStateNode);
            ColorValue objColorMultiplierWithSelection  = /*totalNodeColorMultiplier*/ GetColorMultiplierSelectionState(selectionStateControlledObject);

            //node selection
            if (selectionStateNode != EditorRenderSelectionState.None)
            {
                //node selection rectangle
                Rectangle nodeSelectionRectInUnits = nodeRectInUnits;
                nodeSelectionRectInUnits.Expand(.4);
                Rectangle nodeSelectionRect = window.ConvertUnitToScreen(nodeSelectionRectInUnits);

                renderer.AddQuad(nodeSelectionRect, new ColorValue(.3, .3, .3) * nodeColorMultiplierWithSelection);
                renderer.AddRectangle(nodeSelectionRect, new ColorValue(.6, .6, .6) * nodeColorMultiplierWithSelection);
            }

            //window
            {
                double titleHeight = cellHeight;
                //float titleHeight = ConvertUnitToScreenY( node.NodePosition.Y + 1 ) - ConvertUnitToScreenY( node.NodePosition.Y );
                Rectangle titleRect = new Rectangle(nodeRect.Left, nodeRect.Top, nodeRect.Right, nodeRect.Top + titleHeight);
                Rectangle bodyRect  = new Rectangle(nodeRect.Left, nodeRect.Top + titleHeight, nodeRect.Right, nodeRect.Bottom);

                //!!!!
                ColorValue contentTypeColor;
                ColorValue?titleColor = null;
                switch (representationData.NodeContentType)
                {
                case FlowGraphNodeContentType.Flow: contentTypeColor = new ColorValue(0.16 / 1.2, 0.34 / 1.2, 0.6 / 1.2); break;

                case FlowGraphNodeContentType.MethodBody: contentTypeColor = new ColorValue(0.45, 0.1, 0.1); break;

                case FlowGraphNodeContentType.FlowStart: contentTypeColor = new ColorValue(0.45, 0.1, 0.1); break;
                //case FlowchartNodeContentType.Flow: contentTypeColor = new ColorValue( 0.15, 0.15, 0.4 ); break;
                //case FlowchartNodeContentType.MethodBody: contentTypeColor = new ColorValue( 0.4, 0.1, 0.1 ); break;

                //!!!!
                default:
                    //contentTypeColor = new ColorValue( 0.3, 0.3, 0.3 );
                    //titleColor = new ColorValue( 0.36, 0.36, 0.36 );
                    contentTypeColor = new ColorValue(0.26, 0.26, 0.26);
                    //contentTypeColor = new ColorValue( 0.24, 0.24, 0.24 );
                    titleColor = new ColorValue(0.3, 0.3, 0.3);
                    break;
                    //default: contentTypeColor = new ColorValue( 0.3, 0.3, 0.3 ); break;
                }

                if (titleColor == null)
                {
                    titleColor = contentTypeColor;
                }

                //!!!!
                //object is disabled
                {
                    var c = node.ControlledObject.Value;
                    if (c != null && !c.EnabledInHierarchy)
                    {
                        contentTypeColor *= new ColorValue(0.5, 0.5, 0.5, 1);
                    }
                }

                if (selectionStateControlledObject != EditorRenderSelectionState.None)
                {
                    titleColor = new ColorValue(0.3, 0.3, 0.3) * objColorMultiplierWithSelection;
                }

                //ColorValue titleColor;
                //if( selectionStateControlledObject == EditorRenderSelectionState.None )
                //	titleColor = contentTypeColor;
                //else
                //	titleColor = new ColorValue( 0.3, 0.3, 0.3 ) * objColorMultiplierWithSelection;

                renderer.AddQuad(titleRect, titleColor.Value);
                //renderer.AddQuad( titleRect, new ColorValue( .3, .3, .3 ) * objColorMultiplierWithSelection );

                renderer.AddQuad(bodyRect, contentTypeColor /* totalNodeColorMultiplier*/);
                //renderer.AddQuad( bodyRect, new ColorValue( .3, .3, .3 ) * totalNodeColorMultiplier );

                //renderer.AddQuad( bodyRect, new ColorValue( 1, 1, 1 ) /*new ColorValue( .3, .3, .3 )*/ * nodeColorMultiplier );
                //renderer.AddQuad( bodyRect, settings.BodyColor /*new ColorValue( .3, .3, .3 )*/ * nodeColorMultiplier );

                //renderer.AddQuad( rect, new ColorValue( .3, .3, .3 ) * nodeColorMultiplierWithSelection );
                renderer.AddRectangle(nodeRect, new ColorValue(.6, .6, .6) * objColorMultiplierWithSelection);
                renderer.AddLine(
                    window.ConvertUnitToScreen(node.Position.ToVector2() + new Vector2(0, 1)),
                    window.ConvertUnitToScreen(node.Position.ToVector2() + new Vector2(nodeSize.X, 1)),
                    new ColorValue(.6, .6, .6) * objColorMultiplierWithSelection);

                //if( titleRect.IsContainsPoint( mouse ) )
                //	mouseOverObjects.AddWithCheckAlreadyContained( node );
            }

            //!!!!было
            ////BlueprintGraphNodeComment: draw comment
            //if( node is BlueprintGraphNodeComment && !string.IsNullOrEmpty( node.NodeComment ) )
            //{
            //	renderer.AddText( fontComment, node.NodeComment, rectNode.LeftTop, HorizontalAlign.Left, VerticalAlign.Bottom,
            //		settings.CommentColor );
            //}

            if (window.GetZoom() > .25f)
            {
                //Comment
                if (!string.IsNullOrEmpty(node.Comment))                   //!!!!было && !( node is BlueprintGraphNodeComment ) )
                {
                    //!!!!style
                    var color = new ColorValue(1, 1, 1);                      //settings.CommentColor
                    renderer.AddText(window.NodeFontComment, nodeFontSizeComment, node.Comment, nodeRect.LeftTop, EHorizontalAlignment.Left, EVerticalAlignment.Bottom,
                                     color);
                }

                //title, texts
                {
                    renderer.PushClipRectangle(nodeRect);

                    //title
                    {
                        ColorValue titleColorMultiplier = new ColorValue(1, 1, 1);

                        //!!!!было
                        //if( node.IsFlowEntry() && !IsObjectSelected( node ) )
                        //	titleColorMultiplier = new ColorValue( 1, 0, 0 );

                        Vector2 pos = window.ConvertUnitToScreen(node.Position.ToVector2() + new Vector2(.1f, 0));

                        renderer.AddText(window.NodeFont, nodeFontSize, representation.Title, pos, EHorizontalAlignment.Left, EVerticalAlignment.Top,
                                         titleColorMultiplier * objColorMultiplierWithSelection);
                    }

                    //!!!!
                    ////texts
                    //if( settings.Texts != null )
                    //{
                    //	for( int n = 0; n < settings.Texts.Length; n++ )
                    //	{
                    //		string text = settings.Texts[ n ];
                    //		Vec2 pos2 = ConvertUnitToScreen( node.NodePosition.ToVec2() + new Vec2( .3, (float)n + 1 ) );
                    //		renderer.AddText( fontValue, text, pos2 + new Vec2( 0, cellHeight * .05f ), EHorizontalAlign.Left,
                    //			EVerticalAlign.Top, new ColorValue( .7f, .7f, .7f ) * nodeColorMultiplierWithSelection );
                    //	}
                    //}

                    renderer.PopClipRectangle();
                }

                //client area
                {
                    //!!!!

                    var texture = representationData.NodeImage;
                    if (texture != null)
                    {
                        Rectangle rect;
                        if (representationData.NodeImageView == FlowGraphRepresentationData.NodeImageViewEnum.WideScaled)
                        {
                            double size = 6;
                            rect = new Rectangle(
                                node.Position.ToVector2() + new Vector2(0, representation.Size.Y - size),
                                node.Position.ToVector2() + new Vector2(representation.Size.X, representation.Size.Y));

                            double border = 0.2;
                            rect.Expand(-border);

                            Rectangle rectInScreen = window.ConvertUnitToScreen(rect);
                            var       texCoords    = new Rectangle(0, 0, 1, 1);

                            var textureSize = texture.Result.ResultSize;
                            var s           = textureSize.ToVector2() / viewport.SizeInPixels.ToVector2();
                            var rect2       = new Rectangle(rectInScreen.Left, rectInScreen.Top, rectInScreen.Left + s.X, rectInScreen.Top + s.Y);

                            renderer.PushClipRectangle(rectInScreen);
                            renderer.PushTextureFilteringMode(CanvasRenderer.TextureFilteringMode.Point);
                            renderer.AddQuad(rect2, new Rectangle(0, 0, 1, 1), texture);
                            renderer.PopTextureFilteringMode();
                            renderer.PopClipRectangle();
                        }
                        else
                        {
                            double size = 5;
                            rect = new Rectangle(
                                node.Position.ToVector2() + new Vector2(0, representation.Size.Y - size),
                                node.Position.ToVector2() + new Vector2(size, representation.Size.Y));

                            double border = 0.2;
                            rect.Expand(-border);

                            Rectangle rectInScreen = window.ConvertUnitToScreen(rect);
                            renderer.AddQuad(rectInScreen, new Rectangle(0, 0, 1, 1), texture);
                        }

                        //double size = 5;
                        //double border = 0.2;
                        //Rectangle rect = new Rectangle(
                        //	node.Position.ToVector2() + new Vector2( 0, representation.Size.Y - size ),
                        //	node.Position.ToVector2() + new Vector2( size, representation.Size.Y ) );
                        //rect.Expand( -border );
                        //Rectangle rectInScreen = window.ConvertUnitToScreen( rect );

                        //renderer.AddQuad( rectInScreen, new Rectangle( 0, 0, 1, 1 ), texture );
                    }
                }

                var mouseOverSocket = mouseOverObject as Component_FlowGraphNode.Representation.Connector;

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

                    ColorValue circleColorNotSpecified = new ColorValue(0.6, 0.6, 0.6);
                    ColorValue circleColorSpecified    = new ColorValue(1, 1, 1);
                    ColorValue circleColorMouseOver    = new ColorValue(1, 1, 0);
                    ColorValue circleColorCanConnect   = new ColorValue(1, 1, 0);

                    bool isFlow = false;
                    {
                        var item2 = item as Component_FlowGraphNode.Representation.ItemProperty;
                        //!!!!может кешировать, часто бывает
                        if (item2 != null && MetadataManager.GetTypeOfNetType(typeof(FlowInput)).IsAssignableFrom(item2.Property.TypeUnreferenced))
                        {
                            isFlow = true;
                        }
                    }

                    //draw input circle
                    if (item.Input != null)
                    {
                        Vector2   center = GetSocketPositionInUnits(item, true);
                        Rectangle rect   = window.ConvertUnitToScreen(new Rectangle(center - new Vector2(.25, .25), center + new Vector2(.25, .25)));

                        ColorValue circleColor = circleColorNotSpecified;

                        //check reference specified
                        var itemProperty = item as Component_FlowGraphNode.Representation.ItemProperty;
                        if (itemProperty != null && ReferenceUtility.IsReferenceType(itemProperty.Property.Type.GetNetType()))
                        {
                            Component obj = itemProperty.Owner.Owner.ControlledObject;
                            if (obj != null)
                            {
                                var v          = itemProperty.Property.GetValue(obj, null);
                                var iReference = v as IReference;
                                if (iReference != null && !string.IsNullOrEmpty(iReference.GetByReference))
                                {
                                    //!!!!инвалидная может быть

                                    circleColor = circleColorSpecified;
                                }
                            }
                        }

                        if (mouseOverSocket != null && mouseOverSocket.item == item && mouseOverSocket.input && referenceCreationSocketFrom == null &&
                            dragDropSetReferenceData == null)
                        {
                            circleColor = circleColorMouseOver;
                        }
                        if (referenceCreationSocketFrom != null && window.CanCreateReference(item.Input, referenceCreationSocketFrom))
                        {
                            circleColor = circleColorCanConnect;
                        }
                        if (isFlow && dragDropSetReferenceData != null && window.CanCreateReferenceDragDropSetReference(dragDropSetReferenceData, item.Input, out string[] dummy))
Esempio n. 2
0
 public abstract void RenderNode(Component_FlowGraph_DocumentWindow window, Component_FlowGraphNode node,
                                 EditorRenderSelectionState selectionStateNode, EditorRenderSelectionState selectionStateControlledObject, object mouseOverObject,
                                 Component_FlowGraphNode.Representation.Connector referenceCreationSocketFrom, DragDropSetReferenceData dragDropSetReferenceData);