Game Development Community

GuiControls - how to pass events thru to underlying controls ?

by Orion Elenzil · in Torque Game Engine · 12/23/2005 (10:14 am) · 4 replies

Howdy All,
happy day-before-the-day-to-go-get-presents-for-people !


So i've got a Gui heirarchy something like this:

GuiMyControl              (TheContainer)
   GuiScrollControl       (TheScroll   )
     GuiMessageVectorCtrl (TheVecCtrl  )

What i want is to capture mouseEnter and mouseLeave in TheContainer.

The problem is that TheScroll (and i presume TheVecCtrl) are swallowing those events.

1. Is there a profile setting or something along the lines of "event-Transparent" ?

2. Why is the base class implementation of say onMouseEnter() not something like this:

GuiControl::onMouseEnter(event)
{
   if (getParent())
      getParent()->onMouseEnter(event);
}

or possibly better, what i'm thinking of implementing:

GuiControl::onMouseEnter(event)
{
   if (mProfile->mTransparentToMouseEvents && getParent())
      getParent()->onMouseEnter(event);
}

tia,
orion

#1
12/23/2005 (10:30 am)
Hooray for me speaking too soon!

- i see that mouseMove and a couple other do pass the event to their parent similar to how i was thinking:

//if this control is a dead end, make sure the event stops here
   if ( !mVisible || !mAwake )
      return;
   
   //pass the event to the parent
   GuiControl *parent = getParent();
   if ( parent )
      parent->onMouseMove( event );

- any thoughts on the reasoning behind the 'dead end' logic ?
seems to me that if a control is not visible or not awake
then i especially want to pass the event on to the parent !
#2
12/23/2005 (10:32 am)
Orion, check if the base/parent classes actually have the event you refer to. If so you just need to trigger the parent event from each child instance, similar to how you described.
#3
12/23/2005 (10:55 am)
Hi duncan, thanks for replying.

you mean not put the deafult passing-on behaviour in the base GuiControl class ?

i feel silly implementing it individually in like Button, BitmapButton, ScrollCtrl, etc etc.

onMouseEnter is in the base GuiControl class, so all guiControls have it.
#4
12/23/2005 (2:16 pm)
.. on thinking a bit clearer,
i realized that one doesn't want to pass onMouseEnter() and onMouseLeave() up to the parent, duh!

i ended up creating a new event notification for onMouseEnterBounds() and onMouseLeaveBounds().
these guys only get triggered when the cursor actually leaves the boundary of a control.

i've submitted it as a resource and the pending-approval URL is here:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9421