Game Development Community

GuiControl : Any reason not to call script on each OnMouseDown ?

by Orion Elenzil · in Torque Game Engine · 05/02/2006 (4:27 pm) · 6 replies

Hey All -


so yr stock GuiControl base class does nothing in onMouseDown() and onMouseUp().

certain controls like button override these methods with their own, and that's well and good.

however,
is there any reason *not* to have the default behaviour be to call script methods on the control via executef() ?

it seems like such a natural thing that it makes me nervous it's not already there.

tia,
orion

#1
05/02/2006 (4:38 pm)
I wondered the same thing just the other day.

I don't think this would cause a performance issue.

The only side effect could be that if you actually implement a onMouseDown() in script, that all the gui controls could behave in strange ways as they were not designed for GuiControl to call script callbacks.
#2
05/02/2006 (5:05 pm)
I think you should try it and tell us what happens.
#3
05/02/2006 (5:19 pm)
I did this the other day, just to have more control.
#4
05/02/2006 (6:00 pm)
So i implemented it,
no bad side-effects so far.

thanks for the opinions, guys.

Note you have to watch out for GuiControls which have overridden onMouseDown(),
as they probably aren't calling the base-class onMouseDown() and so you won't get the script callback.
For example guiScrollControl.
#5
05/02/2006 (6:09 pm)
@Orion - If you work this out and feel it's a good improvement to TGE please do post what you changed back here. If it's a good change that makes TGE more useful out of the box and doesn't hurt existing projects, i'm sure Matt/Ben will consider it for inclusion into 1.4.1.
#6
05/04/2006 (2:04 pm)
As an FYI, mouse event handling and dispatching was designed very specifically for the original purpose of the engine, and not really an area that's gone too much in depth for refactoring/redesign. You pointed out a perfect example--it wasn't needed for the original purposes of the engine, so it wasn't added.

Some resources (click 'n pick for one), as well as the RTS-SK (not to mention TGB, which redesigned it drastically) have implemented more detailed and functional event handling back and forth between the PlayGui and the other gui controls, and as Orion points out sometimes it can be useful! One perfect example for usefulness would be to give your players the ability to move their Gui's around dynamically (during runtime) by clicking and dragging...