Error with gui..

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Error with gui..

Post by RapchikProgrammer »

Hey.. i am using irrlicht after a loooonnnggg time.. i am having this problem.. i have created a gui menu with file, edit, help and stuff.. and just below this is an editing area for the user now.. when i open the file menu and click on a button like exit.. it does get a gui event of the menu clicked but it also gets an event of mouse click hence drawing on the editing area.. the gui and the editing area are two different classes who receive onevent calls from a main class.. any idea how to solve this??
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

The way i solve this is using a isPointOverGUI() function which i've written so when my event receiver gets a mouse clicked event if first uses this function to check if the mouse is over any GUI element, if so it ignores the event as the event will no doubt be used by the GUI element the mouse is over, otherwise it processes the event.

This happens because events are sent to the user before being sent to the GUI.

Here's my function i use:

Code: Select all

bool MyEventReceiver::isPointOverGUIElement(const core::position2di& pos, IGUIElement* e) {

  if (e->getElementFromPoint(pos) != NULL) return true;
  
  core::list<IGUIElement*> children = e->getChildren();
  core::list<IGUIElement*>::Iterator iter = children.begin();
  while (iter != children.end()) {
    if (e->getElementFromPoint(pos)) return true;
    iter++;      
  }
  
  return false;

}

bool MyEventReceiver::isPointOverGUI(const core::position2di& pos) {
 
   IGUIElement* root = device->getGUIEnvironment()->getRootGUIElement();

   core::list<IGUIElement*> children = root->getChildren();
   core::list<IGUIElement*>::Iterator iter = children.begin();
   while (iter != children.end()) {
     if (isPointOverGUIElement(pos, *iter)) return true;
     iter++;      
   }
   
   return false;
       
}
Image Image Image
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

thanx a lot jp.. i forgot how good feedback was at the irrlicht forums.. the only problem with this code is that it doesnt handle sub menus.. like edit->colour->red, green, blue.. it works till edit->colour menu but when i click on the red, green or blue submenu it draws again.. its fine for now though.. thanks a lot..
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Interesting... that sounds like a bug within Irrlicht really... Maybe submenus which aren't menus themselves aren't included in the rectangle of the element.
Image Image Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, you could submit the event to the GUI event receiver in your own event receiver, and check the return value. If it isn't handled you should continue with your custom event receiver, otherwise simply skip it.
Post Reply