/// <summary> /// Calls up a precreated popup in the given container at the offset (which becomes the topleft point). /// </summary> public static void Call(LayerContainer Container, Point Offset, Popup Popup) { Point size = Popup.Size; Offset.X = Math.Min(Offset.X, Container.Size.X - size.X); Offset.Y = Math.Min(Offset.Y, Container.Size.Y - size.Y); Container.AddControl(Popup, Offset); ModalOptions mo = new ModalOptions() { MouseFallthrough = true, Lightbox = false, LowestModal = Popup }; mo.BackgroundClick += delegate { Popup.Dismiss(); }; Container.Modal = mo; }
/// <summary> /// Calls up a popup in the container at the offset (which becomes the topleft point). /// </summary> public static Popup Call(LayerContainer Container, Point Offset, IEnumerable<MenuItem> Items, PopupStyle Style) { Popup p = new Popup(Style, Items); Call(Container, Offset, p); return p; }
/// <summary> /// Creates a submenu with the specified items. /// </summary> private void _CreateSubmenu(IEnumerable<MenuItem> Items, Rectangle SourceRect) { PopupStyle style = this._Style; LayerContainer container = this.Container; Popup subpopup = new Popup(style, Items); Point size = subpopup.Size; Point offset = new Point(SourceRect.Location.X + SourceRect.Size.X - 1, SourceRect.Location.Y - style.Margin); if (offset.Y + size.Y > container.Size.Y) { offset.Y = SourceRect.Location.Y + SourceRect.Size.Y - size.Y + style.Margin; } if (offset.X + size.X > container.Size.X) { offset.X = SourceRect.Location.X - size.X + 1; } this._Submenu = subpopup; subpopup._Parent = this; container.AddControl(subpopup, offset); }
/// <summary> /// Creates a submenu, if needed /// </summary> private void _UpdateSubmenu(Rectangle ActiveItemRect) { // Remove current submenu if any if (this._Submenu != null) { this._Submenu.Dismiss(); this._Submenu = null; } // Perhaps a submenu is needed? MenuItem source = this._Active.Source; CompoundMenuItem cpmi = source as CompoundMenuItem; if (cpmi != null) { this._CreateSubmenu(cpmi.Items, ActiveItemRect + this.Position); } }
public override void Update(GUIControlContext Context, double Time) { // Mouse navigation. Rectangle inner = new Rectangle(this.Size).Margin(this._Style.Margin); MouseState ms = Context.MouseState; this._MouseDown = false; if (ms != null) { Point mousepos = ms.Position; foreach (_Item i in this._Items) { Rectangle irect = this._ItemRect(inner, i); if (irect.In(mousepos)) { if (ms.IsButtonDown(MouseButton.Left)) { this._MouseDown = true; } if ((mousepos - this._LastMouse).SquareLength > 1.0 || this._MouseDown) { if (this._Select(i)) { this._UpdateSubmenu(irect); } } if (ms.HasReleasedButton(MouseButton.Left)) { this._Click(); } } } this._LastMouse = mousepos; } // Keyboard navigation KeyboardState ks = Context.KeyboardState; if (ks != null && !this._MouseDown) { foreach (KeyEvent ke in ks.Events) { _Item nitem = this._Active; if (ke.Type == ButtonEventType.Down) { if (ke.Key == Key.Down) { // Navigate down if (this._Active == null) { nitem = this._Items[0]; } else { nitem = this._ItemAtOffsetIndex(this._Active, 1); } } if (ke.Key == Key.Up) { // Navigate up if (this._Active == null) { nitem = this._Items[this._Items.Count - 1]; } else { nitem = this._ItemAtOffsetIndex(this._Active, -1); } } if (ke.Key == Key.Left) { if (this._Parent != null) { this._Parent._Submenu = null; } this.Dismiss(); return; } if (ke.Key == Key.Right) { if (this._Active != null) { this._UpdateSubmenu(_ItemRect(inner, this._Active)); return; } } if (ke.Key == Key.Enter) { this._Click(); return; } } if (nitem != this._Active) { this._Select(nitem); } } // Super quick number navigation foreach (char c in ks.Presses) { int n = (int)c - 49; if (n >= 0 && n < 9) { if (n < this._Items.Count) { _Item item = this._Items[n]; if (this._Select(item)) { this._UpdateSubmenu(this._ItemRect(inner, item)); this._Click(); } } } } } if (this._Submenu == null && !Context.HasKeyboard) { Context.CaptureKeyboard(); } }