Beispiel #1
0
        /// <summary>
        /// Shows tooltip over given control.
        /// </summary>
        /// <param name="target">The parent control to attach to it.</param>
        /// <param name="location">Popup menu orgin location in parent cntrol coordinates.</param>
        /// <param name="targetArea">Tooltip target area or intrest.</param>
        public void Show(Control target, Vector2 location, Rectangle targetArea)
        {
            if (target == null)
            {
                throw new ArgumentNullException();
            }

            // Ensure to be closed
            Hide();

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

            // Calculate popup directinon and initial location
            var parentWin = target.ParentWindow;

            if (parentWin == null)
            {
                return;
            }
            Vector2 locationWS            = target.PointToWindow(location);
            Vector2 locationSS            = parentWin.ClientToScreen(locationWS);
            Vector2 screenSize            = Application.VirtualDesktopSize;
            Vector2 rightBottomLocationSS = locationSS + Size;

            if (screenSize.Y < rightBottomLocationSS.Y)
            {
                // Direction: up
                locationSS.Y -= Height;
            }
            if (screenSize.X < rightBottomLocationSS.X)
            {
                // Direction: left
                locationSS.X -= Width;
            }

            // Create window
            var desc = CreateWindowSettings.Default;

            desc.StartPosition          = WindowStartPosition.Manual;
            desc.Position               = locationSS;
            desc.Size                   = Size;
            desc.Fullscreen             = false;
            desc.HasBorder              = false;
            desc.SupportsTransparency   = false;
            desc.ShowInTaskbar          = false;
            desc.ActivateWhenFirstShown = false;
            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);
            if (_window == null)
            {
                throw new InvalidOperationException("Failed to create tooltip window.");
            }

            // Attach to the window and focus
            Parent  = _window.GUI;
            Visible = true;
            _window.Show();

            // Cache mouse safe movement area
            _mouseMovementRange = new Rectangle(target.ClientToScreen(targetArea.Location), targetArea.Size);
        }
        /// <summary>
        /// Show context menu over given control.
        /// </summary>
        /// <param name="parent">Parent control to attach to it.</param>
        /// <param name="location">Popup menu orgin 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 directinon and initial location
            var parentWin = parent.ParentWindow;

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

            Location = Vector2.Zero;
            Vector2 screenSize            = Application.VirtualDesktopSize;
            Vector2 rightBottomLocationSS = locationSS + Size;

            if (screenSize.Y < rightBottomLocationSS.Y)
            {
                // Direction: up
                locationSS.Y -= Height;
            }
            if (screenSize.X < rightBottomLocationSS.X)
            {
                // Direction: left
                locationSS.X -= Width;
            }

            // 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();
        }
Beispiel #3
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();
        }