示例#1
0
        RectangleF GetContextMenuBounds(SubMenuOverlay sub, PointF location)
        {
            if (Width < 5 || Height < 5)
            {
                return(RectangleF.Empty);
            }

            SizeF sz = sub.PreferredSize(CTX);

            float w = Math.Min(sz.Width, Width);
            float h = Math.Min(sz.Height, Height);

            float y = location.Y;

            RectangleF rsub = new RectangleF(
                location.X,
                y,
                w,
                h);

            if (rsub.Right > Width)
            {
                rsub.Offset(Width - rsub.Right, 0);
            }

            if (rsub.Bottom > Height)
            {
                rsub.Offset(0, Height - rsub.Bottom);
            }

            return(rsub);
        }
示例#2
0
        private void ShowSubMenu(IGuiMenuItem mainmenuItem)
        {
            if (mainmenuItem == null || mainmenuItem.Children.IsNullOrEmpty())
            {
                return;
            }

            if (SubMenu != null)
            {
                CloseSubMenu();
            }

            SubMenu = new SubMenuOverlay("sub", mainmenuItem.Children);

            SubMenu.ZIndex = Math.Max(SubMenu.ZIndex, this.ZIndex + 1);
            SubMenu.SetBounds(GetSubMenuBounds(SubMenu));
            this.AddChild(SubMenu);

            SubMenu.Closing += delegate {
                CloseSubMenu();
                m_LastActiveItemIndex = ActiveItem == null ? -1 : Menu.IndexOf(ActiveItem);
                ActiveItem            = null;
                Invalidate();
            };

            //SubMenu.Focus ();
            //this.Focus();
            this.Select();

            //bool bTest = SubMenu.CanFocus;

            Expanded = true;
            Invalidate();
        }
        protected virtual RectangleF GetSubMenuBounds(SubMenuOverlay sub)
        {
            SummerGUIWindow aw = ParentWindow;

            if (aw == null || aw.Width < 5 || aw.Height < 5)
            {
                return(RectangleF.Empty);
            }

            RectangleF bounds = Bounds;
            SizeF      sz     = sub.PreferredSize(aw);

            float w = Math.Min(sz.Width, aw.Width);
            float h = Math.Min(sz.Height, aw.Height);

            float y = 0;

            try {
                y = itemStartPositions[Menu.IndexOf(m_ActiveItem)] - Padding.Top;
            } catch (Exception ex) {
                ex.LogError();
            }

            RectangleF rsub = new RectangleF(
                bounds.Right,
                y,
                w,
                h);

            try {
                float ofs = 5 * ParentWindow.ScaleFactor;
                rsub.Offset(-ofs, -ofs);
            } catch (Exception ex) {
                ex.LogError();
            }

            if (rsub.Right > aw.Width)
            {
                rsub.Offset(aw.Width - rsub.Right, 0);
            }

            if (rsub.Bottom > aw.Height)
            {
                rsub.Offset(0, aw.Height - rsub.Bottom);
            }

            return(rsub);
        }
示例#4
0
        public void ShowContextMenu(PointF location, IGuiMenu menu)
        {
            lock (contextMenuLock) {
                if (ContextMenuOverlay != null)
                {
                    CloseContextMenu();
                }

                ContextMenuOverlay          = new SubMenuOverlay("contextmenu", menu);
                ContextMenuOverlay.Closing += delegate {
                    CloseContextMenu();
                };

                AddChild(ContextMenuOverlay);
                ContextMenuOverlay.SetBounds(GetContextMenuBounds(ContextMenuOverlay, location));
                ContextMenuOverlay.CanFocus = false;
                ContextMenuOverlay.Visible  = true;
                ContextMenuOverlay.Selected = true;
                Invalidate();
            }
        }
示例#5
0
        protected virtual RectangleF GetSubMenuBounds(SubMenuOverlay sub)
        {
            SummerGUIWindow aw = ParentWindow;

            if (aw == null)
            {
                return(RectangleF.Empty);
            }

            RectangleF bounds = MarginBounds;

            try {
                bounds.Offset(itemStartPositions[Menu.IndexOf(ActiveItem)], 0);
            } catch (Exception ex) {
                ex.LogError();
            }

            float spaceAbove = bounds.Top;
            float spaceBelow = aw.Height - bounds.Bottom;

            SizeF sz = sub.PreferredSize(aw);

            float desiredHeight = sz.Height;
            float desiredWidth  = sz.Width;
            float itemHeight    = sub.LineHeight;

            float maxspace = Math.Max(spaceAbove, spaceBelow);

            if (desiredHeight > maxspace)
            {
                desiredHeight = (int)(maxspace / itemHeight) * itemHeight;
            }

            RectangleF result = RectangleF.Empty;

            if (desiredHeight > 0 && desiredWidth > 0)
            {
                if (spaceBelow >= desiredHeight)
                {
                    result = new RectangleF(bounds.Left, bounds.Bottom, desiredWidth, desiredHeight);
                }
                else if (spaceAbove >= desiredHeight)
                {
                    result = new RectangleF(bounds.Left, bounds.Top - desiredHeight, desiredWidth, desiredHeight);
                }
            }

            if (!result.IsEmpty)
            {
                if (result.Left < 1)
                {
                    result.Offset(Math.Abs(result.Left) + 3, -2);
                }
                else
                {
                    result.Offset(-2, -2);
                }
            }

            return(result);
        }