Game Development Community

Modal GUI and mouseDown event

by Teddy Setiawan Wijaya · in Torque Game Builder · 07/19/2008 (1:55 am) · 4 replies

If a Modal GUI is displayed on screen, who handles the mouseDown event?

I would have thought that it is the modal GUI, but it doesn't seem so...;-(

Here's how I setup my GUI

//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(someBox) {
   canSaveDynamicFields = "0";
   isContainer = "1";
   Profile = "GuiSomeBoxProfile";
   HorizSizing = "right";
   VertSizing = "bottom";
   Position = "0 0";
   Extent = "800 600";
   MinExtent = "8 2";
   canSave = "1";
   Visible = "1";
   hovertime = "1000";

      new GuiMLTextCtrl(someText) {
         canSaveDynamicFields = "0";
         isContainer = "0";
         Profile = "GuiSomeTextProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         Position = "180 130";
         Extent = "328 32";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         hovertime = "1000";
         lineSpacing = "1";
         allowColorChars = "1";
         maxChars = "-1";
         text = "";
		};
};
//--- OBJECT WRITE END ---

Here's more details about GuiSomeBoxProfile (declared in gameScripts\guiProfiles.cs)

if(!isObject(GuiSomeBoxProfile)) new GuiControlProfile (GuiSomeBoxProfile)
	{
		border = false;
		opaque = false;
		modal = true;
	};

Then I also have the following code inside someBox.cs (which have been exec'd in game.cs)

function someBox::onMouseDown( %this, %modifier, %worldPosition, %clicks)
{
	echo("someBox::onMouseDown!!!");
}

After the GUI has been displayed, I expect the echo command to print something on console after I click the left mouse button but nothing happened.

Did I miss anything?

#1
07/19/2008 (9:25 am)
Isn't onMouseDown a t2dSceneWindow callback? GuiControl does not have an onClick callback or anything like that. Making it modal means (I think) if you don't handle the mouse input pass it on to your parent rather than keeping it.
#2
07/21/2008 (12:23 am)
James,

You are right, onMouseDown is indeed only a t2dSceneWindow callback.
I've tried adding
useWindowMouseEvents = "1";
to GuiSomeBoxProfile (see above) but it doesn't work. I have also tried to change GuiControl into GuiCanvas. It doesn't work either.

Backtracking a bit, actually the whole purpose of this 'experiment' is to make sure that when the GUI is displayed, it will sort of 'trap' the mouse movement. What I want is when the GUI is displayed there will be a different handler of onMouseDown event. Of course I can have only one onMouseDown procedure by having a global variable check, but it doesn't seem right...;-(

Finally I tried to define the GUI the following way
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(someBox) {
   canSaveDynamicFields = "0";
   Profile = "GuiTransparentProfile";
   HorizSizing = "width";
   VertSizing = "height";
   Position = "0 0";
   Extent = "1024 768";
   MinExtent = "8 8";
   canSave = "1";
   Visible = "1";
   useVariable = "0";

   new t2dSceneWindow(someBackground) {
      canSaveDynamicFields = "0";
      isContainer = "1";	  
      Profile = "someBackgroundProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "1024 768";
      MinExtent = "8 8";
      canSave = "1";
      Visible = "1";
	  
	   new GuiMLTextCtrl(someText) {
			 canSaveDynamicFields = "0";
			 isContainer = "0";
			 Profile = "someTextProfile";
			 HorizSizing = "width";
			 VertSizing = "right";
			 Position = "180 130";
			 Extent = "328 32";
			 MinExtent = "8 8";
			 canSave = "1";
			 Visible = "1";
			 hovertime = "1000";
			 lineSpacing = "1";
			 allowColorChars = "1";
			 maxChars = "-1";
			 text = "";
			};	  	     	  
	};		
};
//--- OBJECT WRITE END ---

With the following profiles defined in guiProfiles.cs
if(!isObject(someBackgroundProfile)) new GuiControlProfile (someBackgroundProfile)
{
      border = false;
      modal = true;
      lockMouse = 0;
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "0";		
};

Using this new GUI setting, the following code works like a charm
function someBackground::onMouseDown( %this, %modifier, %worldPosition, %clicks)
{
	echo("someBackground::onMouseDown");
}

However, there is one big problem, the GuiMLTextCtrl never shows up on the screen! Don't know why..;-(
#3
07/21/2008 (1:40 am)
Thanks to Amanda (who put up GUI Overview) and Edward Maurina (who wrote about GuiMouseEventCtrl) I found the answer!

The answer is to use GuiMouseEventCtrl instead of t2dSceneWindow. Using it, I can both 'trap' the mouseDown event and display the GuiMLTextCtrl properly.
#4
07/21/2008 (10:00 am)
Nice, glad to hear it.