/// <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> /// Shows tooltip over given control. /// </summary> /// <param name="target">The parent control to attach to it.</param> /// <param name="location">Popup menu origin location in parent control coordinates.</param> /// <param name="targetArea">Tooltip target area of interest.</param> public void Show(Control target, Vector2 location, Rectangle targetArea) { if (target == null) { throw new ArgumentNullException(); } // Ensure to be closed Hide(); // Block showing tooltips when application is not focused if (!Platform.HasFocus) { return; } // Unlock and perform controls update UnlockChildrenRecursive(); PerformLayout(); // Calculate popup direction and initial location var parentWin = target.Root; if (parentWin == null) { return; } float dpiScale = target.RootWindow.DpiScale; Vector2 dpiSize = Size * dpiScale; Vector2 locationWS = target.PointToWindow(location); Vector2 locationSS = parentWin.PointToScreen(locationWS); Rectangle monitorBounds = Platform.GetMonitorBounds(locationSS); Vector2 rightBottomMonitorBounds = monitorBounds.BottomRight; Vector2 rightBottomLocationSS = locationSS + dpiSize; // Prioritize tooltip placement within parent window, fall back to virtual desktop if (rightBottomMonitorBounds.Y < rightBottomLocationSS.Y) { // Direction: up locationSS.Y -= dpiSize.Y; } if (rightBottomMonitorBounds.X < rightBottomLocationSS.X) { // Direction: left locationSS.X -= dpiSize.X; } _showTarget = target; // Create window var desc = CreateWindowSettings.Default; desc.StartPosition = WindowStartPosition.Manual; desc.Position = locationSS; desc.Size = dpiSize; 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 = Platform.CreateWindow(ref 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(); _showTarget.OnTooltipShown(this); }
/// <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.Root; 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; } _showTarget = target; // 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(); }
/// <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(); }