/// <summary> /// Adds a child control at the specified position and size. /// </summary> public void AddChild(Control Child, Rectangle Area) { this.ResizeChild(Child, Area.Size); this._Children.Add(new _Child() { Control = Child, Offset = Area.Location }); }
public override void Render(GUIRenderContext Context) { Rectangle inner = new Rectangle(new Point(), this.Size); Context.PushClip(inner); foreach (_Child c in this._Children) { Context.PushTranslate(c.Offset); c.Control.Render(Context); Context.Pop(); } Context.Pop(); }
public override void Render(GUIRenderContext Context) { Skin skin = this._Style.Skin; Surface surfback = skin.GetSurface(this._Style.Backing, this.Size); Context.DrawSurface(surfback); double width = this.Size.X * this._Value; Rectangle clip = new Rectangle(0, 0, width, this.Size.Y); Context.PushClip(clip); Surface surfprog = skin.GetSurface(this._Style.Progress, this.Size); Context.DrawSurface(surfprog); Context.Pop(); }
public override void Update(GUIControlContext Context, double Time) { MouseState ms = Context.MouseState; if (ms != null) { // Zoom and stuff double scroll = ms.Scroll; if (scroll != 0.0) { double zoom = Math.Pow(2.0, -scroll / 40.0); Rectangle win = this._Window; Point mousepos = new Rectangle(this.Size).ToRelative(ms.Position); mousepos.Y = 1.0 - mousepos.Y; Point nwinsize = win.Size * zoom; Point nwinpos = win.Location + mousepos.Scale(win.Size) - mousepos.Scale(nwinsize); this._Window = new Rectangle(nwinpos, nwinsize).Intersection(this.Domain); } } }
/// <summary> /// Gets the selection index of a position with an x coordinate of X relative to the inner region of the textbox assuming that the selection is somewhere /// in the given text region. /// </summary> private static int _SelectedIndex(Rectangle[] CharacterBounds, double X, int Index, int Length) { int midi = Index + Length / 2; Rectangle midr = CharacterBounds[midi]; double mid = midr.Location.X + midr.Size.X / 2.0; if (Length == 1) { if (X > mid) { return Index + 1; } else { return Index; } } else { if (X > mid) { return _SelectedIndex(CharacterBounds, X, midi, Index + Length - midi); } else { return _SelectedIndex(CharacterBounds, X, Index, midi - Index); } } }
public override void Render(GUIRenderContext Context) { if (this._Text != null && this._Text != "") { if (this._Sample == null) { this._CreateSample(); } //Context.DrawText(this._Color, this._Sample, new Rectangle(this.Size)); /* Skin s = this._Style.Skin; Context.DrawSurface(s.GetSurface(this._Style.Textbox, this.Size)); */ Rectangle inner = new Rectangle(this.Size); Context.PushClip(inner); // Draw text Point texloc = new Point(inner.Location.X, inner.Location.Y + inner.Size.Y / 2.0 - this._Sample.Size.Y / 2.0); Context.DrawText(this._Color, this._Sample, texloc); // Draw selection if (this._Selection != null) { int starti; int endi; this._Selection.Order(out starti, out endi); Rectangle[] charbounds = this._Sample.CharacterBounds; if (endi - starti > 0) { double startx = inner.Location.X + Textbox.SelectionX(charbounds, starti); double endx = inner.Location.X + Textbox.SelectionX(charbounds, endi); Rectangle clip = new Rectangle(startx, inner.Location.Y, endx - startx, inner.Size.Y); Context.PushClip(clip); Context.DrawSolid(this._Style.SelectionBackgroundColor, clip); Context.DrawText(this._Style.SelectionTextColor, this._Sample, texloc); Context.Pop(); } } Context.Pop(); } }
/// <summary> /// Renders the item to the specified location. /// </summary> public void Render(GUIRenderContext Context, PopupStyle Style, Rectangle Area) { CommandMenuItem cmi = Source as CommandMenuItem; if (cmi != null) { Context.DrawText(Style.TextColor, this.Sample, Area); } CompoundMenuItem cpmi = Source as CompoundMenuItem; if (cpmi != null) { Context.DrawText(Style.TextColor, this.Sample, Area); Point arrowsize = Style.CompoundArrowSize; Context.DrawSurface( Style.Skin.GetSurface(Style.CompoundArrow, arrowsize), new Point(Area.Location.X + Area.Size.X - arrowsize.X, Area.Location.Y + Area.Size.Y * 0.5 - arrowsize.Y * 0.5)); } SeperatorMenuItem smi = Source as SeperatorMenuItem; if (smi != null) { Context.DrawSurface( Style.Skin.GetSurface(Style.Seperator, new Point(Area.Size.X, Style.SeperatorHeight)), Area.Location + new Point(0.0, Style.SeperatorPadding)); } }
/// <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); } }
/// <summary> /// Gets the item rectangle for an item, given the inner rectangle. /// </summary> private Rectangle _ItemRect(Rectangle Inner, _Item Item) { return new Rectangle(0.0, Item.Y + Inner.Location.Y, this.Size.X, Item.Size.Y); }
/// <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); }
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(); } }
public override void Render(GUIRenderContext Context) { PopupStyle style = this._Style; Skin s = style.Skin; Context.DrawSurface(s.GetSurface(style.Back, this.Size)); Rectangle inner = new Rectangle(this.Size).Margin(this._Style.Margin); foreach (_Item i in this._Items) { if (this._Active == i) { SkinArea sa = this._MouseDown ? style.PushedItem : style.ActiveItem; Context.DrawSurface(s.GetSurface(sa, new Point(this.Size.X, i.Size.Y)), new Point(0.0, i.Y + inner.Location.Y)); } i.Render(Context, style, new Rectangle(0.0, i.Y, inner.Size.X, i.Size.Y) + inner.Location); } }
/// <summary> /// Gets the x coordinate of the selection when its at the specified index. /// </summary> public static double SelectionX(Rectangle[] CharacterBounds, int Index) { if (Index < CharacterBounds.Length) { return CharacterBounds[Index].Location.X; } else { if (CharacterBounds.Length == 0) { return 0.0; } else { Rectangle r = CharacterBounds[CharacterBounds.Length - 1]; return r.Location.X + r.Size.X; } } }
public override void Render(GUIRenderContext Context) { Skin s = this._Style.Skin; Context.DrawSurface(s.GetSurface(this._Style.Textbox, this.Size)); Rectangle inner = new Rectangle(this.Size).Margin(this._Style.InteriorMargin); Context.PushClip(inner); // Draw text Point texloc = new Point(inner.Location.X, inner.Location.Y + inner.Size.Y / 2.0 - this._TextSample.Size.Y / 2.0); Context.DrawText(this._Style.TextColor, this._TextSample, texloc); // Draw selection if (this._Selection != null) { int starti; int endi; this._Selection.Order(out starti, out endi); Rectangle[] charbounds = this._TextSample.CharacterBounds; if (endi - starti > 0) { double startx = inner.Location.X + SelectionX(charbounds, starti); double endx = inner.Location.X + SelectionX(charbounds, endi); Rectangle clip = new Rectangle(startx, inner.Location.Y, endx - startx, inner.Size.Y); Context.PushClip(clip); Context.DrawSolid(this._Style.SelectionBackgroundColor, clip); Context.DrawText(this._Style.SelectionTextColor, this._TextSample, texloc); Context.Pop(); } // Draw cursor if (_CursorFlashTime > 0.0) { int curi = this._Selection.Start; double cursx = inner.Location.X + SelectionX(charbounds, curi); Context.DrawSolid(this._Style.CursorColor, new Rectangle(cursx, inner.Location.Y, 1.0, inner.Size.Y)); } } Context.Pop(); }
public override void Render(GUIRenderContext Context) { CheckboxStyle style = this._Style; Skin s = style.Skin; Surface surfbox = s.GetSurface(style.Box, style.BoxSize); Context.DrawSurface(surfbox); if(this.Checked) { Surface surftick = s.GetSurface(style.Tick, style.BoxSize); Context.DrawSurface(surftick); } Rectangle textrect = new Rectangle(style.BoxSize.X + style.Padding, 0, this.Size.X - style.BoxSize.X, this.Size.Y); if(this._Sample == null) this._Sample = style.TextFont.CreateSample(this._Text, textrect.Size, TextAlign.Left, TextAlign.Top, TextWrap.Wrap); Context.DrawText(style.TextColor, this._Sample, textrect); }
public override void Render(GUIRenderContext Context) { Rectangle clirect = this.ClientRectangle; // Back Context.DrawSolid(this._Style.BackColor, clirect); // Client Context.PushTranslate(clirect.Location); this._Client.Render(Context); Context.Pop(); // Form Skin s = this._Style.Skin; Context.DrawSurface(s.GetSurface(this._Style.Form, this._Style.Form.Width / 2, this._Style.FormVerticalStretchLine, this.Size)); // Right of the title bar. Context.PushTranslate(this._RightTitleBarOffset); this._RightTitleBar.Render(Context); Context.Pop(); // Text if (this._Text != null && this._Text != "") { Rectangle textrect = new Rectangle( this._Style.TitleBarLeftRightMargin, this._Style.TitleBarTopMargin, this.Size.X - this._Style.TitleBarLeftRightMargin - this._RightTitleBar.Size.X - this._Style.TitleBarItemSeperation, this._Style.TitleBarSize - this._Style.TitleBarTopMargin - this._Style.TitleBarBottomMargin); if (this._TextSample == null) { this._TextSample = this._Style.TitleBarFont.CreateSample(this._Text, textrect.Size, TextAlign.Left, TextAlign.Center, TextWrap.Ellipsis); } Context.DrawText(this._Style.TitleBarTextColor, this._TextSample, textrect); } }