Beispiel #1
0
    protected void RenderRClickPopup()
    {
        if (this.IsShowingRClickPopup == true)
        {
            DrawingUtils.Quad(this.PopupRect, kPopupItemBackgroundColourNormal, kPopupItemBackgroundColourNormal, kPopupAlpha);

            for (int i = 0; i < this.RClickPopupItems.Count; ++i)
            {
                RClickPopupItem item     = this.RClickPopupItems[i];
                Rect            itemRect = this.PopupItemBoxes[i];

                bool  isHover         = itemRect.Contains(this.EditorMousePosition);
                Color backgroundColor = (isHover ? kPopupItemBackgroundColourHover : kPopupItemBackgroundColourNormal);
                Color textColor       = (isHover ? kPopupItemTextColourHover : kPopupItemTextColourNormal);

                DrawingUtils.Quad(itemRect, backgroundColor, backgroundColor, kPopupAlpha);

                Vector2 textPos = new Vector2(itemRect.x + kPopupTextBorder, itemRect.y + (kPopupButtonHeight / 2.0f));
                DrawingUtils.Text(item.Name, textPos, TextAnchor.MiddleLeft, textColor, false);
            }
        }
    }
Beispiel #2
0
    void UpdateRClickPopup(Event e)
    {
        if (this.IsShowingRClickPopup == false)
        {
            if ((e.type == EventType.MouseDown) && ((MouseButton)e.button == MouseButton.Right) && (this.CanShowRClickPopup == true))
            {
                this.RClickPopupItems = this.GetRClickPopupItems();
                if (this.RClickPopupItems != null)
                {
                    if (this.RClickPopupItems.Count > 0)
                    {
                        this.IsShowingRClickPopup = true;

                        //Clear out the old item boxes and rebuild all of the information for the current set of popup items
                        this.PopupItemBoxes.Clear();
                        this.PopupPosition = this.EditorMousePosition;

                        //Determine the required width of the popup based on the text
                        float width = 0.0f;
                        foreach (RClickPopupItem item in this.RClickPopupItems)
                        {
                            Vector2 ts = DrawingUtils.TextSize(item.Name);
                            width = Mathf.Max(width, ts.x);
                        }
                        width += kPopupTextBorder * 2.0f;

                        this.PopupRect          = new Rect(this.PopupPosition.x, this.PopupPosition.y, width, this.RClickPopupItems.Count * (kPopupButtonHeight + kPopupButtonSpacer) + kPopupBorder * 2);
                        this.PopupRectActiveBox = this.PopupRect.Inflate(20.0f, 20.0f);

                        float x = this.PopupPosition.x;
                        float y = this.PopupPosition.y + kPopupBorder;

                        for (int k = 0; k < this.RClickPopupItems.Count; ++k)
                        {
                            Rect itemRect = new Rect(x, y, width, kPopupButtonHeight);
                            this.PopupItemBoxes.Add(itemRect);

                            y += (kPopupButtonHeight + kPopupButtonSpacer);
                        }
                    }
                }
            }
        }
        else
        {
            bool isMouseOverPopup         = this.PopupRect.Contains(this.EditorMousePosition);
            bool isMouseOverInflatedPopup = this.PopupRectActiveBox.Contains(this.EditorMousePosition);

            //First check all of the conditions that should just clear the popup straight up
            if (((e.type == EventType.MouseDown) && (isMouseOverPopup == false)) ||
                ((e.type == EventType.MouseUp) && ((MouseButton)e.button == MouseButton.Right) && (isMouseOverInflatedPopup == false)))
            {
                this.IsShowingRClickPopup = false;
            }
            else
            {
                //We have the possibility of activating an option
                if ((e.type == EventType.MouseDown) || ((e.type == EventType.MouseUp) && ((MouseButton)e.button == MouseButton.Right)))
                {
                    //Check to see if we have Left Clicked an item in the popup
                    if (this.PopupRect.Contains(this.EditorMousePosition) == true)
                    {
                        for (int i = 0; i < this.RClickPopupItems.Count; ++i)
                        {
                            RClickPopupItem item     = this.RClickPopupItems[i];
                            Rect            itemRect = this.PopupItemBoxes[i];

                            bool isOver = itemRect.Contains(this.EditorMousePosition);
                            if (isOver == true)
                            {
                                item.Execute();
                                this.IsShowingRClickPopup = false;
                                e.Use();
                            }
                        }
                    }
                }
            }
        }
    }