protected override RectangleF Layout(GH_Canvas canvas, Graphics graphics, RectangleF rect)
        {
            RectangleF newRect = rect;

            if (this.Target is GH_Component)
            {
                GH_Component com    = this.Target as GH_Component;
                int          height = CanvasRenderEngine.MessageBoxHeight(com.Message, (int)rect.Width);
                newRect = new RectangleF(rect.Location, new SizeF(rect.Width, rect.Height + height));
            }
            newRect.Inflate(this.Radius, this.Radius);
            return(newRect);
        }
Exemple #2
0
        private void AddOneObject(IGH_DocumentObject obj)
        {
            bool showNormal = !normalExceptionGuid.Contains(obj.ComponentGuid);
            bool showPlugin = !pluginExceptionGuid.Contains(obj.ComponentGuid);

            if (showNormal)
            {
                Font             nameFont = new Font(GH_FontServer.Standard.FontFamily, NameBoxFontSize);
                TextBoxRenderSet nameSet  = new TextBoxRenderSet(BackGroundColor, BoundaryColor, nameFont, TextColor);
                if (this.IsShowName)
                {
                    Func <SizeF, RectangleF, RectangleF> layout = (x, y) =>
                    {
                        PointF pivot = new PointF(y.Left + y.Width / 2, y.Top - NameBoxDistance);
                        return(CanvasRenderEngine.MiddleDownRect(pivot, x));
                    };
                    this.RenderObjs.Add(new NickNameOrNameTextBox(this.IsShowNickName, obj, layout, nameSet));
                }

                string cate    = IsShowFullCate ? obj.Category : Grasshopper.Instances.ComponentServer.GetCategoryShortName(obj.Category);
                string subcate = obj.SubCategory;

                if (this.IsShowCategory)
                {
                    if (IsMergeCateBox)
                    {
                        string cateName = cate + " - " + subcate;
                        this.RenderObjs.Add(new TextBox(cateName, obj, (x, y) =>
                        {
                            PointF pivot = new PointF(y.Left + y.Width / 2, y.Top - NameBoxDistance - ((this.IsShowName ? x.Height : 0) + 3));
                            return(CanvasRenderEngine.MiddleDownRect(pivot, x));
                        }, nameSet));
                    }
                    else
                    {
                        this.RenderObjs.Add(new TextBox(subcate, obj, (x, y) =>
                        {
                            PointF pivot = new PointF(y.Left + y.Width / 2, y.Top - NameBoxDistance - ((this.IsShowName ? x.Height : 0) + 3));
                            return(CanvasRenderEngine.MiddleDownRect(pivot, x));
                        }, nameSet));

                        this.RenderObjs.Add(new TextBox(cate, obj, (x, y) =>
                        {
                            PointF pivot = new PointF(y.Left + y.Width / 2, y.Top - NameBoxDistance - ((this.IsShowName ? x.Height : 0) + 3) * 2);
                            return(CanvasRenderEngine.MiddleDownRect(pivot, x));
                        }, nameSet));
                    }
                }
            }


            if ((this.IsShowAssem) || (this.IsShowPlugin && showPlugin))
            {
                string fullName = "";
                string location = "";

                Type type = obj.GetType();
                if (type != null)
                {
                    fullName = type.FullName;

                    GH_AssemblyInfo info = null;
                    foreach (GH_AssemblyInfo lib in Grasshopper.Instances.ComponentServer.Libraries)
                    {
                        if (lib.Assembly == obj.GetType().Assembly)
                        {
                            info = lib;
                            break;
                        }
                    }
                    if (info != null)
                    {
                        location = info.Location;
                        if (!info.IsCoreLibrary)
                        {
                            if (IsShowPlugin && showPlugin)
                            {
                                this.RenderObjsUnderComponent.Add(new HighLightRect(obj, PluginHighLightColor, HighLightRadius));
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(fullName) && this.IsShowAssem)
                {
                    float height = AssemBoxHeight * 14;
                    if (IsAutoAssem)
                    {
                        if (obj is IGH_Component)
                        {
                            IGH_Component com = obj as IGH_Component;
                            height = CanvasRenderEngine.MessageBoxHeight(com.Message, (int)obj.Attributes.Bounds.Width);
                        }
                        else
                        {
                            height = 0;
                        }

                        if (IsAvoidProfiler)
                        {
                            if (height == 0)
                            {
                                height = Math.Max(height, 16);
                            }
                            else
                            {
                                height = Math.Max(height, 32);
                            }
                        }
                    }
                    height += 5;

                    Font             assemFont = new Font(GH_FontServer.Standard.FontFamily, AssemFontSize);
                    TextBoxRenderSet assemSet  = new TextBoxRenderSet(Color.FromArgb(BackGroundColor.A / 2, BackGroundColor), BoundaryColor, assemFont, TextColor);
                    string           fullStr   = fullName;
                    if (location != null)
                    {
                        fullStr += "\n \n" + location;
                    }

                    this.RenderObjs.Add(new TextBox(fullStr, obj, (x, y) =>
                    {
                        PointF pivot = new PointF(y.Left + y.Width / 2, y.Bottom + height);
                        return(CanvasRenderEngine.MiddleUpRect(pivot, x));
                    }, assemSet, (x, y, z) =>
                    {
                        return(x.MeasureString(y, z, AssemBoxWidth));
                    }, showFunc: () => { return(obj.Attributes.Selected); }));
                }
            }
        }