Game Development Community

GUI buttons mouse over events

by Danny Koo · in Torque Game Builder · 04/08/2005 (11:29 am) · 25 replies

Hi all,

Is there a guibutton.onMouseover function somewhere? I'm trying to hunt for it.

Thanks!
Page «Previous 1 2
#1
04/08/2005 (11:35 am)
Out of curiosity what do you want it to do onMouseOver ?
#2
04/08/2005 (11:37 am)
This is in the source

void onMouseDown(const GuiEvent &);
   void onMouseUp(const GuiEvent &);

   void onMouseEnter(const GuiEvent &);
   void onMouseLeave(const GuiEvent &);

   bool onKeyDown(const GuiEvent &event);
   bool onKeyUp(const GuiEvent &event);
#3
04/08/2005 (11:42 am)
Hi there King Bob!

I'm trying to play a wav file when mouse over a button

if I have this:

new GuiBitmapButtonCtrl(btnQuit) {
      profile = "GuiDefaultProfile";
      horizSizing = "relative";
      vertSizing = "relative";
      position = "638 490";
      extent = "100 100";
      minExtent = "8 2";
      visible = "1";
      command = "quitMainMenuGui();";
      text = "Quit";
      groupNum = "-1";
      buttonType = "PushButton";
      bitmap = "./images/gui/buttons/quit";
   };

If a button is an object, surely there's a property linked to it like mouseover?
#4
04/08/2005 (11:46 am)
Hmm... not finding a script callback to a mouse over

but found this

AUDIOHANDLE handle = alxCreateSource(mProfile->mSoundButtonOver);


and this in the profile

// sounds
   soundButtonDown = "";
   soundButtonOver = "";

C:\Torque 2D\SDK\example\common\ui\defaultProfiles.cs

so you can create your own butotn profiles to play sounds... also if you havent checked this out this will instruct on how to make bitmap button images for over, highlighted, depressed, and inactive states
#5
04/08/2005 (11:49 am)
Btw doing a script callback for on mouse over would be easy, but would require you to recompile... then would have to make the changes with the new T2D version
#6
04/08/2005 (12:00 pm)
Lol! How do you play the Handles?
#7
04/08/2005 (12:00 pm)
You guys went right past it. Everythig you need is already there.

onMouseEnter is called when the mouse is inside the bounds of the object. onMouseLeave is called when it leaves the bounds of the object.
#8
04/08/2005 (12:04 pm)
So you're saying .onMouseEnter is a valid?
#9
04/08/2005 (12:18 pm)
Isn't that what Matt listed above?

I know most GUI controls have those callbacks, and I assume thats the one he was looking at when he posted.
#10
04/08/2005 (12:31 pm)
Yup we'ere thinking of the same thing, though I can't find the callback...

guiControl.cc
void GuiControl::onMouseEnter(const GuiEvent &)
{
}

guiButtonBase.cc
guiButtonCtrl.cc
or
guiBitmapButton.cc don't have callbacks either, just tested the onMouseEnter on the buttonCtrl... unless I'm doing something wrong (or missing something) which is entirely possible lol... it seems the functions are there but no callbacks
#11
04/08/2005 (12:39 pm)
if (mActive)
   {
      if (mMouseOver) state = HILIGHT;
      if (mDepressed || mStateOn) state = DEPRESSED;
   }

Found this in guiBitmapButtonCtrl.cc.
I was wondering if we can call directly
if(mActive)
{
  if(button.mMouseOver) //....-insert play sound code-.....
}
#12
04/08/2005 (12:47 pm)
Unfortunately a lot of the GUI code has always felt unfinished to me. Its quite possible that callback is empty.

Unless theres some specific need to not modify the engine this would be trivial to add.
#13
04/08/2005 (12:55 pm)
Yup John... its a shame, though guess the original deadline probably caught up with them lol

@danny: no, but with a little modification you can add a callback and a field like

void GuiBitmapButtonCtrl::initPersistFields()
{
   Parent::initPersistFields();
   addField("bitmap", TypeFilename, Offset(mBitmapName, GuiBitmapButtonCtrl));
}

so maybe make it something like this (just off the top of my head)

void GuiBitmapButtonCtrl::initPersistFields()
{
   Parent::initPersistFields();
   addField("bitmap", TypeFilename, Offset(mBitmapName, GuiBitmapButtonCtrl));
   addField("mouseOver", TypeBool, Offset(mMouseOver, GuiBitmapButtonCtrl));
}
#14
04/08/2005 (1:02 pm)
void GuiControl::onMouseEnter(const GuiEvent &)
{
     Con::executef(this, 1, "onMouseOver");
}

(again could be mistakes, off the top of my head) adding this into the onMouseEnter of GuiControl would give a callback for all the gui controls fairly easily (as John was saying fairly easy)
#15
04/08/2005 (1:49 pm)
Okay, I find out something interesting

if(!isObject(GuiDefaultProfile)) new GuiControlProfile (GuiDefaultProfile)
{
   tab = false;
   canKeyFocus = false;
   hasBitmapArray = false;
   mouseOverSelected = false;

   // fill color
   opaque = false;
   fillColor = ($platform $= "macos") ? "211 211 211" : "192 192 192";
   fillColorHL = ($platform $= "macos") ? "244 244 244" : "220 220 220";
   fillColorNA = ($platform $= "macos") ? "244 244 244" : "220 220 220";

   // border color
   border = false;
   borderColor   = "0 0 0";
   borderColorHL = "128 128 128";
   borderColorNA = "64 64 64";

   // font
   fontType = "Arial";
   fontSize = 14;

   fontColor = "0 0 0";
   fontColorHL = "32 100 100";
   fontColorNA = "0 0 0";
   fontColorSEL= "200 200 200";

   // bitmap information
   bitmap = ($platform $= "macos") ? "./osxWindow" : "./darkWindow";
   bitmapBase = "";
   textOffset = "0 0";

   // used by guiTextControl
   modal = true;
   justify = "left";
   autoSizeWidth = false;
   autoSizeHeight = false;
   returnTab = false;
   numbersOnly = false;
   cursorColor = "0 0 0 255";

   // sounds
   soundButtonDown = "";
   soundButtonOver = "";
};

Is there anyway to modify soundButtonDown and soundButtonOver when creating that object? Regularly, if that object is defined other than the default profile, it will use the new profile and overwrite the default profile. But I don't want to touch defaultprofile.cs in common folder.
#16
04/08/2005 (1:52 pm)
I would assume:

new GuiBitmapButtonCtrl(btnQuit)
{      
profile = "GuiDefaultProfile";      
horizSizing = "relative";      
vertSizing = "relative";      
position = "638 490";      
extent = "100 100";      
minExtent = "8 2";      
visible = "1";      
command = "quitMainMenuGui();";      
text = "Quit";      
groupNum = "-1";      
buttonType = "PushButton";     
bitmap = "./images/gui/buttons/quit";
soundButtonDown = <audioprofile>;
soundButtonOver = <audioprofile>;
};
What do you all think?
#17
04/08/2005 (1:55 pm)
Yup go for it and test it... thats what I was pointing to before... seems they have audio down and overs in, but not the callbacks... if that works (I think it should) then you won't have to modify the engine :)
btw you can just create a new profile for your own type of button ;)
#18
04/08/2005 (1:56 pm)
Just copy the default, change the name like this

If(!isObject(GuiMySoundButtonProfile)) new GuiControlProfile (GuiMySoundButtonProfile){


then reference this profile
#19
04/08/2005 (2:05 pm)
Nope, I tried it, it doesn't work. It only work when you declare a custom profile in defaultprofile.cs,
Add these in defaultprofile.cs
if(!isObject(CustomProfile)) new GuiControlProfile (CustomProfile)
{
  soundButtonDown = <audioprofile>;
  soundButtonOver = <audioprofile>;
}
from above unfortunately reference audio.cs in the common folder.
and in your source code, you should put:
new GuiBitmapButtonCtrl(btnQuit){     
 profile = "CustomProfile";      
horizSizing = "relative";      
vertSizing = "relative";      
position = "638 490";      
extent = "100 100";      
minExtent = "8 2";      
visible = "1";      
command = "quitMainMenuGui();";      
text = "Quit";      
groupNum = "-1";      
buttonType = "PushButton";     
bitmap = "./images/gui/buttons/quit";
};

unless someone found a better way to overwrite profiles without rewriting/modify the engine.
#20
04/08/2005 (2:08 pm)
You have it right... though you can declare profiles wherever, as long as they happen before you call the gui... you could even put your

if(!isObject(CustomProfile)) new GuiControlProfile (CustomProfile){  
   soundButtonDown = <audioprofile>;  
   soundButtonOver = <audioprofile>;
}
at the top of your .gui file... as well as the audio profile...
Page «Previous 1 2