/// <summary> /// Shows a messagebox with the specified options. /// </summary> public static void Show(LayerContainer LayerContainer, MessageBoxOptions Options) { MessageBoxStyle style = Options.Style; // Message Label message = new Label(Options.Message, style.MessageColor, style.MessageLabelStyle); ClickHandler anyclick = null; // Buttons FlowContainer buttonflow = new FlowContainer(style.ButtonSeperation, Axis.Horizontal); ButtonStyle bstyle = style.ButtonStyle; foreach (MessageBoxOptions._Button b in Options._Buttons) { string name = b.Name; Label label = new Label(name, bstyle.TextColor, bstyle.TextStyle); Button button = new Button(bstyle); button.Client = label; button.Click += b.Click; button.Click += delegate { anyclick(); }; buttonflow.AddChild(button, button.GetFullSize(label.SuggestSize).X); } // Main flow container FlowContainer mainflow = new FlowContainer(style.MessageButtonSeperation, Axis.Vertical); mainflow.AddChild(message, message.GetHeight(style.ContentWidth)); mainflow.AddChild(buttonflow.WithCenterAlign(new Point(buttonflow.SuggestLength, style.ButtonHeight)), style.ButtonHeight); // Margin and border MarginContainer margin = mainflow.WithMargin(style.Margin); Point finalsize = margin.GetSize(new Point(style.ContentWidth, mainflow.SuggestLength)); Control final = margin; if (style.BorderSize > 0.0) { double bs = style.BorderSize; final = final.WithBorder(style.BorderColor, bs, bs, bs, bs); finalsize += new Point(bs, bs) * 2.0; } // Form (finally) Form form = new Form(final, Options.Title); form.ClientSize = finalsize; LayerContainer.AddControl(form, LayerContainer.Size * 0.5 - form.Size * 0.5); // Make it modal ModalOptions mo = new ModalOptions() { Lightbox = true, LowestModal = form, MouseFallthrough = false }; LayerContainer.Modal = mo; // Create destruction procedure. anyclick = delegate { LayerContainer.Modal = null; form.Dismiss(); }; }
/// <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> /// Creates a function that displays the selection to the user. /// </summary> public Action<GUIControlContext> Display(GameBoardView BoardView) { return delegate(GUIControlContext Context) { LayerContainer lc; Point offset; if (Context.FindAncestor<LayerContainer>(out lc, out offset)) { FlowContainer options = new FlowContainer(20.0, Axis.Horizontal); Pane pane = new Pane(new SunkenContainer(options.WithMargin(20.0)).WithBorder(1.0)); ModalOptions mo = new ModalOptions() { Lightbox = false, LowestModal = pane, MouseFallthrough = false }; foreach (_Possible p in this._Items) { _Possible ip = p; Button button = new Button(ButtonStyle.CreateSolid(Skin.Default), new _PieceIcon(p.Move.NewState).CreateControl()); options.AddChild(button, 150.0); button.Click += delegate { lc.Modal = null; pane.Dismiss(); BoardView.MakeMove(ip.Move, ip.Board); }; } pane.ClientSize = new Point(options.SuggestLength + 42.0, 190.0); Rectangle merect = new Rectangle(offset, Context.Control.Size); lc.AddControl(pane, merect.Location + merect.Size * 0.5 - pane.Size * 0.5); lc.Modal = mo; } }; }