Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ContextMenuBase"/> class.
        /// </summary>
        public ContextMenuBase()
            : base(0, 0, 120, 32)
        {
            _direction = ContextMenuDirection.RightDown;
            Visible    = false;

            _performChildrenLayoutFirst = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ContextMenuBase"/> class.
        /// </summary>
        public ContextMenuBase()
            : base(0, 0, 120, 32)
        {
            _direction = ContextMenuDirection.RightDown;
            Visible    = false;

            _isSubMenu = true;
        }
Esempio n. 3
0
        public ZContextMenu()
        {
            this.SetStyle(ControlStyles.UserPaint |
                          ControlStyles.AllPaintingInWmPaint |
                          ControlStyles.OptimizedDoubleBuffer, true);


            mHoverColor = Color.SteelBlue;
            mTextColor  = Color.WhiteSmoke;
            mBgColor    = Color.FromArgb(50, 50, 50);

            mPopup = new Popup(this);

            Direction = ContextMenuDirection.Down;

            mItems = new List <ListItem>();
        }
Esempio n. 4
0
        /// <summary>
        /// Show context menu over given control.
        /// </summary>
        /// <param name="parent">Parent control to attach to it.</param>
        /// <param name="location">Popup menu origin location in parent control coordinates.</param>
        public virtual void Show(Control parent, Vector2 location)
        {
            Assert.IsNotNull(parent);

            // Ensure to be closed
            Hide();

            // Peek parent control window
            var parentWin = parent.RootWindow;

            if (parentWin == null)
            {
                return;
            }

            // Check if show menu inside the other menu - then link as a child to prevent closing the calling menu window on lost focus
            if (_parentCM == null && parentWin.ChildrenCount == 1 && parentWin.Children[0] is ContextMenuBase parentCM)
            {
                parentCM.ShowChild(this, parentCM.ScreenToClient(parent.ClientToScreen(location)), false);
                return;
            }

            // Unlock and perform controls update
            UnlockChildrenRecursive();
            PerformLayout();

            // Calculate popup direction and initial location (fit on a single monitor)
            var     dpiScale   = Platform.DpiScale;
            Vector2 dpiSize    = Size * dpiScale;
            Vector2 locationWS = parent.PointToWindow(location);
            Vector2 locationSS = parentWin.ClientToScreen(locationWS * dpiScale);

            Location = Vector2.Zero;
            Rectangle monitorBounds = Platform.GetMonitorBounds(locationSS);
            Vector2   rightBottomLocationSS = locationSS + dpiSize;
            bool      isUp = false, isLeft = false;

            if (monitorBounds.Bottom < rightBottomLocationSS.Y)
            {
                // Direction: up
                isUp          = true;
                locationSS.Y -= dpiSize.Y;
            }
            if (monitorBounds.Right < rightBottomLocationSS.X)
            {
                // Direction: left
                isLeft        = true;
                locationSS.X -= dpiSize.X;
            }

            // Update direction flag
            if (isUp)
            {
                _direction = isLeft ? ContextMenuDirection.LeftUp : ContextMenuDirection.RightUp;
            }
            else
            {
                _direction = isLeft ? ContextMenuDirection.LeftDown : ContextMenuDirection.RightDown;
            }

            // Create window
            var desc = CreateWindowSettings.Default;

            desc.Position               = locationSS;
            desc.StartPosition          = WindowStartPosition.Manual;
            desc.Size                   = dpiSize;
            desc.Fullscreen             = false;
            desc.HasBorder              = false;
            desc.SupportsTransparency   = false;
            desc.ShowInTaskbar          = false;
            desc.ActivateWhenFirstShown = true;
            desc.AllowInput             = true;
            desc.AllowMinimize          = false;
            desc.AllowMaximize          = false;
            desc.AllowDragAndDrop       = false;
            desc.IsTopmost              = true;
            desc.IsRegularWindow        = false;
            desc.HasSizingFrame         = false;
            _window            = Platform.CreateWindow(ref desc);
            _window.LostFocus += OnWindowLostFocus;

            // Attach to the window
            _parentCM = parent as ContextMenuBase;
            Parent    = _window.GUI;

            // Show
            Visible = true;
            if (_window == null)
            {
                return;
            }
            _window.Show();
            PerformLayout();
            Focus();
            OnShow();
        }
Esempio n. 5
0
        /// <summary>
        /// Show context menu over given control.
        /// </summary>
        /// <param name="parent">Parent control to attach to it.</param>
        /// <param name="location">Popup menu origin location in parent control coordinates.</param>
        public virtual void Show(Control parent, Vector2 location)
        {
            Assert.IsNotNull(parent);

            // Ensure to be closed
            Hide();

            // Unlock and perform controls update
            UnlockChildrenRecursive();
            PerformLayout();

            // Calculate popup direction and initial location (fit on a single monitor)
            var parentWin = parent.RootWindow;

            if (parentWin == null)
            {
                return;
            }
            Vector2 locationWS = parent.PointToWindow(location);
            Vector2 locationSS = parentWin.ClientToScreen(locationWS);

            Location = Vector2.Zero;
            Rectangle monitorBounds = Application.GetMonitorBounds(locationSS);
            Vector2   rightBottomLocationSS = locationSS + Size;
            bool      isUp = false, isLeft = false;

            if (monitorBounds.Bottom < rightBottomLocationSS.Y)
            {
                // Direction: up
                isUp          = true;
                locationSS.Y -= Height;
            }
            if (monitorBounds.Right < rightBottomLocationSS.X)
            {
                // Direction: left
                isLeft        = true;
                locationSS.X -= Width;
            }

            // Update direction flag
            if (isUp)
            {
                _direction = isLeft ? ContextMenuDirection.LeftUp : ContextMenuDirection.RightUp;
            }
            else
            {
                _direction = isLeft ? ContextMenuDirection.LeftDown : ContextMenuDirection.RightDown;
            }

            // Create window
            var desc = CreateWindowSettings.Default;

            desc.Position               = locationSS;
            desc.StartPosition          = WindowStartPosition.Manual;
            desc.Size                   = Size;
            desc.Fullscreen             = false;
            desc.HasBorder              = false;
            desc.SupportsTransparency   = false;
            desc.ShowInTaskbar          = false;
            desc.ActivateWhenFirstShown = true;
            desc.AllowInput             = true;
            desc.AllowMinimize          = false;
            desc.AllowMaximize          = false;
            desc.AllowDragAndDrop       = false;
            desc.IsTopmost              = true;
            desc.IsRegularWindow        = false;
            desc.HasSizingFrame         = false;
            _window              = FlaxEngine.Window.Create(desc);
            _window.OnLostFocus += onWindowLostFocus;

            // Attach to the window
            _parentCM = parent as ContextMenuBase;
            Parent    = _window.GUI;

            // Show
            Visible = true;
            _window.Show();
            PerformLayout();
            Focus();
            OnShow();
        }