예제 #1
0
        public MenuItemSubmenu(string name, MenuItem[] submenuItems)
            : base(-1, name, null)
        {
            m_Submenu = new PopupMenu(submenuItems);

            OnOver = delegate(UIMenuEventArgs args) {
                m_Submenu.Parent = (Component)args.Menu;
                int x, y, w, h;
                args.Menu.GetItemArea(this, out x, out y, out w, out h);
                m_Submenu.MoveTo(args.Menu.Width, y);                 // x + w

                if (!m_MenuAdded)
                {
                    args.Menu.Add(m_Submenu);
                }

                m_Submenu.Visible = true;
            };

            OnOut = delegate(UIMenuEventArgs args) {
                m_Submenu.Visible = false;
            };
        }
예제 #2
0
        public PopupMenu(int x, int y, MenuItem[] items) : base(x, y, 0, 0)
        {
            m_Items = (items != null) ? new List <MenuItem>(items) : new List <MenuItem>();

            foreach (MenuItem item in m_Items)
            {
                item.RecalcSize(m_Font);
            }
            Invalidate();

            OnMouseMove += delegate(UIMouseMoveEventArgs args) {
                if (args.Target != this)
                {
                    return;
                }

                int      over = m_HoverItemIndex;
                MenuItem item;

                m_HoverItemIndex = ItemHitTest(args.Cursor);
                if (over != m_HoverItemIndex)
                {
                    UIMenuEventArgs margs;
                    if (over >= 0 && over < m_Items.Count)
                    {
                        item  = m_Items[over];
                        margs = new UIMenuEventArgs(this, item);
                        if (item.OnOut != null)
                        {
                            item.OnOut(margs);
                        }
                        if (OnItemOut != null)
                        {
                            OnItemOut(margs);
                        }
                    }

                    if (m_HoverItemIndex >= 0 && m_HoverItemIndex < m_Items.Count)
                    {
                        item  = m_Items[m_HoverItemIndex];
                        margs = new UIMenuEventArgs(this, item);
                        if (item.OnOver != null)
                        {
                            item.OnOver(margs);
                        }
                        if (OnItemOver != null)
                        {
                            OnItemOver(margs);
                        }
                    }
                }
            };

            OnMouseOut += delegate(UIMouseOverEventArgs args) {
                if (args.Target != this)
                {
                    return;
                }
                if (args.OverTo is PopupMenu)
                {
                    if (args.OverTo.Parent == this)
                    {
                        return;
                    }
                }

                int      over = m_HoverItemIndex;
                MenuItem item;
                m_HoverItemIndex = -1;
                if (over >= 0 && over < m_Items.Count)
                {
                    item = m_Items[over];
                    UIMenuEventArgs margs = new UIMenuEventArgs(this, item);
                    if (item.OnOut != null)
                    {
                        item.OnOut(margs);
                    }
                    if (OnItemOut != null)
                    {
                        OnItemOut(margs);
                    }
                }

                if (!(args.OverTo is PopupMenu))
                {
                    PopupMenu rootMenu = this;
                    while (rootMenu.Parent is PopupMenu)
                    {
                        rootMenu.m_HoverItemIndex = -1;
                        if (rootMenu.OnMenuOut != null)
                        {
                            rootMenu.OnMenuOut(new UIMenuEventArgs(rootMenu, null));
                        }
                        rootMenu = (PopupMenu)rootMenu.Parent;
                    }
                    rootMenu.m_HoverItemIndex = -1;
                    if (rootMenu.OnMenuOut != null)
                    {
                        rootMenu.OnMenuOut(new UIMenuEventArgs(rootMenu, null));
                    }
                }
            };

            OnMouseOver += delegate(UIMouseOverEventArgs args) {
                if (args.Target != this)
                {
                    return;
                }
            };

            OnMouseClick += delegate(UIMouseButtonEventArgs args) {
                if (args.Target != this)
                {
                    return;
                }

                MenuItem item;
                if (m_HoverItemIndex >= 0 && m_HoverItemIndex < m_Items.Count)
                {
                    item = m_Items[m_HoverItemIndex];
                    UIMenuEventArgs margs = new UIMenuEventArgs(this, item);
                    if (item.OnClick != null)
                    {
                        item.OnClick(margs);
                    }
                    if (OnItemClick != null)
                    {
                        OnItemClick(margs);
                    }
                }
            };
        }