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)); }
public override void Layout(RectangleF innerRect, RectangleF outerRect) { float small = -2; RectangleF rect = CanvasRenderEngine.MaxSquare(ParamControlHelper.ParamLayoutBase(this.Target.Attributes, Width, outerRect)); rect.Inflate(small, small); this.Bounds = rect; }
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 DrawOneLegend(Graphics graphics, PointF pivot, GooTypeProxy info, float size, float mult) { float height = size * mult; float padding = size * (1 - mult) / 2; RectangleF fillRect = new RectangleF(pivot.X, pivot.Y - size, size, size); fillRect.Inflate(-padding, -padding); graphics.FillPath(new SolidBrush(info.ShowColor), CanvasRenderEngine.GetRoundRectangle_Obsolete(fillRect, padding)); graphics.DrawString(info.TypeName, new Font(GH_FontServer.Standard.FontFamily, height / 2), new SolidBrush(Owner.LegendTextColor), new PointF(pivot.X + size + padding, pivot.Y - height - padding)); }
public static void CreateNewObject(IGH_DocumentObject obj, IGH_Param target, bool isInputSide, int index = 0, float leftMove = 100, string init = null) { if (obj == null) { return; } PointF comRightCenter = new PointF(target.Attributes.Bounds.Left + (isInputSide ? -leftMove:(leftMove + target.Attributes.Bounds.Width)), target.Attributes.Bounds.Top + target.Attributes.Bounds.Height / 2); if (obj is GH_Component) { GH_Component com = obj as GH_Component; CanvasRenderEngine.AddAObjectToCanvas(com, comRightCenter, false, init); if (isInputSide) { target.AddSource(com.Params.Output[index]); } else { com.Params.Input[index].AddSource(target); } //com.Params.Output[outIndex].Recipients.Add(target); target.OnPingDocument().NewSolution(false); } else if (obj is IGH_Param) { IGH_Param param = obj as IGH_Param; CanvasRenderEngine.AddAObjectToCanvas(param, comRightCenter, false, init); if (isInputSide) { target.AddSource(param); } else { param.AddSource(target); } target.OnPingDocument().NewSolution(false); } else { target.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, LanguagableComponent.GetTransLation(new string[] { "The added object is not a Component or Parameters!", "添加的对象不是一个运算器或参数!", })); } }
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); }
private void DialogHost_DialogOpened(object sender, MaterialDesignThemes.Wpf.DialogOpenedEventArgs eventArgs) { IndexTextBox.Text = null; ActiveBorder.Visibility = Visibility.Visible; this.ComponentName.Text = _selectedProxy.FullName; System.Drawing.Bitmap bitmap = CanvasRenderEngine.GetObjectBitmap(_selectedProxy.CreateObejct(), this._isInput, out _); ShowcaseImage.Source = CanvasRenderEngine.BitmapToBitmapImage(bitmap); this.DialogCancelButton.Content = LanguagableComponent.GetTransLation(new string[] { "CANCEL", "取消" }); this.DialogFinishButton.Content = LanguagableComponent.GetTransLation(new string[] { "ACCEPT", "接受" }); HintAssist.SetHint(this.IndexTextBox, _isInput ? LanguagableComponent.GetTransLation(new string[] { "Output Index", "输出端索引" }) : LanguagableComponent.GetTransLation(new string[] { "Input Index", "输入端索引" })); }
public ObjectProxy(IGH_DocumentObject obj) { this.FullName = obj.Name; this.Category = obj.HasCategory ? obj.Category : ""; this.Subcategory = obj.HasSubCategory ? obj.SubCategory : ""; this.Description = obj.Description; this.Icon = CanvasRenderEngine.BitmapToBitmapImage(obj.Icon_24x24); this.Guid = obj.ComponentGuid; this.Exposure = obj.Exposure; foreach (var item in Grasshopper.Instances.ComponentServer.Libraries) { if (item.Assembly == obj.GetType().Assembly) { this.IsPlugin = !item.IsCoreLibrary; this.Location = item.Location; break; } } }
public ObjectProxy(IGH_ObjectProxy proxy) { this.FullName = proxy.Desc.Name; this.Category = string.IsNullOrEmpty(proxy.Desc.Category) ? "No Category" : proxy.Desc.Category; this.Subcategory = string.IsNullOrEmpty(proxy.Desc.SubCategory) ? "No SubCategory" : proxy.Desc.SubCategory; this.Description = proxy.Desc.Description; this.Icon = CanvasRenderEngine.BitmapToBitmapImage(proxy.Icon); this.Guid = proxy.Guid; this.Exposure = proxy.Exposure; this.Location = proxy.Location; foreach (var item in Grasshopper.Instances.ComponentServer.Libraries) { if (item.Id == proxy.LibraryGuid) { this.IsPlugin = !item.IsCoreLibrary; break; } } }
private void IndexTextBox_TextChanged(object sender, TextChangedEventArgs e) { DialogFinishButton.IsEnabled = true; SelectedMessage.Text = SelectedParam.Text = null; System.Drawing.Bitmap bitmap; SelectedMessage.Foreground = new SolidColorBrush(ColorExtension.ConvertToMediaColor(System.Drawing.Color.DimGray)); byte index; if (byte.TryParse(IndexTextBox.Text, out index)) { IGH_Param dataType; bitmap = CanvasRenderEngine.GetObjectBitmap(_selectedProxy.CreateObejct(), this._isInput, out dataType, index); if (bitmap != null) { ShowcaseImage.Source = CanvasRenderEngine.BitmapToBitmapImage(bitmap); SelectedParam.Text = $"{dataType.Name} [{dataType.Type.Name}]"; if (this._proxy.TypeFullName != dataType.Type.FullName) { SelectedMessage.Text += LanguagableComponent.GetTransLation(new string[] { "Data Type is not the Same!", "数据类型并不一致!" }); SelectedMessage.Foreground = new SolidColorBrush(ColorExtension.ConvertToMediaColor(System.Drawing.Color.DarkOrange)); } } else { bitmap = CanvasRenderEngine.GetObjectBitmap(_selectedProxy.CreateObejct(), this._isInput, out _); SelectedMessage.Text = LanguagableComponent.GetTransLation(new string[] { "Input data is out of range!", "输入数据超出索引阈值!" }); SelectedMessage.Foreground = new SolidColorBrush(ColorExtension.ConvertToMediaColor(System.Drawing.Color.DarkRed)); DialogFinishButton.IsEnabled = false; } } else { bitmap = CanvasRenderEngine.GetObjectBitmap(_selectedProxy.CreateObejct(), this._isInput, out _); SelectedMessage.Text = LanguagableComponent.GetTransLation(new string[] { "Please input a number between 0 - 255!", "请输入一个0 - 255的数值!" }); SelectedMessage.Foreground = new SolidColorBrush(ColorExtension.ConvertToMediaColor(System.Drawing.Color.DarkRed)); DialogFinishButton.IsEnabled = false; } ShowcaseImage.Source = CanvasRenderEngine.BitmapToBitmapImage(bitmap); this._paramIndex = index; }
public ComTypeInfo(IGH_DocumentObject obj) { this.Category = obj.HasCategory ? obj.Category : LanguagableComponent.GetTransLation(new string[] { "<Unnamed Category>", "<未命名类别>" }); this.Subcategory = obj.HasSubCategory ? obj.SubCategory : LanguagableComponent.GetTransLation(new string[] { "<Unnamed Subcategory>", "<未命名子类>" }); this.Name = obj.Name; this.Description = obj.Description; #region Bitmap bitmap = new Bitmap(obj.Icon_24x24, 20, 20); this.Icon = CanvasRenderEngine.BitmapToBitmapImage(bitmap); #endregion this.Exposure = obj.Exposure; this.Guid = obj.ComponentGuid; Type type = obj.GetType(); GH_AssemblyInfo lib = null; Isvalid = true; if (type == null) { this.FullName = ""; } else { this.FullName = type.FullName; lib = GetGHLibrary(type); } this.PluginLocation = lib.Location; this.ShowLocation = this.PluginLocation; this.IsPlugin = !lib.IsCoreLibrary; if (lib != null) { this.AssemblyName = lib.Name; this.AssemblyAuthor = lib.AuthorName; } this.Tip = CreateTip(); }
private void DrawDataTree(List <GooTypeProxy> proxies) { if (LeftCateTree == null) { return; } var result = proxies.GroupBy((x) => x.Assembly).ToList(); result.Sort((x, y) => x.Key.Name.CompareTo(y.Key.Name)); foreach (var categoryItem in result) { TreeViewItem viewItem = new TreeViewItem(); #region Dim the CategoryName StackPanel panel = new StackPanel(); panel.MouseDown += AssemblyClick; panel.Orientation = Orientation.Horizontal; try { panel.Children.Add(new Image() { Source = CanvasRenderEngine.BitmapToBitmapImage( new System.Drawing.Bitmap(categoryItem.Key.Icon, 20, 20)), }); } catch { } panel.Children.Add(new Label() { Content = categoryItem.Key.Name, FontSize = 15, Margin = new Thickness(5, 0, 0, 0), }); viewItem.Header = panel; #endregion LeftCateTree.Items.Add(viewItem); } }
public ComTypeInfo(IGH_ObjectProxy proxy) { this.Category = proxy.Desc.HasCategory ? proxy.Desc.Category : LanguagableComponent.GetTransLation(new string[] { "<Unnamed Category>", "<未命名类别>" }); this.Subcategory = proxy.Desc.HasSubCategory ? proxy.Desc.SubCategory : LanguagableComponent.GetTransLation(new string[] { "<Unnamed Subcategory>", "<未命名子类>" }); this.Name = proxy.Desc.Name; this.Description = proxy.Desc.Description; #region Bitmap bitmap = new Bitmap(proxy.Icon, 20, 20); this.Icon = CanvasRenderEngine.BitmapToBitmapImage(bitmap); #endregion this.Exposure = proxy.Exposure; this.Guid = proxy.Guid; Isvalid = true; Type type = proxy.Type; GH_AssemblyInfo lib = null; if (type == null) { this.FullName = ""; } else { this.FullName = type.FullName; lib = GetGHLibrary(type); } this.IsPlugin = checkisPlugin(proxy, lib); if (lib != null) { this.AssemblyName = lib.Name; this.AssemblyAuthor = lib.AuthorName; } this.Tip = CreateTip(); }
private void DrawLegend(Graphics graphics) { if (Owner.ShowProxy.Count == 0) { return; } float zoom = Grasshopper.Instances.ActiveCanvas.Viewport.Zoom; float size = (float)Owner.LegendSize / zoom; float spacing = (float)Owner.LegendSpacing / zoom; float mult = 0.8f; float width = 0f; foreach (var info in Owner.ShowProxy) { float newWidth = graphics.MeasureString(info.TypeName, new Font(GH_FontServer.Standard.FontFamily, size * mult / 2)).Width; if (newWidth > width) { width = newWidth; } } float height = Owner.ShowProxy.Count * size; width += size; float oneWayWidth = width; RectangleF rect = Grasshopper.Instances.ActiveCanvas.Viewport.VisibleRegion; int heightMult = (int)(height / (rect.Height - 2 * spacing)); if (heightMult > 0) { height = rect.Height - 2 * spacing; width += heightMult * (width + size); } PointF pivot; switch (Owner.LegendLocation) { case 0: pivot = new PointF(rect.X + spacing, rect.Y + height + spacing); break; case 1: pivot = new PointF(rect.X + spacing, rect.Y + rect.Height - spacing); break; case 2: pivot = new PointF(rect.Right - width - spacing, rect.Y + rect.Height - spacing); break; case 3: pivot = new PointF(rect.Right - width - spacing, rect.Y + height + spacing); break; default: pivot = new PointF(rect.X, rect.Y + height); break; } RectangleF background = new RectangleF(pivot.X, pivot.Y - height, width, height); background.Inflate(size / 4, size / 4); GraphicsPath path = CanvasRenderEngine.GetRoundRectangle_Obsolete(background, size / 4); graphics.FillPath(new SolidBrush(Owner.LegendBackGroundColor), path); graphics.DrawPath(new Pen(Owner.LegendBoundaryColor, size / 15), path); float actHeight = 0; float startY = pivot.Y; foreach (var info in Owner.ShowProxy) { DrawOneLegend(graphics, pivot, info, size, mult); actHeight += size; if (actHeight > rect.Height - 2 * spacing) { actHeight = 0; pivot = new PointF(pivot.X + oneWayWidth + size, startY); } else { pivot = new PointF(pivot.X, pivot.Y - size); } } }
private void DrawDataTree(List <ExceptionProxy> proxies) { if (LeftCateTree == null) { return; } var result = proxies.GroupBy((x) => x.Category).ToList(); result.Sort((x, y) => x.Key.CompareTo(y.Key)); foreach (var categoryItem in result) { TreeViewItem viewItem = new TreeViewItem(); #region Dim the CategoryName StackPanel panel = new StackPanel(); panel.MouseDown += CategoryClick; panel.Orientation = Orientation.Horizontal; try { panel.Children.Add(new Image() { Source = CanvasRenderEngine.BitmapToBitmapImage( new System.Drawing.Bitmap(Grasshopper.Instances.ComponentServer.GetCategoryIcon(categoryItem.Key), 20, 20)), }); } catch { } panel.Children.Add(new Label() { Content = categoryItem.Key, FontSize = 15, Margin = new Thickness(5, 0, 0, 0), }); viewItem.Header = panel; #endregion var relayResult = categoryItem.ToList().GroupBy((x) => x.Subcategory).ToList(); relayResult.Sort((x, y) => x.Key.CompareTo(y.Key)); foreach (var SubcategoryItem in relayResult) { Label label = new Label() { Content = SubcategoryItem.Key, Margin = new Thickness(5, 0, 0, 0), Foreground = new SolidColorBrush(Color.FromRgb(40, 40, 40)), }; TreeViewItem treeView = new TreeViewItem() { Header = label, }; treeView.Selected += SubcateClick; viewItem.Items.Add(treeView); } LeftCateTree.Items.Add(viewItem); } }
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); })); } } }