Example #1
0
 public void ShowMenu()
 {
     if (CtxMenu.Visible || CtxMenu.Items.Count <= 0)
     {
         return;
     }
     CtxMenu.Show(this,
                  RightToLeft == RightToLeft.No
                   ? new Point(_menuGlyph.Bounds.Left, _menuGlyph.Bounds.Bottom)
                   : new Point(_menuGlyph.Bounds.Right, _menuGlyph.Bounds.Bottom));
     _menuOpen = true;
 }
Example #2
0
    /// <summary>
    /// Shows the context menu associated with this object. If you are handling
    /// your own picking, then you should call this function when this object
    /// is picked.
    /// </summary>
    public void ShowMenu()
    {
        if (contextMenu != null)
        {
            EventDelegate.Add(contextMenu.onSelection, OnMenuSelect);
            EventDelegate.Add(contextMenu.onHide, OnHide, true);

            current = this;
            EventDelegate.Execute(onShow);

            gameObject.SendMessage("OnShowMenu", this, SendMessageOptions.DontRequireReceiver);

            if (menuItems != null && menuItems.Length > 0)
            {
                contextMenu.Show(MenuPosition, menuItems);
            }
            else
            {
                contextMenu.Show(MenuPosition);
            }
        }
    }
Example #3
0
    void OnPress(bool isPressed)
    {
        // Filter for touches or selected mouse button.

        if (UICamera.currentTouchID >= 0 || UICamera.currentTouchID == (-1 - mouseButton))
        {
            // We show the menu on the up-press not the down-press. Otherwise NGUI would steal
            // the selection state from the context menu on the up-press, causing the menu to
            // close immediately.

            if (!isPressed)
            {
                current = this;
                EventDelegate.Execute(onShow);

                Vector3 menuPosition = placeAtTouchPosition ? new Vector3(UICamera.currentTouch.pos.x, UICamera.currentTouch.pos.y, 0f) :
                                       CtxHelper.ComputeMenuPosition(contextMenu, gameObject);

                CtxMenu.Item[] items = MenuItems;

                if (items != null || contextMenu.onShow.Count > 0)
                {
                    EventDelegate.Add(contextMenu.onSelection, OnMenuSelection);
                    EventDelegate.Add(contextMenu.onHide, OnHide, true);

                    if (menuItems != null && menuItems.Length > 0)
                    {
                        contextMenu.Show(menuPosition, menuItems);
                    }
                    else
                    {
                        contextMenu.Show(menuPosition);
                    }
                }
            }
        }
    }
Example #4
0
    void OnPress(bool isPressed)
    {
        if (isPressed)
        {
            // We compute the menu position on the down-press. Why? Because
            // UIButtonScale and UIButtonOffset will distort the button's transform
            // and throw off our calculations if we do it on the up-press. We don't
            // want to not support those NGUI features, so...
            menuPosition = CtxHelper.ComputeMenuPosition(contextMenu, gameObject);
        }
        else if (enabled && contextMenu != null)
        {
            current = this;
            if (onShow != null)
            {
                EventDelegate.Execute(onShow);
            }

            CtxMenu.Item[] items = MenuItems;

            if (items != null || contextMenu.onShow != null)
            {
                EventDelegate.Add(contextMenu.onSelection, OnMenuSelection);
                EventDelegate.Add(contextMenu.onHide, OnHide, true);

                if (menuItems != null && menuItems.Length > 0)
                {
                    contextMenu.Show(menuPosition, menuItems);
                }
                else
                {
                    contextMenu.Show(menuPosition);
                }
            }
        }
    }
Example #5
0
 void Update()
 {
     if (Input.GetMouseButtonUp(0))
     {
         Camera     mainCam = Camera.main;
         RaycastHit hit     = new RaycastHit();
         Ray        ray     = mainCam.ScreenPointToRay(Input.mousePosition);
         if (GetComponent <Collider>().Raycast(ray, out hit, mainCam.farClipPlane))
         {
             Vector3 screenPos = mainCam.WorldToScreenPoint(transform.position);
             EventDelegate.Add(menu.onSelection, OnMenuSelection);
             menu.Show(screenPos);
         }
     }
 }
Example #6
0
        //safly lets you shutdown the browser

        private void btnMenu_Click(object sender, EventArgs e)
        {
            CtxMenu.Show(MousePosition);
            //opens the contextbrowser menu and opens it on your mouse position
        }
Example #7
0
	void ShowSubmenu(int itemIndex)
	{
		// Occasionally seeing this pop up after the parent menu has been closed,
		// probably because the submenu timer is still going. In this case we
		// simply decline to show the submenu.
		if (menuRoot == null)
			return;
		
		CtxMenu submenu = items[index].submenu;
		Item[] submenuItems = items[index].submenuItems;
		
		// There can be only one!
		HideSubmenu();
		
		currentSubmenu = submenu;
		
		if (currentSubmenu != null)
		{
			Bounds highlightBounds;
			Rect highlightScreenRect;
			
			UICamera uiCam = uiCamera;
			
			EventDelegate.Add(currentSubmenu.onSelection, OnSubmenuSelection);
			currentSubmenu.parentMenu = this;
			
			float dx = 0f, dy = 0f;
			
			// Before we can place the submenu, we need to determine the screen-space
			// area it will occupy so that we can adjust its position in those cases
			// where it goes off screen. In either case we let NGUI help us by
			// determining the combined volume of all the submenu widgets.
			
			if (style == Style.Pie)
			{
				// We don't want to the shadow to be part of the bounds calculation,
				// so we disable it temporarily.
				if (itemData[itemIndex].shadow != null)
					CtxHelper.SetActive(itemData[itemIndex].shadow.gameObject, false);
				
				highlightBounds = NGUIMath.CalculateRelativeWidgetBounds(menuRoot.transform, itemData[itemIndex].background.transform, true);
				
				if (itemData[itemIndex].shadow != null)
					CtxHelper.SetActive(itemData[itemIndex].shadow.gameObject, true);
				
				highlightBounds = CtxHelper.LocalToWorldBounds(highlightBounds, menuRoot.transform);
				highlightScreenRect = CtxHelper.ComputeScreenSpaceBounds(highlightBounds, uiCam.cachedCamera);
			}
			else
			{
				// We don't want the shadow to be part of the bounds calculation,
				// so we disable it temporarily.
				if (shadow != null)
					CtxHelper.SetActive(shadow.gameObject, false);
				
				Bounds menuBounds = NGUIMath.CalculateRelativeWidgetBounds(menuRoot.transform);
				
				if (shadow != null)
					CtxHelper.SetActive(shadow.gameObject, true);
				
				highlightBounds = NGUIMath.CalculateRelativeWidgetBounds(menuRoot.transform, itemData[itemIndex].highlight.transform, true);

				// Adjust the highlight boundaries so that it accounts for the menu
				// dimensions. Otherwise the submenu will butt up against the highlight
				// rather than the menu background.
				Vector3 ext = highlightBounds.extents;
				Vector3 ctr = highlightBounds.center;
				if (style == Style.Horizontal)
				{
					ctr.y = menuBounds.center.y;
					ext.y = menuBounds.extents.y;
				}
				else
				{
					ctr.x = menuBounds.center.x;
					ext.x = menuBounds.extents.x;
				}
				
				highlightBounds.center = ctr;
				highlightBounds.extents = ext;
				highlightBounds = CtxHelper.LocalToWorldBounds(highlightBounds, menuRoot.transform);
				highlightScreenRect = CtxHelper.ComputeScreenSpaceBounds(highlightBounds, uiCam.cachedCamera);

				// Account for the submenu padding. This ensures that the submenu highlights
				// will align with our highlights, which is an aesthetic consideration.
				if (style == Style.Horizontal)
					dx = -currentSubmenu.padding.x;
				else if (style == Style.Vertical)
					dy = currentSubmenu.padding.y;
				
				// Account for backgound padding, plus one pixel extra.
				highlightScreenRect = CtxHelper.InsetRect(highlightScreenRect, -backgroundPadding.x - 1f, -backgroundPadding.y - 1f);
			}

			// CtxHelper.ComputeMenuPosition() does the actual adjusting of position based
			// on the menus pivot and its screen-space dimensions.
			
			Vector3 submenuPos = CtxHelper.ComputeMenuPosition(currentSubmenu, highlightScreenRect, (style == Style.Horizontal));
			submenuPos.x += dx;
			submenuPos.y += dy;
					
			submenuTimer = 0f;
			
			itemData[itemIndex].submenu = currentSubmenu;
			
			if (submenuItems != null && submenuItems.Length > 0)
				currentSubmenu.Show(submenuPos, submenuItems);
			else
				currentSubmenu.Show(submenuPos);
		}
	}