guiDisabledMenu.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (C) 2008-2012 Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. using namespace core;
  6. using namespace gui;
  7. // Tests that disabled GUI menu items don't cause their submenu to appear when hovered over.
  8. /**
  9. http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?p=178436#178436
  10. */
  11. bool guiDisabledMenu(void)
  12. {
  13. IrrlichtDevice *device = createDevice( video::EDT_BURNINGSVIDEO,
  14. dimension2d<u32>(160, 40), 32);
  15. assert_log(device);
  16. if (!device)
  17. return false;
  18. video::IVideoDriver* driver = device->getVideoDriver();
  19. gui::IGUIEnvironment* env = device->getGUIEnvironment();
  20. gui::IGUIContextMenu* menu = env->addMenu();
  21. menu->addItem(L"Menu", -1, true, true);
  22. gui::IGUIContextMenu* subMenu = menu->getSubMenu(0);
  23. subMenu->addItem(L"Submenu 1", -1, false, true);
  24. gui::IGUIContextMenu* subSubMenu = subMenu->getSubMenu(0);
  25. subSubMenu->addItem(L"Final item");
  26. SEvent event;
  27. event.EventType = EET_MOUSE_INPUT_EVENT;
  28. event.MouseInput.Event = EMIE_LMOUSE_PRESSED_DOWN;
  29. event.MouseInput.X = menu->getAbsolutePosition().UpperLeftCorner.X + 1;
  30. event.MouseInput.Y = menu->getAbsolutePosition().UpperLeftCorner.Y + 1;
  31. (void)menu->OnEvent(event);
  32. // Hovering over the disabled submenu shouldn't cause the "Final item" to appear.
  33. event.MouseInput.Event = EMIE_MOUSE_MOVED;
  34. event.MouseInput.X = subMenu->getAbsolutePosition().UpperLeftCorner.X + 40;
  35. event.MouseInput.Y = subMenu->getAbsolutePosition().UpperLeftCorner.Y + 10;
  36. (void)menu->OnEvent(event);
  37. device->run();
  38. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(150,50,50,50));
  39. env->drawAll();
  40. driver->endScene();
  41. bool result = takeScreenshotAndCompareAgainstReference(driver, "-guiDisabledMenu.png", 98.77f);
  42. device->closeDevice();
  43. device->run();
  44. device->drop();
  45. return result;
  46. }