示例#1
0
        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));
        }
示例#3
0
        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;
            }
        }
示例#4
0
        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));
        }
示例#5
0
        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);
        }
示例#7
0
        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);
        }
示例#9
0
        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;
        }
示例#10
0
        public override void Update(IWidgetRenderContext renderContext)
        {
            base.Update(renderContext);

            if (Layout.Focus == null && Layout.Count > 0)
            {
                Layout.Focus = Layout.First();
            }
        }
示例#11
0
 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));
 }
示例#12
0
 public override Size ComputeIdealSize(IWidgetRenderContext renderContext, Size maxSize)
 {
     if (string.IsNullOrEmpty(Text))
     {
         return(Display.Font.MeasureString("M"));
     }
     else
     {
         return(Display.Font.MeasureString(Text));
     }
 }
示例#13
0
        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);
        }
示例#14
0
        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);
        }
示例#15
0
        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);
            }
        }
示例#16
0
        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;
        }
示例#18
0
        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));
        }
示例#19
0
        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);
        }
示例#20
0
        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);
        }
示例#21
0
 public virtual void TheDrawFocus(IWidgetRenderContext renderContext, IWidget widget, Rectangle destRect)
 {
 }
示例#22
0
 public override void Draw(IWidgetRenderContext renderContext, Point offset)
 {
     Display.Font.DrawText(renderContext.SpriteBatch,
                           offset.ToVector2(), Text);
 }
示例#23
0
 protected virtual void DrawPointer(IWidgetRenderContext renderContext, Rectangle pointerDest)
 {
     renderContext.SpriteBatch.Draw(texture, pointerDest, Color.White);
 }
示例#24
0
 public override void Update(IWidgetRenderContext renderContext)
 {
 }
示例#25
0
 public override void Draw(IWidgetRenderContext renderContext, Point offset)
 {
     throw new NotImplementedException();
 }
示例#26
0
 protected override void DrawPointer(IWidgetRenderContext renderContext, Rectangle pointerDest)
 {
     draws.Add(pointerDest);
 }
示例#27
0
 public override Size ComputeIdealSize(IWidgetRenderContext renderContext, Size maxSize)
 {
     return(tabLayout.RecalculateSize(this, renderContext, maxSize));
 }
示例#28
0
 public void DrawFocus(IWidgetRenderContext renderContext, Workspace workspace)
 {
     throw new NotImplementedException();
 }
示例#29
0
 public override void Update(IWidgetRenderContext renderContext)
 {
     throw new NotImplementedException();
 }
示例#30
0
 public void EndDraw(IWidgetRenderContext renderContext)
 {
     throw new NotImplementedException();
 }