C# Hide profiler overlay for certain components


#21

Thanks @DavidRutten
Works perfectly.


#22

Hi @DavidRutten and @PaulBomke
I am using same topic but question is slightly different.
It seems that event RespondToMouseDown doesn’t fire if I click outside the boundary of the Custom Component (CC).
But basically I have a drop-down list extending behind CC’s bound.
How can I catch such mouse event?

Thanks,
Dmitriy


(David Rutten) #23

Technically it isn’t an event, but a method which is called when the canvas is handling the event. But no, if the click happens outside the attribute Bounds, you will not get called. The bounds really do need to contain all the pixels within which your object is drawing stuff and handling events.

Normally I’d say create correct Bounds and just use another Rectangle for creating the capsules, but if you’re deriving from GH_ComponentAttribute then the Bounds has additional meaning. I think you’ll have to set correct bounds on your attributes, and swap them with the capsule bounds before calling the base class Draw and Layout methods.

// pseudo template
class MyAttributes : SomePreexistingAttributes
{
  private RectangleF _actualBounds;
  private RectangleF _capsuleBounds;

  public override void Layout()
  {
    base.Layout();
    _capsuleBounds = Bounds;
    _actualBounds = Bounds + some extra space;
    Bounds = _actualBounds;
  }

  public override void Render(...)
  {
     Bounds = _capsuleBounds;
     base.Render(...);
     Bounds = _actualBounds;
  }
}

#24

@DavidRutten, it certainly works.
Thank you!


(Hellguz) #25

@PaulBomke

Hi Paul! This topic has really impressed me, currently I’m looking for a way how to include some elements like DropDown, InputText and ColorPicker into my component, and your example looks very nice. If it is possible, can you share the code please? I still can’t understand how to add elements except GH_Capsule.

Thanks in advance!


(Paul Bomke) #26

Hi @hellguz,
can’t share the code, sorry…
It all happens inside your components custom attributes. There’s a tutorial by David Rutten that explains the basics using a simple custom parameter. Start with a simple button. Override Layout to define it’s bounds (RectangleF) wrt your components bounds. Override Render to draw a box using the bounds. Override the RespondToMouseEvent methods to create mouse behaviour.

There is an example for a component with a button here, that should get you started!

Hope this helps…
Best,
Paul


(Hellguz) #27

Thanks for the explanation @PaulBomke !
But I still can’t get how to add more complex elements. Or do I have to construct them by myself? That’s the question :slight_smile: Now I know how to work with buttons, rectangles and simple text, hopefully I’ll be able to create a slider out of it, for instance.


(Paul Bomke) #28

All the elements are custom made.
E.g. to make a slider you need the following things:

  • Variables:
    • Slider bounds (calculated in Layout method)
    • Slider knob position relative (normalized between 0 and 1 makes sense)
    • Slider knob position absolute
    • Slider sliding flag
  • In Layout:
    • Keep track of your slider bounds so the slider moves with the component if you drag the component over the canvas
    • Keep track of your knob position wrt the slider bounds so the knob moves with the slider. This is where you use the relative slider position and from that calculate the absolute knob position in canvas coordinates
  • Render
    • Render the slider rail or whatever that line is called where the knob slides on
    • Render the knob. If you need fancyness, render the knob different if sliding mode flag is set…
  • Handle LMB down event
    • check if mouse hit the slider knob
    • if it did, set a flag so you are in sliding mode
    • Return mouse event handled flag so you won’t drag the component
  • Handle mouse move event
    • check if sliding mode flag is set
    • if yes, set slider knob position to mouse position so the knob follows the cursor
    • check if knob moves out of your slider bounds. If it does, limit its position to the bounds so you cannot drag the knob out of the slider
  • Handle LMB release event
    • Unset the sliding mode flag

I guess that a slider is one of the more complex things but if you break it down into individual parts like above you should be all right :slight_smile:
Hope that get’s you started…


(Hellguz) #29

Thanks for such a detailed answer! It’s right what I needed


#30

Hey Paul,
A good thread here :slight_smile:

Have done a similar thing…
This widget crossed also my way, but I just avoided the dropdown.
Thanks for the digging :wink:

anyway :thinking:

I have seen there are some problems with the scaling of text on bigger screens / HighRes-Screen. Which I can not solve - Dont own such a screen… a bit hard to guess whats going on…
:persevere:

Have u noticed such a thing? U have any advices?

greets
Mark


(Paul Bomke) #31

Also noticed this but got around it by using the fonts ending with adjusted from the GH font server. Unfortunately not all of the available fonts have an adjusted variant.


#32

Ok,
thanks for the advice.
I shortly tried ur suggestion but it looks like there is not such a thing in “GH_FontServer”…
Are u building against Rhino6?
Looks like in Rhino5 there is not such a thing…

Maybe I should switch to 6…

https://developer.rhino3d.com/api/grasshopper/html/T_Grasshopper_Kernel_GH_FontServer.htm


(David Rutten) #33

Gh on rhino5 was not screen scale aware, you need to work on GH for Rhino6 to get those fixes.