Game Development Community

passthrough on gui controls

by Rex Hiebert · in Torque 3D Professional · 10/15/2009 (10:03 am) · 1 replies

I ran into an issue where I wanted to have a number of fields, both text and graphic, on a button. I wanted this button to still allow clicking but when the other controls were on it, they kept stealing the mouse events. I looked around and there was some discussion about adding a field and extra code but no real examples. So I started poking around and found that a search is launched to find which control was hit. There was even a var called "canHit". So.... in "guiControl.cpp" in the function:

void GuiControl::initPersistFields()
{
   // Things relevant only to the editor.
   addGroup("Gui Editing");
   addField("isContainer",       TypeBool,      Offset(mIsContainer, GuiControl));
   addField("canHit",            TypeBool,      Offset(mCanHit, GuiControl)); // <<< ADDED
   endGroup("Gui Editing");
...

That's it. "canHit" defaults to "true" so everything behaves normally but you now have the option to set it to false in the UI editor. The control can be seen but the mouse events pass down to the containing control (These are not the controls you are looking for. Move along!). I haven't noticed any issues with this method. Let me know if you find something.

#1
05/18/2012 (7:19 am)
I'm not sure if it is due to changes in the code base since the opening post, or if the author just didn't run into these problems, but I got several Nullpointer-Issues. They occured when the root-control (in my case the transparent background of a dialog window) if pass-through. This is because sometimes there's no check whether or not findHitControl() returns a valid pointer (or NULL).

For T3D 1.1 I've found so far:

In guiCanvas.cpp in rootMouseDown() change
//see if the controlHit is a modeless dialog...
if( !controlHit->getControlProfile()->mModal )
  continue;

to
if(!controlHit /*<< dirty fix! see comment below*/ || !controlHit->getControlProfile()->mModal )
// Due to the exposition of mCanHit, ctrl may be NULL -MD
    continue;


In guiEditCtrl.cpp in onMouseDown() and onMouseUp() insert after:
GuiControl* ctrl = mContentControl->findHitControl( mLastMousePos, getCurrentAddSet()->mLayer );

this:

//< insert start
// Dirty Hackfix 
// Due to the exposition of mCanHit, ctrl may be NULL -MD
if(! ctrl)
    ctrl = this;
//> insert end

I'll post more as I find them.