/// <summary> /// Hide popup menu and all child menus. /// </summary> public virtual void Hide() { if (!Visible) { return; } // Lock update IsLayoutLocked = true; // Close child HideChild(); // Unlink _parentCM = null; Parent = null; // Close window if (_window != null) { var win = _window; _window = null; win.Close(); } // Hide Visible = false; OnHide(); }
/// <summary> /// Hides child popup menu if any opened. /// </summary> public void HideChild() { if (_childCM != null) { _childCM.Hide(); _childCM = null; } }
/// <summary> /// Shows new child context menu. /// </summary> /// <param name="child">The child menu.</param> /// <param name="location">The child menu initial location.</param> public void ShowChild(ContextMenuBase child, Vector2 location) { // Hide current child HideChild(); // Set child _childCM = child; _childCM._parentCM = this; // Show child _childCM.Show(this, location); }
/// <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(); }
/// <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(); }