Page 1 of 1

scrollbar and contextmenu problem

Posted: Thu Jun 29, 2006 5:29 pm
by HighBuddha
I have setup a contextmenu in my application and it shows up and I can click on File, for example. But when I click on an Item in the submenu nothing happens and I can't click on any of the other menu Items. I have looked in the API and found the function setFocus. I understand what it does, but I don't understand how I'm supposed to use it in my program or if that would even solve my problem. Here is the code in my application:

from my event reciever

Code: Select all

case EGET_MENU_ITEM_SELECTED:
				{
					// a menu item was clicked
				    menu = (IGUIContextMenu*)event.GUIEvent.Caller;
					s32 id = menu->getItemCommandId(menu->getSelectedItem());
					
					switch(id)
					{
					case 100: // File -> Open Model
						
						break;
					case 200: // File -> Quit
						device->closeDevice();
						break;
					case 300:
                        break;
                    case 400:
                        break;
                    case 500:
                        break;
					}
					return true;
				}
and from main()

Code: Select all

menu = env->addMenu();
	menu->addItem(L"File", -1, true, true);
	menu->addItem(L"Layers", -1, true, true);

	submenu = menu->getSubMenu(0);
	submenu->addItem(L"Open", 100);
	submenu->addItem(L"Quit", 200);
	submenu->setItemEnabled()
    
    submenu = menu->getSubMenu(1);
    submenu->addItem(L"Layer 1", 300);
    submenu->addItem(L"Layer 2", 400);
    submenu->addItem(L"Layer 3", 500);
I have read the tutorials on user interfaces and checked in the meshviewer tutorial for additional help. I found the lines IGUIElement* root = env->getRootGUIElement();

and
IGUIElement* e = root->getElementFromId(5000, true);

Should I be using something like this to fix my problem?

I am also having a similar problem with my scrollbar, which doesn't move when I click on it.

Any assistance is very appreciated.

Posted: Thu Jun 29, 2006 5:50 pm
by Acki
Hmm, you do nothing with id 300, 400 and 500 (the sub menus) !!!
Try to do something in the case statements...
Also you should return true only if you handled the action, not always, like you did... So insert the return true inside the case statements and not at the end of the switch statement, there has to be return false...

Code: Select all

case EGET_MENU_ITEM_SELECTED:{
  // a menu item was clicked
  menu = (IGUIContextMenu*)event.GUIEvent.Caller;
  s32 id =     menu->getItemCommandId(menu->getSelectedItem());
  switch(id){
    case 100: // File -> Open Model              
      return true;
      break;
    case 200: // File -> Quit
      device->closeDevice();
      return true;
      break;
    case 300:
// do something here
      return true;
      break;
    case 400:
// do something here
      return true;
      break;
    case 500:
// do something here
      return true;
      break;
  }
  return false;
}
For the scrollbar click: you mean if you're clicking on the bar itself ???
If you click the knob and drag it up and down (left and right) it should work...
The "do nothing by click" is a bug of Irrlicht (it's not implemented), but there is a patch for this (also included to my IrrExtensions) !!!

Posted: Sun Jul 02, 2006 2:46 pm
by HighBuddha
Thanks for the help, I will do what you said and edit my post if I run into any problems :D