It seems that by returning “GH_ObjectResponse.Capture” as the return value of the RespondToMouse method of GH_ComponentAttributes, the component enters the “Capture” state. Is it possible to intentionally switch the Capture/Release state of a component other than returning “Capture” as the return value of the RespondTo~ method?
The specific situation I would like to use is to expand and switch component drop-down menus, as shown in the figure below. We would like to make the component in “Capture” state so that mouse events of the currently expanded component will take precedence even if other components or menus overlap. However, it is necessary to “Release” at the timing when the component switches to unselected state.
The process of closing the menu when switching to the unselected state is implemented by overriding the Selected property of GH_ComponentAttributes as shown below.
private bool m_selected;
public override bool Selected
{
get { return m_selected; }
set {
if (m_selected != value && m_selected) OnDeselected();
m_selected = value;
}
}
public void OnDeselected()
{
// 1. Close Menu !
// 2. Release Component !
}
I may not have done enough research, as I did not end up using the questions I asked in my implementation, but it seems that the state in which a component is Captured is actually related to whether the component is registered in the corresponding GH_Canvas.ActiveObject property or not. This property is normally null and can be assigned to, so it is possible to check the Captured state and change it freely.
As an example, the following implementation allows switching the Capture/Release state from the context menu of the component, instead of using the RespondTo~ method. (The RespondToMouseDown() method is implemented to check the Capture state by checking whether a click outside the Component’s region is picked up.)