Game Development Community

Mouse events with gui controls

by Charlie Malbaurn · in Torque Game Builder · 04/11/2005 (4:57 pm) · 24 replies

Hey all,


I started a gui control using a GuiWindowCtrl. I tried to use a mousedown function so that when i click on it, it gives me a message.

Well, I get errors so I am wondering if the gui's have mouse events or not? If so, can someone point me in the right direction to find out what it's arguments would be?

here is the code that I tried. Basically a copy of Matthew's mouse move tuts.

Function test1::onMouseDown()
{
echo("Mouse Down");
}

I realize that the arguments are not there but that is because I don't know what they are for that control.

Any help would be most welcome.

Edit test1 is what I named my GuiWindowCtrl
Page «Previous 1 2
#1
04/11/2005 (5:22 pm)
Capitalizing function will always generate an error.
#2
04/11/2005 (9:20 pm)
Do you really think that is all? Damn if it is. I'll have to check when I get home..


What happened to the whole 'not case sensitive' thing
#3
04/11/2005 (9:34 pm)
I don't think there are callbacks for GUI controls (though wouldn't be hard to add).... though if you use a button base you can use the "command" parameter to have a function happen when clicked
#4
04/11/2005 (10:51 pm)
Matt, there are mouse events for gui controls

I just looked up guicontrol class in the engine docs and sure enough there are the mouse calls. ::mousemove etc.. And since all the gui's are children of that, they are available to each control.

So I am guessing that it must have been something as stupid as the capitol F.

I cant use command params because I am doing dragging within the gui so I am depending on there being mouse events
#5
04/11/2005 (10:52 pm)
There are internal calls, but I didn't notice any script callbacks
#6
04/11/2005 (11:06 pm)
void GuiControl::onMouseUp(const GuiEvent &event)
{
}

void GuiControl::onMouseDown(const GuiEvent &event)
{
}

void GuiControl::onMouseMove(const GuiEvent &event)
{
   //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 );
}

void GuiControl::onMouseDragged(const GuiEvent &event)
{
}

void GuiControl::onMouseEnter(const GuiEvent &)
{
}

void GuiControl::onMouseLeave(const GuiEvent &)
{
}
#7
04/11/2005 (11:56 pm)
You know, I didn't even check for script call backs.

Since they all derive from console object, I just assumed that they where available in script.

I'll fiddle with it when I get home

Edit:
Oh and it's supposed to be "King Tut" mister!
#8
04/12/2005 (12:04 am)
Matt any idea of the purpose for GuiMouseEventCtrl?
#9
04/12/2005 (5:09 am)
IIRC (and it's been a while), GuiMouseEventCtrl is an artifact left over from before direct implementation of mouse events within the top level parent GuiControl. Originally in TAP, you had to create a separate GuiMouseEventCtrl for each and every mouse input option you wanted to provide to your players within a Gui--and it was quite cumbersome!

It's not currently in use for most projects, but was left in for backwards compatibility.
#10
04/12/2005 (9:27 am)
Lol I should've known this answer better... I had to implement an onMouseClick and onMouseMove callback for my DB/Journal system

(hides the "orial")
#11
04/12/2005 (3:00 pm)
Ok,

So I got it to stop yelling at me for th function test1::onmousedown()

The problem now is that it doesn't do a echo when I'm actually pushing down on test1 but it does it on the main screen

Which, you could guess, sucks!

Edit: Nevermind, it doesn't work. The message it was giving me was from some other code
#12
04/14/2005 (4:42 pm)
For what it's worth to anyone else wondering about this stuff, I found this resource

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1864
#13
04/14/2005 (5:07 pm)
Stephen, So basically you are saying that Each control does have it's own mouse events then? so the above resource wouldn't be needed?

I'm confused about this and could really use some confirmation/direction on the this matter.

If anyone can help, it would be greatly appreciated
#14
04/14/2005 (5:11 pm)
@Charlie--I'm regurgitating forum info here (and without links, which is bad...sorry), but that is my understanding. You'll need to re-implement the virtual methods for specific inputs but back in the day, you didn't have this capability, so you had to use actual different gui controls within your gui controls for mouse stuff.

If I'm off base here guys, someone tell me, please! I'd hate to confuse folks more.

And yes, I think you still have to implement them in code--they aren't exposed to script.
#15
04/14/2005 (7:10 pm)
From what I've seen looking through the gui files I would have to agree with Stephen... for GUI mouse controls that I listed up in the code snippet you'd have to add the callbacks, if you want I'll add them and test them, but in the end you'll have to add them to your source and recompile :) You can also try making your GUI in T2D
#16
04/14/2005 (9:43 pm)
Matt,
So in essance, the link that I posted above should do the same thing, right?
#17
04/15/2005 (12:02 am)
I think... though note the date on that resource, it is very old, in fact it was released before the bitmap button was implemented it seems lol ( from the comments on it )...

I think using a buttonBase you can accomplish what you want... an invisible button that will work with clicking by the command property :) I'll see if I can run some tests for you

if not extending the source wouldn't be hard... simple callbacks
#18
04/15/2005 (12:51 am)
Heres the source changes in guiControl.cc .... note I tried adding the onMouseDown, but it crashes T2D on a lot of controls (like the file dropdown menu) because it handles it its own way :)

void GuiControl::onMouseUp(const GuiEvent &event)
{
}

void GuiControl::onMouseDown(const GuiEvent &event)
{
}

void GuiControl::onMouseMove(const GuiEvent &event)
{
   //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 );

   Con::executef(this, 1, "onMouseMove");
}

void GuiControl::onMouseDragged(const GuiEvent &event)
{
   //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->onMouseDragged( event );

	Con::executef(this, 1, "onMouseDragged");
}

void GuiControl::onMouseEnter(const GuiEvent &event)
{
   //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->onMouseEnter( event );

	Con::executef(this, 1, "onMouseEnter");
}

void GuiControl::onMouseLeave(const GuiEvent &event)
{
   //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->onMouseLeave( event );

	Con::executef(this, 1, "onMouseLeave");
}

bool GuiControl::onMouseWheelUp( const GuiEvent &event )
{
   //if this control is a dead end, make sure the event stops here
   if ( !mVisible || !mAwake )
      return true;
   
   //pass the event to the parent
   GuiControl *parent = getParent();
   if ( parent )
      return parent->onMouseWheelUp( event );
   else
      return false;

   Con::executef(this, 1, "onMouseWheelUp()");
}

...continued
#19
04/15/2005 (12:51 am)
bool GuiControl::onMouseWheelDown( const GuiEvent &event )
{
   //if this control is a dead end, make sure the event stops here
   if ( !mVisible || !mAwake )
      return true;
   
   //pass the event to the parent
   GuiControl *parent = getParent();
   if ( parent )
      return parent->onMouseWheelDown( event );
   else
      return false;

   Con::executef(this, 1, "onMouseWheelDown");
}

void GuiControl::onRightMouseDown(const GuiEvent &event)
{
	   //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->onRightMouseDown( event );

	Con::executef(this, 1, "onRightMouseDown");
}

void GuiControl::onRightMouseUp(const GuiEvent &event)
{
   //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->onRightMouseUp( event );

	Con::executef(this, 1, "onRightMouseUp");
}

void GuiControl::onRightMouseDragged(const GuiEvent &event)
{
   //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->onRightMouseDragged( event );

	Con::executef(this, 1, "onRightMouseDragged");
}

void GuiControl::onMiddleMouseDown(const GuiEvent &event)
{
   //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->onMiddleMouseDown( event );

	Con::executef(this, 1, "onMiddleMouseDown");
}

void GuiControl::onMiddleMouseUp(const GuiEvent &event)
{
   //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->onMiddleMouseUp( event );

	Con::executef(this, 1, "onMiddleMouseUp");
}

void GuiControl::onMiddleMouseDragged(const GuiEvent &event)
{
	   //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->onMiddleMouseDragged( event );

	Con::executef(this, 1, "onMiddleMouseDragged");
}
#20
04/15/2005 (12:51 am)
Heres script accessors.... note the HelperGui is just a gui control I named HelperGui

function HelperGui::onMouseMove(%this)
{
	echo("onMouseMove");
}

function HelperGui::onMouseDragged(%this)
{
	echo("onMouseDragged");
}

function HelperGui::onMouseEnter(%this)
{
	echo("onMouseEnter");
}

function HelperGui::onMouseLeave(%this)
{
	echo("onMouseLeave");
}

function HelperGui::onMouseWheelUp(%this)
{
	echo("onMouseWheelUp");
}

function HelperGui::onMouseWheelDown(%this)
{
	echo("onMouseWheelDown");
}

function HelperGui::onRightMouseDown(%this)
{
	echo("onRightMouseDown");
}

function HelperGui::onRightMouseUp(%this)
{
	echo("onRightMouseUp");
}

function HelperGui::onRightMouseDragged(%this)
{
	echo("onRightMouseDragged");
}

function HelperGui::onMiddleMouseDown(%this)
{
	echo("onMiddleMouseDown");
}

function HelperGui::onMiddleMouseUp(%this)
{
	echo("onMiddleMouseUp");
}

function HelperGui::onMiddleMouseDragged(%this)
{
	echo("onMiddleMouseDragged");
}
Page «Previous 1 2