i am learning doing custom attributes of component,i follow the tutorial : https://developer.rhino3d.com/guides/grasshopper/custom-attributes/
and the result is this:
the little half circle is missing!
can some people explain it?Thankyou!
this is my code:
using System;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Rhino.Geometry;
using Grasshopper.Kernel.Types;
using System.Drawing;
using Grasshopper.GUI.Canvas;
namespace FabUnionRobot
{
public class testParamAttributes : GH_Attributes<ParamTest>
{
int height;
public testParamAttributes(ParamTest owner) : base(owner) { }
protected override void Layout()
{
int width = GH_FontServer.StringWidth(Owner.NickName, GH_FontServer.Standard);
width = Math.Max(width + 30, 80);
height = 60;
Bounds = new RectangleF(Pivot, new SizeF(width, height));
}
public override void ExpireLayout()
{
base.ExpireLayout();
}
protected override void Render(Grasshopper.GUI.Canvas.GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
{
if (channel == GH_CanvasChannel.Wires)
{
RenderIncomingWires(canvas.Painter, Owner.Sources, Owner.WireDisplay);
return;
}
GH_Palette palette = GH_Palette.Normal;
if (channel == GH_CanvasChannel.Objects)
{
switch (Owner.RuntimeMessageLevel)
{
case GH_RuntimeMessageLevel.Warning:
palette = GH_Palette.Warning;
break;
case GH_RuntimeMessageLevel.Error:
palette = GH_Palette.Error;
break;
}
}
GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, palette);
capsule.Render(graphics, Selected, Owner.Locked, true);
capsule.Dispose();
capsule = null;
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
format.Trimming = StringTrimming.EllipsisCharacter;
RectangleF textRectangle = Bounds;
textRectangle.Height = 20;
textRectangle.Y = -textRectangle.Height / 2 + Pivot.Y + height / 2;
graphics.DrawString(Owner.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format);
}
}
public class ParamTest : GH_Param<GH_Integer>
{
public ParamTest()
: base(new GH_InstanceDescription("ParamTest", "pT",
"Description",
CommonValues.Catalog, CommonValues.subCatalogOthers))
{
}
public override void CreateAttributes()
{
m_attributes = new testParamAttributes(this);
}
protected override System.Drawing.Bitmap Icon
{
get
{
return null;
}
}
public override Guid ComponentGuid
{
get { return new Guid("42bc5dac-9eb5-459e-a2ee-2cfbff68eac3"); }
}
}
}