/.cs
Created
January 29, 2021 14:14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Attributes_Custom : Grasshopper.Kernel.Attributes.GH_ComponentAttributes { | |
//public bool userClick0 =false; | |
public Attributes_Custom(GH_Component owner) : base(owner) { } | |
protected override void Layout() { | |
base.Layout(); | |
System.Drawing.Rectangle rec0 = GH_Convert.ToRectangle(Bounds); | |
rec0.Height += 22; | |
System.Drawing.Rectangle rec1 = rec0; | |
rec1.Y = rec1.Bottom - 22; | |
rec1.Height = 22; | |
rec1.Inflate(-2, -2); | |
Bounds = rec0; | |
ButtonBounds = rec1; | |
} | |
private System.Drawing.Rectangle ButtonBounds { get; set; } | |
protected override void Render(GH_Canvas canvas, System.Drawing.Graphics graphics, GH_CanvasChannel channel) { | |
SolverGH baseClass = Owner as SolverGH; | |
base.Render(canvas, graphics, channel); | |
if (channel == GH_CanvasChannel.Objects) { | |
var color = baseClass.userClick0 ? GH_Palette.White : GH_Palette.White; | |
GH_Capsule button = GH_Capsule.CreateTextCapsule(ButtonBounds, ButtonBounds, color, baseClass.userClick0.ToString(), 2, 0); | |
button.Render(graphics, Selected, Owner.Locked, false); | |
button.Dispose(); | |
} | |
} | |
public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, GH_CanvasMouseEvent e) { | |
SolverGH baseClass = Owner as SolverGH; | |
if (e.Button == System.Windows.Forms.MouseButtons.Left) { | |
System.Drawing.RectangleF rec = ButtonBounds; | |
if (rec.Contains(e.CanvasLocation)) { | |
baseClass.userClick0 = !baseClass.userClick0; | |
//MessageBox.Show("The button was clicked", "Button", MessageBoxButtons.OK); | |
baseClass.ExpireSolution(true); | |
return GH_ObjectResponse.Handled; | |
} | |
} | |
return base.RespondToMouseDown(sender, e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment