private void DrawTheWhole(Graphics graphics, string name, float height, float padding, float cornerRadius, float sideDistance, float lineWeight, Color nameColor, Color backgroundColor, Color lineColor, Color triColor, bool top) { float zoom = Grasshopper.Instances.ActiveCanvas.Viewport.Zoom; height /= zoom; padding /= zoom; cornerRadius /= zoom; lineWeight /= zoom; padding += height * 0.2f; Font font = new Font(GH_FontServer.Standard.FontFamily, height / 2); float triangleWidth = height * (float)Math.Pow(3, 0.5) / 2; PointF pivot = top ? GetMiddleUpPt(sideDistance / zoom + height) : GetMiddleDownPt(sideDistance / zoom); float nameBoxwidth = Math.Min(graphics.MeasureString(name, font).Width, Grasshopper.Instances.ActiveCanvas.Viewport.VisibleRegion.Width - 4 * triangleWidth); nameRect = CanvasRenderEngine.MiddleDownRect(pivot, new SizeF(nameBoxwidth, height)); CanvasRenderEngine.DrawTextBox_Obsolete(graphics, nameRect, backgroundColor, lineColor, name, font, nameColor, lineWeight, -40, cornerRadius); SizeF triangleSize = new SizeF(triangleWidth, height); float distance = nameBoxwidth / 2 + padding + triangleWidth / 2; leftButton = CanvasRenderEngine.MiddleDownRect(new PointF(pivot.X - distance, pivot.Y), triangleSize); rightButton = CanvasRenderEngine.MiddleDownRect(new PointF(pivot.X + distance, pivot.Y), triangleSize); DrawBothTriangle(graphics, lineWeight, lineColor, triColor, cornerRadius / 2f); this.Bounds = CanvasRenderEngine.MiddleDownRect(pivot, new SizeF(nameBoxwidth + triangleWidth * 2 + padding * 2, height)); }
private void RenderTextBox(Graphics graphics, Font font, int i) { if (Owner.IsShowLabel) { string str = ""; PointF pivot = new PointF((((IGH_Param)Target).Sources.ElementAt(i).Attributes.OutputGrip.X + ((IGH_Param)Target).Attributes.InputGrip.X) / 2, ((((IGH_Param)Target).Sources.ElementAt(i).Attributes.OutputGrip.Y + ((IGH_Param)Target).Attributes.InputGrip.Y) / 2)); if (Owner.IsShowLabel) { str += ParamProxies[i].TypeName + "\n"; } if (Owner.IsShowTree) { string dataStr = ""; var datas = ((IGH_Param)Target).Sources.ElementAt(i).VolatileData; for (int j = 0; j < Math.Min(datas.PathCount, Owner.TreeCount); j++) { dataStr += datas.get_Path(j).ToString() + " N = " + datas.get_Branch(j).Count.ToString() + "\n"; } if (datas.PathCount > Owner.TreeCount) { dataStr += "..."; } else if (datas.PathCount == 1) { for (int k = 0; k < Math.Min(datas.get_Branch(0).Count, Owner.TreeCount); k++) { var obj = datas.get_Branch(0)[k]; if (obj == null) { dataStr += "Null\n"; } else { dataStr += obj.ToString() + "\n"; } } if (datas.get_Branch(0).Count > Owner.TreeCount) { dataStr += "..."; } } str += dataStr; } if (str == "") { return; } SizeF size = graphics.MeasureString(str, font); PointF loc = new PointF(pivot.X, pivot.Y + size.Height / 2); TextBox.DrawTextBox(graphics, CanvasRenderEngine.MiddleDownRect(loc, size), Owner.LabelBackGroundColor, Owner.LabelBoundaryColor, str, font, Owner.LabelTextColor, isCenter: true); } }
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); })); } } }