Question: How to get control under mouse pointer?
by Kevin Rogers · in Torque 3D Professional · 09/09/2014 (11:31 am) · 3 replies
When dragging around a control (e.g. GuiWindowCtrl), I would like to know what the underlying control is. Seems like there should already be a way to do this (looks like the Gui Editor can do it), but I'm not seeing it. Anyone know what the method would be or where to look for it?
Thanks!
Thanks!
#2
Also, it looks like we have findHitControls() which appears to return all controls within the specified rectangle. Does anyone use this method? Can you tell me more about how you use it?
09/09/2014 (11:51 am)
Incidentally, findHitControl() is a member of GuiControl. Also, it looks like we have findHitControls() which appears to return all controls within the specified rectangle. Does anyone use this method? Can you tell me more about how you use it?
#3
I prefer to use the drag and drop stuff for this sort of thing - and there is direct support in GuiControl for getting info back -
09/09/2014 (12:17 pm)
https://github.com/RichardRanft/Torque2D/tree/inventory - though it would need some work to get it functioning correctly in T3D....I prefer to use the drag and drop stuff for this sort of thing - and there is direct support in GuiControl for getting info back -
// drag enter and exit callbacks IMPLEMENT_CALLBACK( GuiControl, onControlDragEnter, void, ( GuiControl* control, const Point2I& dropPoint ), ( control, dropPoint ), "Called when a drag&drop operation through GuiDragAndDropControl has entered the control. This is only called for " "topmost visible controls as the GuiDragAndDropControl moves over them.nn" "@param control The payload of the drag operation.n" "@param dropPoint The point at which the payload would be dropped if it were released now. Relative to the canvas." ); IMPLEMENT_CALLBACK( GuiControl, onControlDragExit, void, ( GuiControl* control, const Point2I& dropPoint ), ( control, dropPoint ), "Called when a drag&drop operation through GuiDragAndDropControl has exited the control and moved over a different control. This is only called for " "topmost visible controls as the GuiDragAndDropControl moves off of them.nn" "@param control The payload of the drag operation.n" "@param dropPoint The point at which the payload would be dropped if it were released now. Relative to the canvas." );But of course it might depend on what you're doing and how you really need to do it....
Torque 3D Owner Kevin Rogers
function GuiEditor::onControlDragged( %this, %payload, %position ) { // Make sure we have the right kind of D&D. if( !%payload.parentGroup.isInNamespaceHierarchy( "GuiDragAndDropControlType_GuiControl" ) ) return; // use the position under the mouse cursor, not the payload position. %position = VectorSub( %position, GuiEditorContent.getGlobalPosition() ); %x = getWord( %position, 0 ); %y = getWord( %position, 1 ); %target = GuiEditor.getContentControl().findHitControl( %x, %y ); // Make sure the target is a valid parent for our payload. while( ( !%target.isContainer || !%target.acceptsAsChild( %payload ) ) && %target != GuiEditor.getContentControl() ) %target = %target.getParent(); if( %target != %this.getCurrentAddSet() ) %this.setCurrentAddSet( %target ); }