Exemplo n.º 1
0
        public override void Draw(IPlatformDrawer platform, float scale)
        {
            base.Draw(platform, scale);

            var headerPadding = StyleSchema.HeaderPadding;
//            var headerBounds = new Rect(
//                Bounds.x - headerPadding.left,
//                Bounds.y,
//                Bounds.width + headerPadding.left * 2 + 1,
//                Bounds.height + (NodeViewModel.IsCollapsed ? 0 : -20) + headerPadding.bottom);
            var headerBounds = new Rect(
                //Bounds.x-headerPadding.left-1,
                Bounds.x - headerPadding.left + 1,
                Bounds.y + 1,
                Bounds.width + headerPadding.left + headerPadding.right + headerPadding.left - 6,
                Bounds.height + 0 + (NodeViewModel.IsCollapsed ? 9 : -2));

            var image = HeaderImage;

            platform.DrawNodeHeader(
                headerBounds,
                NodeViewModel.IsCollapsed ? StyleSchema.CollapsedHeaderStyleObject : StyleSchema.ExpandedHeaderStyleObject,
                NodeViewModel.IsCollapsed,
                scale, image);


            // The bounds for the main text

//            var textBounds = new Rect(Bounds.x, Bounds.y + ((Bounds.height / 2f) - (TextSize.y / 2f)), Bounds.width,
//                Bounds.height);
            var padding     = headerPadding;
            var titleBounds = new Rect(
                Bounds.x + padding.left,
                Bounds.y + padding.top + (StyleSchema.ShowSubtitle ? 1 : 0),
                Bounds.width - padding.right - padding.left - (StyleSchema.ShowIcon ? 16 : 0), //Subtract icon size if shown
                Bounds.height - padding.top - padding.bottom);

            var titleSize = platform.CalculateTextSize(NodeViewModel.Label, StyleSchema.TitleStyleObject);

            var subtitleBound = new Rect(Bounds.x + padding.left + 0, Bounds.y + padding.top + titleSize.y + 0, Bounds.width - padding.right, Bounds.height - padding.top);



            if (NodeViewModel.IsEditing && NodeViewModel.IsEditable)
            {
                //UnityEngine.GUI.SetNextControlName("EditingField");
                //DiagramDrawer.IsEditingField = true;
                //UnityEditor.EditorGUI.BeginChangeCheck();

                //var newText = GUI.TextField(textBounds.Scale(scale), NodeViewModel.Name,
                //    ElementDesignerStyles.ViewModelHeaderEditingStyle);

                //if (UnityEditor.EditorGUI.EndChangeCheck())
                //{
                //    NodeViewModel.Rename(newText);
                //    Dirty = true;
                //}

                //textBounds.y += TextSize.y / 2f;
                platform.DrawTextbox(NodeViewModel.GraphItemObject.Identifier, titleBounds.Scale(scale), NodeViewModel.Name, CachedStyles.ViewModelHeaderStyle, (v, finished) =>
                {
                    NodeViewModel.Rename(v);
                    ParentDrawer.Refresh(platform);
                    if (finished)
                    {
                        NodeViewModel.EndEditing();
                    }
                });
            }
            else
            {
                //var titleStyle = new GUIStyle(TextStyle);
                //titleStyle.normal.textColor = BackgroundStyle.normal.textColor;
                //titleStyle.alignment = TextAnchor.MiddleCenter;
                //titleStyle.fontSize = Mathf.RoundToInt(12*scale);
                platform.DrawLabel(titleBounds.Scale(scale), NodeViewModel.Label ?? string.Empty, StyleSchema.TitleStyleObject, StyleSchema.ShowSubtitle ? DrawingAlignment.TopLeft : DrawingAlignment.MiddleLeft);

                if (StyleSchema.ShowSubtitle && !string.IsNullOrEmpty(NodeViewModel.SubTitle))
                {
                    platform.DrawLabel(subtitleBound.Scale(scale), NodeViewModel.SubTitle ?? string.Empty,
                                       StyleSchema.SubTitleStyleObject, StyleSchema.ShowSubtitle ? DrawingAlignment.TopLeft : DrawingAlignment.MiddleLeft);
                }

                if (StyleSchema.ShowIcon && !string.IsNullOrEmpty(NodeViewModel.IconName))
                {
                    var iconsize    = IconBounds ?? (IconBounds = new Vector2(16, 16));
                    var size        = 16;
                    var imageBounds = new Rect(Bounds.xMax - padding.right - size, Bounds.y + ((Bounds.height / 2f) - (size / 2f)), 16, 16);


                    //var imageBounds = new Rect().WithSize(16, 16).InnerAlignWithUpperRight(Bounds).AlignHorisonallyByCenter(headerBounds).Translate(-headerPadding.right,0);
                    var cCache = GUI.color;
                    GUI.color = new Color(cCache.r, cCache.g, cCache.b, 0.7f);
                    platform.DrawImage(imageBounds.Scale(scale), IconImage, true);
                    GUI.color = cCache;

                    if (!string.IsNullOrEmpty(IconTooltip))
                    {
                        platform.SetTooltipForRect(imageBounds.Scale(scale), IconTooltip);
                    }
                }

                //GUI.Label(textBounds.Scale(scale), NodeViewModel.Label ?? string.Empty, titleStyle);
                //if (NodeViewModel.IsCollapsed)
                //{
                //    textBounds.y += TextSize.y/2f;
                //    //titleStyle.fontSize = Mathf.RoundToInt(10*scale);
                //    //titleStyle.fontStyle = FontStyle.Italic;

                //    GUI.Label(textBounds.Scale(scale), NodeViewModel.SubTitle, titleStyle);
                //}
            }
        }
Exemplo n.º 2
0
        public override void Draw(IPlatformDrawer platform, float scale)
        {
            base.Draw(platform, scale);

            var headerPadding = StyleSchema.HeaderPadding;
//            var headerBounds = new Rect(
//                Bounds.x - headerPadding.left, 
//                Bounds.y, 
//                Bounds.width + headerPadding.left * 2 + 1,
//                Bounds.height + (NodeViewModel.IsCollapsed ? 0 : -20) + headerPadding.bottom);
            var headerBounds = new Rect(
                //Bounds.x-headerPadding.left-1, 
                Bounds.x-headerPadding.left+1, 
                Bounds.y+1, 
                Bounds.width + headerPadding.left + headerPadding.right + headerPadding.left -6,
                Bounds.height+0 + (NodeViewModel.IsCollapsed ? 9 : -2));

            var image = HeaderImage;

                platform.DrawNodeHeader(
                    headerBounds, 
                    NodeViewModel.IsCollapsed ? StyleSchema.CollapsedHeaderStyleObject : StyleSchema.ExpandedHeaderStyleObject, 
                    NodeViewModel.IsCollapsed, 
                    scale,image);
            

            // The bounds for the main text

//            var textBounds = new Rect(Bounds.x, Bounds.y + ((Bounds.height / 2f) - (TextSize.y / 2f)), Bounds.width,
//                Bounds.height);
            var padding = headerPadding;
            var titleBounds = new Rect(
                Bounds.x + padding.left, 
                Bounds.y + padding.top + (StyleSchema.ShowSubtitle ? 1 : 0 ) , 
                Bounds.width-padding.right-padding.left-(StyleSchema.ShowIcon ? 16 : 0), //Subtract icon size if shown
                Bounds.height-padding.top-padding.bottom);

            var titleSize = platform.CalculateTextSize(NodeViewModel.Label, StyleSchema.TitleStyleObject);

            var subtitleBound = new Rect(Bounds.x + padding.left+0, Bounds.y + padding.top + titleSize.y + 0, Bounds.width-padding.right, Bounds.height-padding.top);




            if (NodeViewModel.IsEditing && NodeViewModel.IsEditable)
            {

                //UnityEngine.GUI.SetNextControlName("EditingField");
                //DiagramDrawer.IsEditingField = true;
                //UnityEditor.EditorGUI.BeginChangeCheck();

                //var newText = GUI.TextField(textBounds.Scale(scale), NodeViewModel.Name,
                //    ElementDesignerStyles.ViewModelHeaderEditingStyle);

                //if (UnityEditor.EditorGUI.EndChangeCheck())
                //{
                //    NodeViewModel.Rename(newText);
                //    Dirty = true;
                //}

                //textBounds.y += TextSize.y / 2f;
                platform.DrawTextbox(NodeViewModel.GraphItemObject.Identifier, titleBounds.Scale(scale), NodeViewModel.Name, CachedStyles.ViewModelHeaderStyle, (v, finished) =>
                {
                    NodeViewModel.Rename(v);
                    ParentDrawer.Refresh(platform);
                    if (finished)
                    {
                        NodeViewModel.EndEditing();
                    }
                });

            }
            else
            {
                //var titleStyle = new GUIStyle(TextStyle);
                //titleStyle.normal.textColor = BackgroundStyle.normal.textColor;
                //titleStyle.alignment = TextAnchor.MiddleCenter;
                //titleStyle.fontSize = Mathf.RoundToInt(12*scale);
                platform.DrawLabel(titleBounds.Scale(scale), NodeViewModel.Label ?? string.Empty, StyleSchema.TitleStyleObject, StyleSchema.ShowSubtitle ? DrawingAlignment.TopLeft : DrawingAlignment.MiddleLeft);

                if (StyleSchema.ShowSubtitle && !string.IsNullOrEmpty(NodeViewModel.SubTitle))
                {
                    platform.DrawLabel(subtitleBound.Scale(scale), NodeViewModel.SubTitle ?? string.Empty,
                        StyleSchema.SubTitleStyleObject, StyleSchema.ShowSubtitle ? DrawingAlignment.TopLeft : DrawingAlignment.MiddleLeft);
                }

                if (StyleSchema.ShowIcon && !string.IsNullOrEmpty(NodeViewModel.IconName))
                {
                    var iconsize = IconBounds ?? (IconBounds = new Vector2(16,16));
                    var size = 16;
                    var imageBounds = new Rect(Bounds.xMax - padding.right - size, Bounds.y + ((Bounds.height / 2f) - (size / 2f)), 16, 16);


                    //var imageBounds = new Rect().WithSize(16, 16).InnerAlignWithUpperRight(Bounds).AlignHorisonallyByCenter(headerBounds).Translate(-headerPadding.right,0);
                    var cCache = GUI.color;
                    GUI.color = new Color(cCache.r, cCache.g, cCache.b, 0.7f);
                    platform.DrawImage(imageBounds.Scale(scale), IconImage, true);
                    GUI.color = cCache;

                    if (!string.IsNullOrEmpty(IconTooltip))
                    {
                        platform.SetTooltipForRect(imageBounds.Scale(scale), IconTooltip);
                    }


                }

                //GUI.Label(textBounds.Scale(scale), NodeViewModel.Label ?? string.Empty, titleStyle);
                //if (NodeViewModel.IsCollapsed)
                //{
                //    textBounds.y += TextSize.y/2f;
                //    //titleStyle.fontSize = Mathf.RoundToInt(10*scale);
                //    //titleStyle.fontStyle = FontStyle.Italic;

                //    GUI.Label(textBounds.Scale(scale), NodeViewModel.SubTitle, titleStyle);
                //}
            }
        }