public void Draw(IWidgetRenderContext renderContext) { contentLayoutOptions.Font = Font; contentLayoutOptions.MaxWidth = renderContext.Area.Width; var validItems = items.Where(kvp => kvp.Value.Visible && !string.IsNullOrWhiteSpace(kvp.Value.Text)); int totalWidth = 0; int count = 0; foreach (var itemKvp in validItems) { var item = itemKvp.Value; InitializeContent(renderContext, itemKvp.Key, item); totalWidth += item.Content.Size.Width + item.ButtonContent.Size.Width; count++; } totalWidth += (count - 1) * Margin; int x = (renderContext.Area.Width - totalWidth) / 2; foreach (var itemKvp in validItems) { DrawContent(renderContext, itemKvp.Value.ButtonContent, ref x); DrawContent(renderContext, itemKvp.Value.Content, ref x); x += Margin; } }
public void DrawFocus(IWidgetRenderContext renderContext, Rectangle destRect) { var alpha = 0.3f; // Color is yellow but we are premultiplying the alpha. renderContext.SpriteBatch.Draw(texture, destRect, new Color(alpha, alpha, 0, alpha)); }
public override void ApplyLayout(Size size, IWidgetRenderContext renderContext) { Point dest = new Point(0, 0); int itemWidth = size.Width; for (int i = 0; i < items.Count; i++) { if (!items[i].Display.IsVisible) { continue; } var item = items[i]; var itemDest = dest; var marginToContent = item.Display.Region.MarginToContentOffset; itemDest.X += marginToContent.Left; itemDest.Y += marginToContent.Top; item.Display.Region.Position = itemDest; var contentSize = item.Display.Region.Size.ComputeContentSize(); contentSize.Width = itemWidth - item.Display.Region.MarginToContentOffset.Width; item.Display.Region.ContentSize = contentSize; dest.Y += item.Display.Region.MarginRect.Height; item.Display.HasFocus = item == Focus; } }
public override Size ComputeIdealSize(Size maxSize, IWidgetRenderContext renderContext) { int idealWidth = 0; int idealHeight = 0; for (int i = 0; i < items.Count; i++) { var item = items[i]; if (!item.Display.IsVisible) { continue; } var itemBox = item.Display.Region.MarginToContentOffset; var itemMaxSize = LayoutMath.ItemContentMaxSize(itemBox, maxSize); item.RecalculateSize(renderContext, maxSize); var itemIdealContentSize = item.Display.Region.Size.IdealContentSize; idealWidth = Math.Max(idealWidth, itemIdealContentSize.Width + itemBox.Width); idealHeight += itemIdealContentSize.Height + itemBox.Height; } return(new Size(idealWidth, idealHeight)); }
public bool Update(IWidget menu, IWidgetRenderContext renderContext) { var animation = menu.Display.Animation; animation.IsVisible = true; animation.Alpha += (float)renderContext.GameTime.ElapsedGameTime.TotalSeconds / menu.Display.Style.Animation.TransitionInTime; if (animation.Alpha >= 1) { animation.Alpha = 1; animation.BorderRect = menu.Display.Region.BorderRect; return(true); } const float shrinkMax = 0.1f; float shrink = shrinkMax * MathF.Pow(1 - animation.Alpha, 3); float leftRightMargin = shrink * menu.Display.Region.BorderRect.Width; float topBottomMargin = shrink * menu.Display.Region.BorderRect.Height; animation.BorderRect = new Rectangle( menu.Display.Region.BorderRect.X + (int)leftRightMargin, menu.Display.Region.BorderRect.Y + (int)leftRightMargin, menu.Display.Region.BorderRect.Width - (int)(2 * leftRightMargin), menu.Display.Region.BorderRect.Height - (int)(2 * leftRightMargin)); return(false); }
public void CompleteRendering(Point parentContentDest, IWidgetRenderContext renderContext, IWidget widget) { var animation = widget.Display.Animation; var display = widget.Display; display.Animation.Buffer.RenderContext.SpriteBatch.End(); // Now use the parent render target. renderContext.GraphicsDevice.SetRenderTarget(renderContext.RenderTarget); var screenRect = animation.BorderRect; screenRect.X += parentContentDest.X; screenRect.Y += parentContentDest.Y; renderContext.SpriteBatch.Draw( animation.RenderTarget, screenRect, null, animation.Color, 0, Vector2.Zero, SpriteEffects.None, animation.LayerDepth); }
public bool Update(IWidget widget, IWidgetRenderContext renderContext) { var animation = widget.Display.Animation; animation.BorderRect = widget.Display.Region.BorderRect; animation.Alpha -= (float)renderContext.GameTime.ElapsedGameTime.TotalSeconds / widget.Display.Style.Animation.TransitionOutTime; if (animation.Alpha <= 0) { animation.Alpha = 0; animation.IsVisible = false; return(true); } const float shrinkMax = 0.1f; float shrink = shrinkMax * MathF.Pow(1 - animation.Alpha, 0.8f); float leftRightMargin = shrink * widget.Display.Region.BorderRect.Width; float topBottomMargin = shrink * widget.Display.Region.BorderRect.Height; animation.BorderRect = new Rectangle( widget.Display.Region.BorderRect.X + (int)leftRightMargin, widget.Display.Region.BorderRect.Y + (int)leftRightMargin, widget.Display.Region.BorderRect.Width - (int)(2 * leftRightMargin), widget.Display.Region.BorderRect.Height - (int)(2 * leftRightMargin)); return(false); }
public IWidgetRenderContext PrepRenderState(IWidget widget, IWidgetRenderContext renderContext) { var animation = widget.Display.Animation; var display = widget.Display; if (InitializeRenderTarget(display, renderContext.GraphicsDevice)) { if (display.Animation.Buffer.RenderContext == null) { display.Animation.Buffer.RenderContext = new WidgetRenderContext( (WidgetRenderContext)renderContext, new SpriteBatch(renderContext.GraphicsDevice), animation.RenderTarget); } display.Animation.Buffer.RenderContext.RenderTarget = animation.RenderTarget; } var newRenderContext = display.Animation.Buffer.RenderContext; newRenderContext.GameTime = renderContext.GameTime; newRenderContext.GraphicsDevice.SetRenderTarget(animation.RenderTarget); newRenderContext.GraphicsDevice.Clear(new Color(0, 0, 0, 0)); newRenderContext.GraphicsDevice.BlendState = blendState; newRenderContext.Indicator = renderContext.Indicator; newRenderContext.SpriteBatch.Begin(); widget.Display.Animation.Buffer.ContentDestination = new Point( display.Region.MarginToContentOffset.Left, display.Region.MarginToContentOffset.Top); return(newRenderContext); }
private static void DrawContent(IWidgetRenderContext renderContext, IContentLayout content, ref int x) { content.Draw( new Vector2(x, renderContext.Area.Height - content.Size.Height), renderContext.SpriteBatch); x += content.Size.Width; }
public override void Update(IWidgetRenderContext renderContext) { base.Update(renderContext); if (Layout.Focus == null && Layout.Count > 0) { Layout.Focus = Layout.First(); } }
public void DrawFrame(IWidgetRenderContext renderContext, WidgetDisplay display, Point dest) { styleRenderer.DrawFrame( renderContext.SpriteBatch, display.Style.Border, new Rectangle( new Point(dest.X - display.Region.BorderToContentOffset.Left, dest.Y - display.Region.BorderToContentOffset.Top), display.Region.BorderRect.Size)); }
public override Size ComputeIdealSize(IWidgetRenderContext renderContext, Size maxSize) { if (string.IsNullOrEmpty(Text)) { return(Display.Font.MeasureString("M")); } else { return(Display.Font.MeasureString(Text)); } }
public bool Update(IWidget owner, IWidgetRenderContext renderContext) { var animation = owner.Display.Animation; animation.IsVisible = owner.Display.IsVisible; animation.ContentRect = owner.Display.Region.ContentRect; animation.BorderRect = owner.Display.Region.BorderRect; animation.Alpha = 1; return(true); }
public override void TheDrawFocus(IWidgetRenderContext renderContext, IWidget widget, Rectangle destRect) { const int overlap = 1; Rectangle pointerDest = new Rectangle( destRect.Left - texture.Width + overlap, (destRect.Top + destRect.Bottom - texture.Height) / 2, texture.Width, texture.Height); DrawPointer(renderContext, pointerDest); }
private void InitializeContent(IWidgetRenderContext renderContext, Buttons key, InstructionItem item) { if (item.ButtonContent == null) { item.ButtonContent = renderContext.CreateContentLayout( "{Button " + key + "} ", contentLayoutOptions, localizeText: false); } if (item.Content == null) { item.Content = renderContext.CreateContentLayout(item.Text, contentLayoutOptions); } }
public void UpdateAnimation(IWidgetRenderContext renderContext, IWidget widget) { var animator = widget.Display.Animation; SetTransition(widget); bool finished = animator.Transition?.Update(widget, renderContext) ?? false; if (finished) { AdvanceTransitionState(widget); } }
public UserInterfaceSceneDriver(IWidgetRenderContext renderContext) { this.renderContext = renderContext; this.renderContext.BeforeUpdate += widget => widget.Display.Instructions = Desktop.Instructions; desktop = new Desktop(); Desktop.UnhandledEvent += Desktop_UnhandledEvent; uiInput.ButtonDown += desktop.ButtonDown; uiInput.ButtonUp += desktop.ButtonUp; }
public void DrawFocus(IWidgetRenderContext renderContext, Workspace workspace) { (IWidget focusWidget, Point offset) = FindFocus(workspace.Layout.Focus); if (focusWidget == null) { return; } if (!focusWidget.CanHaveFocus) { return; } TheDrawFocus(renderContext, focusWidget, new Rectangle(offset, focusWidget.Display.Region.ContentSize)); }
public override void Draw( IWidgetRenderContext renderContext, Point clientDest) { foreach (var child in Layout.Items) { if (child == Layout.Focus) { child.Display.Styles.SetActiveStyle("selected"); } else { child.Display.Styles.SetActiveStyle(""); } } renderContext.DrawChildren(clientDest, Layout.Items); }
public void DrawBackground(IWidgetRenderContext renderContext, WidgetDisplay display, Point dest) { // This draws the background behind the border - a problem for borders which have transparency on their outer edges // but important for borders which have transparency on their inner edges. Oh what to do... //Rectangle backgroundRect = new Rectangle( // new Point(dest.X - display.Region.BorderToContentOffset.Left, // dest.Y - display.Region.BorderToContentOffset.Top), // display.Region.BorderRect.Size); // Here we make a compromise and set the background rectangle to be slightly smaller than // the border rectangle Rectangle backgroundRect = new Rectangle( dest.X - display.Region.BorderToContentOffset.Left + display.Region.Style.Border.Left.Width / 2, dest.Y - display.Region.BorderToContentOffset.Top + display.Region.Style.Border.Top.Width / 2, display.Region.BorderRect.Width - display.Region.Style.Border.Width / 2, display.Region.BorderRect.Height - display.Region.Style.Border.Height / 2); styleRenderer.DrawBackground( renderContext.SpriteBatch, display.Style.Background, backgroundRect); }
public virtual void TheDrawFocus(IWidgetRenderContext renderContext, IWidget widget, Rectangle destRect) { }
public override void Draw(IWidgetRenderContext renderContext, Point offset) { Display.Font.DrawText(renderContext.SpriteBatch, offset.ToVector2(), Text); }
protected virtual void DrawPointer(IWidgetRenderContext renderContext, Rectangle pointerDest) { renderContext.SpriteBatch.Draw(texture, pointerDest, Color.White); }
public override void Update(IWidgetRenderContext renderContext) { }
public override void Draw(IWidgetRenderContext renderContext, Point offset) { throw new NotImplementedException(); }
protected override void DrawPointer(IWidgetRenderContext renderContext, Rectangle pointerDest) { draws.Add(pointerDest); }
public override Size ComputeIdealSize(IWidgetRenderContext renderContext, Size maxSize) { return(tabLayout.RecalculateSize(this, renderContext, maxSize)); }
public void DrawFocus(IWidgetRenderContext renderContext, Workspace workspace) { throw new NotImplementedException(); }
public override void Update(IWidgetRenderContext renderContext) { throw new NotImplementedException(); }
public void EndDraw(IWidgetRenderContext renderContext) { throw new NotImplementedException(); }