private int ComputeW_ico(IGH_Component owner) { GH_SwitcherComponent gH_SwitcherComponent = (GH_SwitcherComponent)owner; int num = 24; int num2 = 0; int num3 = 0; foreach (IGH_Param componentInput in gH_SwitcherComponent.StaticData.GetComponentInputs()) { int val = ((List <IGH_StateTag>)componentInput.StateTags).Count * 20; num3 = Math.Max(num3, val); num2 = Math.Max(num2, GH_FontServer.StringWidth(componentInput.NickName, StandardFont.font())); } num2 = Math.Max(num2 + 6, 12); num2 += num3; int num4 = 0; int num5 = 0; foreach (IGH_Param componentOutput in gH_SwitcherComponent.StaticData.GetComponentOutputs()) { int val2 = ((List <IGH_StateTag>)componentOutput.StateTags).Count * 20; num5 = Math.Max(num5, val2); num4 = Math.Max(num4, GH_FontServer.StringWidth(componentOutput.NickName, StandardFont.font())); } num4 = Math.Max(num4 + 6, 12); num4 += num5; return(num2 + num + num4 + 6); }
private void DisplayDefaultComponent() { //reset the comonent imgBitmap = null; this.scale = 1; this.Owner.Message = null; RectangleF rec = GetImgBounds(Bounds, TopOffset, BtmOffset); Pen pen = new Pen(Color.Gray, 3); SolidBrush myBrush = new SolidBrush(Color.Gray); Font standardFont = GH_FontServer.Standard; //29 //Font standardFont4kScreen = new Font(standardFont.Name, 4); //15 Font standardFontAdjust = GH_FontServer.NewFont(standardFont, (float)Math.Round(120M / standardFont.Height)); StringFormat myFormat = new StringFormat(); MyGraphics.FillRectangle(myBrush, Rectangle.Round(rec)); //graphics.DrawRectangle(pen, Rectangle.Round(imgViewBounds)); MyGraphics.DrawString("Please use a valid image file path.\nHDR, TIF, PNG, GIF, or JPG image", standardFontAdjust, Brushes.White, new Point((int)rec.X + 12, (int)rec.Y + ((int)rec.Width * 2 / 3) + 10), myFormat); MyGraphics.DrawImage(Resources.Ladybug_Viewer_370, new RectangleF(rec.X, rec.Y, rec.Width, rec.Width * 2 / 3)); myBrush.Dispose(); myFormat.Dispose(); }
private void DrawComponentName(Graphics g, RectangleF ContentBox = new RectangleF(), bool IsFullName = true) { Pen _Pen = new Pen(Color.Black, 1); Brush _Brush = _Pen.Brush; string Text = IsFullName? this.ParamComponent.Name: this.ParamComponent.NickName; SizeF NameSize = GH_FontServer.MeasureString(Text, GH_FontServer.Large); //ContentBox is the property and m_innerBounds is the field StringFormat Format = new StringFormat(StringFormatFlags.DirectionVertical); Format.Alignment = StringAlignment.Center; Format.LineAlignment = StringAlignment.Center; //先存储Graphics的状态 //对Graphics执行操作 GraphicsState State = g.Save(); //修改旋转中心点 g.TranslateTransform(ContentBox.X + ContentBox.Width / 2, ContentBox.Y + ContentBox.Height / 2); g.RotateTransform(-180); g.TranslateTransform(-(ContentBox.X + ContentBox.Width / 2), -(ContentBox.Y + ContentBox.Height / 2)); //回复旋转中心点 g.DrawString(Text, GH_FontServer.Large, _Brush, ContentBox, Format); // 恢复Graphics的状态,否则Parameter Name的绘制将会出错 g.Restore(State); Format.Dispose(); }
protected override void Render(GH_Canvas canvas, System.Drawing.Graphics graphics, GH_CanvasChannel channel) { base.Render(canvas, graphics, channel); if (channel == GH_CanvasChannel.Objects) { //We need to draw everything outselves. Color myColour = UI.Colour.GsaDarkBlue; Brush myBrush = new SolidBrush(myColour); //Text boxes Brush activeFillBrush = myBrush; Brush passiveFillBrush = Brushes.LightGray; Color borderColour = myColour; Color passiveBorder = Color.DarkGray; Brush annoText = Brushes.Black; Font font = GH_FontServer.Standard; int s = 8; if (Grasshopper.CentralSettings.CanvasFullNames) { s = 10; font = GH_FontServer.Standard; } // adjust fontsize to high resolution displays font = new Font(font.FontFamily, font.Size / GH_GraphicsUtil.UiScale, FontStyle.Regular); Font sml = GH_FontServer.Small; // adjust fontsize to high resolution displays sml = new Font(sml.FontFamily, sml.Size / GH_GraphicsUtil.UiScale, FontStyle.Regular); //draw the component base.RenderComponentCapsule(canvas, graphics, true, true, true, true, true, true); Pen pen = new Pen(borderColour); graphics.DrawString(SpacerTxt, sml, annoText, SpacerBounds, GH_TextRenderingConstants.CenterCenter); graphics.DrawLine(pen, SpacerBounds.X, SpacerBounds.Y + SpacerBounds.Height / 2, SpacerBounds.X + (SpacerBounds.Width - GH_FontServer.StringWidth(SpacerTxt, sml)) / 2 - 4, SpacerBounds.Y + SpacerBounds.Height / 2); graphics.DrawLine(pen, SpacerBounds.X + (SpacerBounds.Width - GH_FontServer.StringWidth(SpacerTxt, sml)) / 2 + GH_FontServer.StringWidth(SpacerTxt, sml) + 4, SpacerBounds.Y + SpacerBounds.Height / 2, SpacerBounds.X + SpacerBounds.Width, SpacerBounds.Y + SpacerBounds.Height / 2); graphics.DrawString("x", font, annoText, xTxtBounds, GH_TextRenderingConstants.CenterCenter); ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(xBounds.X + xBounds.Width / 2, xBounds.Y + xBounds.Height / 2), x, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s); graphics.DrawString("y", font, annoText, yTxtBounds, GH_TextRenderingConstants.CenterCenter); ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(yBounds.X + yBounds.Width / 2, yBounds.Y + yBounds.Height / 2), y, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s); graphics.DrawString("z", font, annoText, zTxtBounds, GH_TextRenderingConstants.CenterCenter); ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(zBounds.X + zBounds.Width / 2, zBounds.Y + zBounds.Height / 2), z, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s); graphics.DrawString("xx", font, annoText, xxTxtBounds, GH_TextRenderingConstants.CenterCenter); ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(xxBounds.X + xxBounds.Width / 2, xxBounds.Y + xxBounds.Height / 2), xx, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s); graphics.DrawString("yy", font, annoText, yyTxtBounds, GH_TextRenderingConstants.CenterCenter); ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(yyBounds.X + yyBounds.Width / 2, yyBounds.Y + yyBounds.Height / 2), yy, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s); graphics.DrawString("zz", font, annoText, zzTxtBounds, GH_TextRenderingConstants.CenterCenter); ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(zzBounds.X + zzBounds.Width / 2, zzBounds.Y + zzBounds.Height / 2), zz, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s); } }
protected override void Layout() { switch (this.Owner.ListMode) { case GH_ValueListMode.CheckList: this.LayoutCheckList(); break; case GH_ValueListMode.DropDown: this.LayoutDropDown(); break; } this.ItemBounds = this.Bounds; RectangleF bounds = this.Bounds; RectangleF bounds2 = new RectangleF(bounds.X, this.Bounds.Y, 0f, this.Bounds.Height); this.NameBounds = bounds2; if (this.Owner.DisplayName != null) { int nameWidth = GH_FontServer.StringWidth(this.Owner.DisplayName, GH_FontServer.Standard) + 10; bounds2 = this.Bounds; bounds = new RectangleF(bounds2.X - (float)nameWidth, this.Bounds.Y, (float)nameWidth, this.Bounds.Height); this.NameBounds = bounds; this.Bounds = RectangleF.Union(this.NameBounds, this.ItemBounds); } }
public StackPanel(string name, Orientation orientation, bool drawBorder, params GHControl[] items) : base(name, "") { _orientation = orientation; Items = items; _titleHeight = GH_FontServer.MeasureString(Name, SmallFont).Height + Offset * 2; _showBorder = drawBorder; }
protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel) { base.Render(canvas, graphics, channel); if (channel == GH_CanvasChannel.Objects) { GH_Capsule buttonCapsule = GH_Capsule.CreateTextCapsule(buttonRectangle, buttonRectangle, GH_Palette.Grey, ButtonText); buttonCapsule.Render(graphics, Selected, attributeOwner.Locked, false); buttonCapsule.Dispose(); StringFormat format = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter }; if (GH_FontServer.StringWidth(TextLine.Long, this.TextFont) < Bounds.Width) { graphics.DrawString(TextLine.Long, TextFont, Brushes.Black, textRectangle, format); } else { graphics.DrawString(TextLine.Short, TextFont, Brushes.Black, textRectangle, format); } format.Dispose(); } }
protected override void Render(GH_Canvas canvas, System.Drawing.Graphics graphics, GH_CanvasChannel channel) { // Draw base component. base.Render(canvas, graphics, channel); // Add custom elements. if (channel == GH_CanvasChannel.Objects) { // Add button to connect/disconect. GH_Capsule button = GH_Capsule.CreateTextCapsule(this.BoundsButton, this.BoundsButton, GH_Palette.Black, this.component.status ? "Disconnect" : "Connect", 2, 0); button.Render(graphics, this.Selected, this.Owner.Locked, false); button.Dispose(); // Add list of Found Devices. // IPAddress ipv4Addresse = Array.FindLast(Dns.GetHostEntry(string.Empty).AddressList, // a => a.AddressFamily == AddressFamily.InterNetwork); string message = "Devices: "; if (HoloConnect.deviceFinder.devices.Count > 0) { foreach (HoloDevice device in HoloConnect.deviceFinder.devices.Values) { message += "\n" + device.ToString(); } } else { message += "(not found)"; } graphics.DrawString(message, GH_FontServer.NewFont(FontFamily.GenericMonospace, 6, FontStyle.Regular), Brushes.Black, this.BoundsText, GH_TextRenderingConstants.CenterCenter); } }
// this function gets the coordinates from the probabilities, (same as getPts) but draws a HISTOGRAM shape an irregular polygon from points private PointF[] getHistoPts(List <double> Probabilities) { int n = (Probabilities.Count * 2) + 2; PointF[] points = new PointF[n]; int width_nickname = GH_FontServer.StringWidth(Owner.NickName, GH_FontServer.Standard); points[0] = new PointF(this.Pivot.X + width_nickname, this.Pivot.Y - 7); points[1] = new PointF(this.Pivot.X + (Bounds.Width) - 11, this.Pivot.Y - 7); if (Probabilities.Count != 0) { int count = 0; // routine to get drawing coordinates based on bin probabilities for (int i = 0; i < Probabilities.Count; i++) { float rail_width = (int)(points[1].X - points[0].X); float bin_width = rail_width / Probabilities.Count; float t = (Probabilities.Count - i) / Probabilities.Count; points[count + 2] = new PointF((float)((this.Pivot.X + width_nickname) + (bin_width * (Probabilities.Count - i))), this.Pivot.Y - 7 - (glob.max_ht * (float)Probabilities[Probabilities.Count - i - 1])); points[count + 2 + 1] = new PointF((float)((this.Pivot.X + width_nickname) + (bin_width * (Probabilities.Count - i - 1))), this.Pivot.Y - 7 - (glob.max_ht * (float)Probabilities[Probabilities.Count - i - 1])); count += 2; } } return(points); }
// Rui // Calculate the background bays for the graph based on Probabilities // return a list of equal size rectangles as background for the render private RectangleF[] getBackgroundBins(List <double> Probabilities) { int n = Probabilities.Count; RectangleF[] backgroundBins = new RectangleF[n]; PointF[] points = new PointF[n]; int width_nickname = GH_FontServer.StringWidth(Owner.NickName, GH_FontServer.Standard); points[0] = new PointF(this.Pivot.X + width_nickname, this.Pivot.Y - 7); points[1] = new PointF(this.Pivot.X + (Bounds.Width) - 11, this.Pivot.Y - 7); if (Probabilities.Count != 0) { for (int i = 0; i < Probabilities.Count; i++) { float rail_width = (int)(points[1].X - points[0].X); float bin_width = rail_width / Probabilities.Count; backgroundBins[i] = new System.Drawing.RectangleF( (float)((this.Pivot.X + width_nickname) + (bin_width * (Probabilities.Count - i - 1))), (float)(this.Pivot.Y - 7 - glob.max_ht), (float)bin_width, (float)(glob.max_ht)); } } return(backgroundBins); }
protected override void Render(GH_Canvas canvas, System.Drawing.Graphics graphics, GH_CanvasChannel channel) { base.Render(canvas, graphics, channel); if (channel == GH_CanvasChannel.Objects) { Pen spacer = new Pen(UI.Colour.SpacerColour); Pen pen = new Pen(UI.Colour.BorderColour) { Width = 0.5f }; //Draw divider line if (SpacerTxt != "") { graphics.DrawString(SpacerTxt, GH_FontServer.Small, UI.Colour.AnnotationTextDark, SpacerBounds, GH_TextRenderingConstants.CenterCenter); graphics.DrawLine(spacer, SpacerBounds.X, SpacerBounds.Y + SpacerBounds.Height / 2, SpacerBounds.X + (SpacerBounds.Width - GH_FontServer.StringWidth(SpacerTxt, GH_FontServer.Small)) / 2 - 4, SpacerBounds.Y + SpacerBounds.Height / 2); graphics.DrawLine(spacer, SpacerBounds.X + (SpacerBounds.Width - GH_FontServer.StringWidth(SpacerTxt, GH_FontServer.Small)) / 2 + GH_FontServer.StringWidth(SpacerTxt, GH_FontServer.Small) + 4, SpacerBounds.Y + SpacerBounds.Height / 2, SpacerBounds.X + SpacerBounds.Width, SpacerBounds.Y + SpacerBounds.Height / 2); } // Draw button box graphics.FillRectangle(UI.Colour.ButtonColor, ButtonBounds); graphics.DrawRectangle(pen, ButtonBounds.X, ButtonBounds.Y, ButtonBounds.Width, ButtonBounds.Height); graphics.DrawString(buttonText, GH_FontServer.Standard, UI.Colour.AnnotationTextBright, ButtonBounds, GH_TextRenderingConstants.CenterCenter); } }
/*******************************************/ /**** Private Methods ****/ /*******************************************/ private void RenderMessage(Graphics graphics, string message) { Color fill, text, edge; this.MessageLabelColours(out fill, out text, out edge); int zoomFadeMedium = GH_Canvas.ZoomFadeMedium; if (zoomFadeMedium > 5) { Rectangle box = new Rectangle((int)Bounds.X, (int)Bounds.Y, (int)Bounds.Width, (int)Bounds.Height); box.Inflate(-3, 0); box.Y = box.Bottom; Font font = GH_FontServer.Standard; bool flag = false; Size size = GH_FontServer.MeasureString(message, font); size.Width += 8; if (size.Width > box.Width) { double num = (double)box.Width / (double)size.Width; font = GH_FontServer.NewFont(font, Convert.ToSingle((double)font.SizeInPoints * num)); size = GH_FontServer.MeasureString(message, font); flag = true; } box.Height = Math.Max(size.Height, 6); GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddArc(box.Left - 3, box.Top, 6, 6, 270f, 90f); graphicsPath.AddArc(box.Left + 3, box.Bottom - 6, 6, 6, 180f, -90f); graphicsPath.AddArc(box.Right - 9, box.Bottom - 6, 6, 6, 90f, -90f); graphicsPath.AddArc(box.Right - 3, box.Top, 6, 6, 180f, 90f); graphicsPath.CloseAllFigures(); SolidBrush solidBrush = new SolidBrush(Color.FromArgb(zoomFadeMedium, fill)); Pen pen = new Pen(Color.FromArgb(zoomFadeMedium, edge)) { LineJoin = LineJoin.Bevel }; graphics.FillPath(solidBrush, graphicsPath); graphics.DrawPath(pen, graphicsPath); pen.Dispose(); solidBrush.Dispose(); graphicsPath.Dispose(); if (graphics.Transform.Elements[0].Equals(1f)) { graphics.TextRenderingHint = GH_TextRenderingConstants.GH_CrispText; } else { graphics.TextRenderingHint = GH_TextRenderingConstants.GH_SmoothText; } SolidBrush solidBrush2 = new SolidBrush(Color.FromArgb(zoomFadeMedium, text)); graphics.DrawString(message, font, solidBrush2, box, GH_TextRenderingConstants.CenterCenter); solidBrush2.Dispose(); if (flag) { font.Dispose(); } } }
protected static PointF DrawTimeLine(Graphics graphics, float PtXStart, float PtY) { float Width = Frame.Component.SliderWidth - 20; float PtXend = PtXStart + Width; //draw basic line graphics.DrawLine(new Pen(ShareData.SecondaryColor, ShareData.middleThick), new PointF(PtXStart, PtY), new PointF(PtXend, PtY)); int count = (int)(Width / 25f); float step = (float)Width / (float)count; if (Frame.Component.KeyTimes == null) { return(new PointF()); } else if (Frame.Component.KeyTimes.Count == 0) { return(new PointF()); } float startTime = (float)Frame.Component.KeyTimes[0]; float timeStep = ((float)Frame.Component.MaxTime - (float)Frame.Component.FrameTimeLast) / (float)count; //draw keytime for (int n = 0; n <= count; n++) { PointF loc = new PointF(PtXStart + n * step, PtY); PointF textLoc = new PointF(loc.X - 8, loc.Y + 2); string tmStr = (startTime + n * timeStep).ToString("f1"); graphics.DrawString(tmStr, GH_FontServer.NewFont(GH_FontServer.Script, 5, FontStyle.Regular), new SolidBrush(ShareData.SecondaryColor), textLoc); PointF keyPt = new PointF(loc.X - ShareData.KeyTimeRadius / 2, loc.Y - ShareData.KeyTimeRadius / 2); try { graphics.DrawEllipse(new Pen(ShareData.SecondaryColor, ShareData.KeyTimeRadius), keyPt.X, keyPt.Y, ShareData.KeyTimeRadius, ShareData.KeyTimeRadius); } catch { } } graphics.DrawString("s", GH_FontServer.NewFont(GH_FontServer.Script, 5, FontStyle.Regular), new SolidBrush(ShareData.SecondaryColor), new PointF(PtXend + 5, PtY + 2)); //draw right time string txtT = Frame.Component.RightTime.ToString("f2") + "s"; PointF Cloc = new PointF((float)((Frame.Component.RightTime - Frame.Component.KeyTimes[0]) / (Frame.Component.MaxTime - Frame.Component.FrameTimeLast)) * Width + PtXStart, PtY); PointF Ptloc = new PointF(Cloc.X - ShareData.KeyPtRadius / 2, Cloc.Y - ShareData.KeyPtRadius / 2); graphics.DrawEllipse(new Pen(ShareData.HighLightColor, ShareData.KeyPtRadius), Ptloc.X, Ptloc.Y, ShareData.KeyPtRadius, ShareData.KeyPtRadius); PointF txtLoc = new PointF(Cloc.X - 12, Cloc.Y + 5); graphics.DrawString(txtT, GH_FontServer.NewFont(GH_FontServer.Script, 7, FontStyle.Bold), new SolidBrush(ShareData.HighLightColor), txtLoc); return(Cloc); }
public TabPanel(string name, string description, int activeTab, bool showTitle, bool showHeaderText = true, Bitmap toolTipDiagram = null) : base(name, description, activeTab, toolTipDiagram) { _tabs = new Dictionary <string, GHControl[]>(); _icons = new Dictionary <string, Image>(); _values = new List <int>(); _showTitle = showTitle; _showHeaderText = showHeaderText; _titleHeight = GH_FontServer.MeasureString(Name, SmallFont).Height + Offset; }
protected override void Layout() { int FontWidth = GH_FontServer.StringWidth(Owner.NickName, GH_FontServer.Standard); //10 is meanless float ComponentWidth = FontWidth + 2 * Setting.DROPDOWNCOMPONENTPARAMHEIGHT + Setting.DROPDOWNTRIANGLEHEIGHT + 10; SizeF BoundsSize = new SizeF(ComponentWidth, Setting.DROPDOWNCOMPONENTHEIGHT); this.Owner.Attributes.Bounds = new RectangleF(Pivot, BoundsSize); base.AttributeUtil.ComputeFixPramGridBounds(Setting.DROPDOWNCOMPONENTPARAMHEIGHT); }
protected override void Render(GH_Canvas canvas, System.Drawing.Graphics graphics, GH_CanvasChannel channel) { base.Render(canvas, graphics, channel); if (channel == GH_CanvasChannel.Objects) { Pen spacer = new Pen(UI.Colour.SpacerColour); Pen pen = new Pen(UI.Colour.GsaDarkBlue); if (displayText == initialTxt) { pen = new Pen(UI.Colour.BorderColour); } pen.Width = 0.5f; //Draw divider line if (SpacerTxt != "") { graphics.DrawString(SpacerTxt, GH_FontServer.Small, UI.Colour.AnnotationTextDark, SpacerBounds, GH_TextRenderingConstants.CenterCenter); graphics.DrawLine(spacer, SpacerBounds.X, SpacerBounds.Y + SpacerBounds.Height / 2, SpacerBounds.X + (SpacerBounds.Width - GH_FontServer.StringWidth(SpacerTxt, GH_FontServer.Small)) / 2 - 4, SpacerBounds.Y + SpacerBounds.Height / 2); graphics.DrawLine(spacer, SpacerBounds.X + (SpacerBounds.Width - GH_FontServer.StringWidth(SpacerTxt, GH_FontServer.Small)) / 2 + GH_FontServer.StringWidth(SpacerTxt, GH_FontServer.Small) + 4, SpacerBounds.Y + SpacerBounds.Height / 2, SpacerBounds.X + SpacerBounds.Width, SpacerBounds.Y + SpacerBounds.Height / 2); } // Draw selected item Font font = new Font(GH_FontServer.FamilyStandard, 7); Brush fontColour = UI.Colour.AnnotationTextDark; // background Brush background = new SolidBrush(UI.Colour.GsaLightGrey); graphics.FillRectangle(background, BorderBound); // background // border graphics.DrawRectangle(pen, BorderBound.X, BorderBound.Y, BorderBound.Width, BorderBound.Height); // text graphics.DrawString(displayText, (displayText == initialTxt) ? GH_FontServer.Small : font, (displayText == initialTxt) ? Brushes.Gray : fontColour, TextBound, GH_TextRenderingConstants.NearCenter); // draw dropdown arrow ButtonsUI.DropDownArrow.DrawDropDownButton(graphics, new PointF(ButtonBound.X + ButtonBound.Width / 2, ButtonBound.Y + ButtonBound.Height / 2), UI.Colour.GsaDarkBlue, 15); // draw dropdown list if (unfolded) { Pen penborder = new Pen(Brushes.Gray); Brush dropdownbackground = new SolidBrush(UI.Colour.GsaLightGrey); penborder.Width = 0.3f; for (int i = 0; i < dropdownlist.Count; i++) { // background graphics.FillRectangle(dropdownbackground, dropdownBounds[i]); // border graphics.DrawRectangle(penborder, dropdownBounds[i].X, dropdownBounds[i].Y, dropdownBounds[i].Width, dropdownBounds[i].Height); // text graphics.DrawString(dropdownlist[i], font, fontColour, dropdownBounds[i], GH_TextRenderingConstants.NearCenter); } // border graphics.DrawRectangle(pen, dropdownBound.X, dropdownBound.Y, dropdownBound.Width, dropdownBound.Height); } } }
private int ItemMaximumWidth() { int val1 = 20; foreach (GH_ValueListItem listItem in Owner.ListItems) { int val2 = GH_FontServer.StringWidth(listItem.Name, GH_FontServer.Standard); val1 = Math.Max(val1, val2); } return(val1 + 10); }
private int ItemMaximumWidth() { int num2 = 20; foreach (GuanacoListItem item in this.Owner.ListItems) { int num3 = GH_FontServer.StringWidth(item.Name, GH_FontServer.Standard); num2 = Math.Max(num2, num3); } return(num2 + 10); }
protected override void Layout() { //Fixed the Component Size; int FontWidth = GH_FontServer.StringWidth(Owner.NickName, GH_FontServer.Standard); //10 is meanless float ComponentWidth = FontWidth + 2 * ParamWidth + TriangleSize + 10; SizeF BoundsSize = new SizeF(ComponentWidth, Setting.DROPDOWNCOMPONENTHEIGHT); //Pivot非常的重要 this.Owner.Attributes.Bounds = new RectangleF(Pivot, BoundsSize); this.ComputeParamGridBounds(); }
private Transform CalculateTextPlane() { string Text = this.TextObj.Text; System.Drawing.Font _Font = new System.Drawing.Font(this.TextObj.Font.FaceName, Convert.ToSingle(this.TextObj.TextHeight)); int Width = GH_FontServer.StringWidth(Text, _Font); int Height = _Font.Height; Plane originPlane = this.TextObj.Plane; Transform H_Tran = new Transform(), V_Tran = new Transform(); Vector3d H_Vector, V_Vector; switch (this.TextObj.TextHorizontalAlignment) { case TextHorizontalAlignment.Center: H_Vector = originPlane.XAxis * Width * (-0.5); break; case TextHorizontalAlignment.Left: H_Vector = originPlane.XAxis; break; case TextHorizontalAlignment.Right: H_Vector = originPlane.XAxis * Width * (-1); break; default: H_Vector = originPlane.XAxis; break; } switch (this.TextObj.TextVerticalAlignment) { case TextVerticalAlignment.Bottom: V_Vector = originPlane.YAxis; break; case TextVerticalAlignment.Middle: V_Vector = originPlane.YAxis * Height * 0.5; break; case TextVerticalAlignment.Top: V_Vector = originPlane.YAxis * Height * 1; break; default: V_Vector = originPlane.YAxis; break; } H_Tran = Transform.Translation(H_Vector); V_Tran = Transform.Translation(V_Vector); return(Transform.Multiply(H_Tran, V_Tran)); }
protected override void Render(GH_Canvas canvas, System.Drawing.Graphics graphics, GH_CanvasChannel channel) { base.Render(canvas, graphics, channel); if (channel == GH_CanvasChannel.Objects) { Pen spacer = new Pen(ButtonColours.SpacerColour); Font font = GH_FontServer.Standard; // adjust fontsize to high resolution displays font = new Font(font.FontFamily, font.Size / GH_GraphicsUtil.UiScale, FontStyle.Regular); Font sml = GH_FontServer.Small; // adjust fontsize to high resolution displays sml = new Font(sml.FontFamily, sml.Size / GH_GraphicsUtil.UiScale, FontStyle.Regular); //Draw divider line if (SpacerTxt != "") { graphics.DrawString(SpacerTxt, sml, ButtonColours.AnnotationTextDark, SpacerBounds, GH_TextRenderingConstants.CenterCenter); graphics.DrawLine(spacer, SpacerBounds.X, SpacerBounds.Y + SpacerBounds.Height / 2, SpacerBounds.X + (SpacerBounds.Width - GH_FontServer.StringWidth(SpacerTxt, sml)) / 2 - 4, SpacerBounds.Y + SpacerBounds.Height / 2); graphics.DrawLine(spacer, SpacerBounds.X + (SpacerBounds.Width - GH_FontServer.StringWidth(SpacerTxt, sml)) / 2 + GH_FontServer.StringWidth(SpacerTxt, sml) + 4, SpacerBounds.Y + SpacerBounds.Height / 2, SpacerBounds.X + SpacerBounds.Width, SpacerBounds.Y + SpacerBounds.Height / 2); } // Draw button box System.Drawing.Drawing2D.GraphicsPath button = RoundedRect(ButtonBounds, 2); Brush normal_colour = ButtonColours.ButtonColor; Brush hover_colour = ButtonColours.HoverButtonColour; Brush clicked_colour = ButtonColours.ClickedButtonColour; Brush butCol = (mouseOver) ? hover_colour : normal_colour; graphics.FillPath(mouseDown ? clicked_colour : butCol, button); // draw button edge Color edgeColor = ButtonColours.BorderColour; Color edgeHover = ButtonColours.HoverBorderColour; Color edgeClick = ButtonColours.ClickedBorderColour; Color edgeCol = (mouseOver) ? edgeHover : edgeColor; Pen pen = new Pen(mouseDown ? edgeClick : edgeCol) { Width = (mouseDown) ? 0.8f : 0.5f }; graphics.DrawPath(pen, button); System.Drawing.Drawing2D.GraphicsPath overlay = RoundedRect(ButtonBounds, 2, true); graphics.FillPath(new SolidBrush(Color.FromArgb(mouseDown ? 0 : mouseOver ? 40 : 60, 255, 255, 255)), overlay); // draw button text graphics.DrawString(buttonText, font, ButtonColours.AnnotationTextBright, ButtonBounds, GH_TextRenderingConstants.CenterCenter); } }
protected HorizontalSlider(string name, string description, object value, float min, float max, bool showTitle, string formatString, string suffix, Bitmap toolTipDiagram = null) : base(name, description, value, toolTipDiagram) { _format = new StringFormat(); _format.Alignment = StringAlignment.Near; _format.LineAlignment = StringAlignment.Near; _format.Trimming = StringTrimming.EllipsisCharacter; _min = min; _max = max; FormatString = formatString; Suffix = suffix; _showTitle = showTitle; _fontSize = GH_FontServer.MeasureString(Name, StandardFont).Height; }
protected override void Layout() { switch (Owner.ListMode) { case GH_ValueListMode.CheckList: LayoutCheckList(); break; case GH_ValueListMode.DropDown: LayoutDropDown(); break; default: LayoutSequence(); break; } ItemBounds = Bounds; RectangleF bounds1 = Bounds; //RectangleF rectangleF; RectangleF local1; double x = (double)bounds1.X; RectangleF bounds2 = Bounds; double y1 = (double)bounds2.Y; bounds2 = Bounds; double height1 = (double)bounds2.Height; local1 = new RectangleF((float)x, (float)y1, 0.0f, (float)height1); NameBounds = local1; if (Owner.DisplayName == null) { return; } int num1 = GH_FontServer.StringWidth(Owner.DisplayName, GH_FontServer.Standard) + 10; RectangleF bounds3 = Bounds; RectangleF local2; double num2 = (double)bounds3.X - (double)num1; bounds2 = Bounds; double y2 = (double)bounds2.Y; double num3 = (double)num1; bounds2 = Bounds; double height2 = (double)bounds2.Height; local2 = new RectangleF((float)num2, (float)y2, (float)num3, (float)height2); NameBounds = bounds1; Bounds = RectangleF.Union(NameBounds, ItemBounds); }
public RectangleF LayoutComponentBox2(IGH_Component owner) { GH_SwitcherComponent gH_SwitcherComponent = (GH_SwitcherComponent)owner; int val = Math.Max(gH_SwitcherComponent.StaticData.GetComponentInputSection().Count, gH_SwitcherComponent.StaticData.GetComponentOutputSection().Count) * 20; val = Math.Max(val, 24); int num = 24; if (!GH_Attributes <IGH_Component> .IsIconMode(owner.IconDisplayMode)) { val = Math.Max(val, GH_Convert.ToSize((SizeF)GH_FontServer.MeasureString(owner.NickName, StandardFont.largeFont())).Width + 6); } return(GH_Convert.ToRectangle(new RectangleF(owner.Attributes.Pivot.X - 0.5f * (float)num, owner.Attributes.Pivot.Y - 0.5f * (float)val, num, val))); }
protected override void Layout() { Pivot = GH_Convert.ToPoint(Pivot); Size size = new Size(150, 18); size.Width = Math.Max(size.Width, GH_FontServer.StringWidth(base.Owner.NickName, GH_FontServer.StandardAdjusted) + 20); int num = Convert.ToInt32((double)Pivot.X - 0.5 * (double)size.Width); int num2 = Convert.ToInt32((double)Pivot.X + 0.5 * (double)size.Width); int num3 = Convert.ToInt32((double)Pivot.Y - 0.5 * (double)size.Height); int num4 = Convert.ToInt32((double)Pivot.Y + 0.5 * (double)size.Height); Bounds = RectangleF.FromLTRB(num, num3, num2, num4); TextBound = RectangleF.FromLTRB(num + 30, num3, num2, num4); m_button = new RectangleF(Bounds.Left, Bounds.Top, 30, Bounds.Height); }
protected override void Layout() { // Compute the width of the NickName of the owner (plus some extra padding), // then make sure we have at least 80 pixels. int width = GH_FontServer.StringWidth(Owner.NickName, GH_FontServer.Standard); width = Math.Max(width + 10, 80); // The height of our object is always 60 pixels int height = 60; // Assign the width and height to the Bounds property. // Also, make sure the Bounds are anchored to the Pivot Bounds = new RectangleF(Pivot, new SizeF(width, height)); }
protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel) { base.Render(canvas, graphics, channel); if (channel == GH_CanvasChannel.Objects) { var prototype = GH_FontServer.StandardAdjusted; var font = GH_FontServer.NewFont(prototype, 6f / GH_GraphicsUtil.UiScale); var radius = 3; var highlight = !_mouseDown ? 8 : 0; using var button = GH_Capsule.CreateTextCapsule(_buttonBounds, _buttonBounds, GH_Palette.Black, _label, font, radius, highlight); button.Render(graphics, false, Owner.Locked, false); } }
public static float MaxTextWidth(List <string> spacerTxts, Font font) { float sp = new float(); //width of spacer text // adjust fontsize to high resolution displays font = new Font(font.FontFamily, font.Size / GH_GraphicsUtil.UiScale, FontStyle.Regular); for (int i = 0; i < spacerTxts.Count; i++) { if (GH_FontServer.StringWidth(spacerTxts[i], font) + 8 > sp) { sp = GH_FontServer.StringWidth(spacerTxts[i], font) + 8; } } return(sp); }
public override void Render(GH_Canvas canvas) { var document = canvas.Document; if (document == null) { return; } var zoomFadeMedium = GH_Canvas.ZoomFadeMedium; if (zoomFadeMedium == 0) { return; } var historyComponent = document.Objects.SingleOrDefault(x => x is UserHistoryComponent) as UserHistoryComponent; if (historyComponent == null) { return; } var solidBrush = new SolidBrush(Color.FromArgb(zoomFadeMedium, Color.Black)); foreach (var ghDocumentObject in document.Objects) { if (ghDocumentObject is IGH_ActiveObject) { var historyRecord = historyComponent.GetHistory(ghDocumentObject.ComponentGuid); if (historyRecord == null) { continue; } var bounds = ghDocumentObject.Attributes.Bounds; if (canvas.Viewport.IsVisible(ref bounds, 10f)) { var str = $"{historyRecord.UserName}: {historyRecord.DateTime:dd.MM.yy HH:mm}"; var sizeF = (SizeF)GH_FontServer.MeasureString(str, GH_FontServer.ConsoleSmall); var rectangleF = bounds; rectangleF.Height = sizeF.Height + 2f; rectangleF.Width = sizeF.Width + 2f; rectangleF.X = (float)(0.5 * ((double)bounds.Left + (double)bounds.Right) - 0.5 * (double)rectangleF.Width); rectangleF.Y = bounds.Top - 15f; canvas.Graphics.DrawString(str, GH_FontServer.ConsoleSmall, (Brush)solidBrush, rectangleF, GH_TextRenderingConstants.CenterCenter); } } } }
protected override void Render(GH_Canvas canvas, System.Drawing.Graphics graphics, GH_CanvasChannel channel) { base.Render(canvas, graphics, channel); if (channel == GH_CanvasChannel.Objects) { //Draw divider line if (SpacerTxt != "") { Pen spacer = new Pen(UI.Colour.SpacerColour); Font sml = GH_FontServer.Small; // adjust fontsize to high resolution displays sml = new Font(sml.FontFamily, sml.Size / GH_GraphicsUtil.UiScale, FontStyle.Regular); graphics.DrawString(SpacerTxt, sml, UI.Colour.AnnotationTextDark, SpacerBounds, GH_TextRenderingConstants.CenterCenter); graphics.DrawLine(spacer, SpacerBounds.X, SpacerBounds.Y + SpacerBounds.Height / 2, SpacerBounds.X + (SpacerBounds.Width - GH_FontServer.StringWidth(SpacerTxt, sml)) / 2 - 4, SpacerBounds.Y + SpacerBounds.Height / 2); graphics.DrawLine(spacer, SpacerBounds.X + (SpacerBounds.Width - GH_FontServer.StringWidth(SpacerTxt, sml)) / 2 + GH_FontServer.StringWidth(SpacerTxt, sml) + 4, SpacerBounds.Y + SpacerBounds.Height / 2, SpacerBounds.X + SpacerBounds.Width, SpacerBounds.Y + SpacerBounds.Height / 2); } // draw drag line and intervals Pen line = new Pen(UI.Colour.GsaDarkGrey); graphics.DrawLine(line, new PointF(SliderBound.X + GrabBound.Width / 2, SliderBound.Y + SliderBound.Height / 2), new PointF(SliderBound.X + SliderBound.Width - GrabBound.Width / 2, SliderBound.Y + SliderBound.Height / 2)); //graphics.DrawLine(line, new PointF(BorderBound.X + GrabBound.Width / 2, BorderBound.Y + BorderBound.Height / 3), new PointF(BorderBound.X + GrabBound.Width / 2, BorderBound.Y + BorderBound.Height * 2 / 3)); //graphics.DrawLine(line, new PointF(BorderBound.X + BorderBound.Width - GrabBound.Width / 2, BorderBound.Y + BorderBound.Height / 3), new PointF(BorderBound.X + BorderBound.Width - GrabBound.Width / 2, BorderBound.Y + BorderBound.Height * 2 / 3)); // draw grab item Pen pen = new Pen(UI.Colour.GsaDarkBlue); pen.Width = 2f; RectangleF button = new RectangleF(GrabBound.X, GrabBound.Y, GrabBound.Width, GrabBound.Height); button.Inflate(-2, -2); Brush fill = new SolidBrush(UI.Colour.GsaLightGrey); graphics.FillEllipse(fill, button); graphics.DrawEllipse(pen, button); // Draw display value text Font font = new Font(GH_FontServer.FamilyStandard, 7); // adjust fontsize to high resolution displays font = new Font(font.FontFamily, font.Size / GH_GraphicsUtil.UiScale, FontStyle.Regular); string val = string.Format(new System.Globalization.NumberFormatInfo() { NumberDecimalDigits = noDigits }, "{0:F}", new decimal(CurrentValue)); graphics.DrawString(val, font, UI.Colour.AnnotationTextDark, SliderValTextBound, ((CurrentValue - MinValue) / (MaxValue - MinValue) < 0.5) ? GH_TextRenderingConstants.NearCenter : GH_TextRenderingConstants.FarCenter); } }