1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "GUI/BsGUIContextMenu.h"
4#include "GUI/BsGUIDropDownBoxManager.h"
5#include "GUI/BsGUIManager.h"
6
7namespace bs
8{
9 GUIContextMenu::~GUIContextMenu()
10 {
11 close();
12 }
13
14 void GUIContextMenu::open(const Vector2I& position, GUIWidget& widget)
15 {
16 DROP_DOWN_BOX_DESC desc;
17 desc.camera = widget.getCamera();
18 desc.skin = widget.getSkinResource();
19 desc.placement = DropDownAreaPlacement::aroundPosition(position);
20 desc.dropDownData = getDropDownData();
21
22 GameObjectHandle<GUIDropDownMenu> dropDownBox = GUIDropDownBoxManager::instance().openDropDownBox(
23 desc, GUIDropDownType::ContextMenu, std::bind(&GUIContextMenu::onMenuClosed, this));
24
25 mContextMenuOpen = true;
26 }
27
28 void GUIContextMenu::close()
29 {
30 if(mContextMenuOpen)
31 {
32 GUIDropDownBoxManager::instance().closeDropDownBox();
33 mContextMenuOpen = false;
34 }
35 }
36
37 void GUIContextMenu::onMenuClosed()
38 {
39 mContextMenuOpen = false;
40 }
41}