BsGUIContextMenu.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "BsGUIContextMenu.h"
  2. #include "BsGUIDropDownBoxManager.h"
  3. #include "BsGUIManager.h"
  4. using namespace CamelotFramework;
  5. namespace BansheeEngine
  6. {
  7. GUIContextMenu::GUIContextMenu()
  8. :GUIMenu(), mContextMenuOpen(false)
  9. {
  10. }
  11. GUIContextMenu::~GUIContextMenu()
  12. {
  13. close();
  14. }
  15. void GUIContextMenu::open(const Int2& position, GUIWidget& widget)
  16. {
  17. GUIDropDownAreaPlacement placement = GUIDropDownAreaPlacement::aroundPosition(position);
  18. GameObjectHandle<GUIDropDownBox> dropDownBox = GUIDropDownBoxManager::instance().openDropDownBox(widget.getTarget(),
  19. placement, getDropDownData(), widget.getSkin(), GUIDropDownType::ContextMenu, boost::bind(&GUIContextMenu::onMenuClosed, this));
  20. GUIManager::instance().enableSelectiveInput(boost::bind(&GUIContextMenu::close, this));
  21. GUIManager::instance().addSelectiveInputWidget(dropDownBox.get());
  22. mContextMenuOpen = true;
  23. }
  24. void GUIContextMenu::close()
  25. {
  26. if(mContextMenuOpen)
  27. {
  28. GUIDropDownBoxManager::instance().closeDropDownBox();
  29. GUIManager::instance().disableSelectiveInput();
  30. mContextMenuOpen = false;
  31. }
  32. }
  33. void GUIContextMenu::onMenuClosed()
  34. {
  35. GUIManager::instance().disableSelectiveInput();
  36. mContextMenuOpen = false;
  37. }
  38. }