Ejemplo n.º 1
0
        private bool AnimateEntry(RenderElementDisplay display, IUserInterfaceRenderContext renderContext, RenderElementAnimator animation)
        {
            animation.Alpha +=
                (float)renderContext.GameTime.ElapsedGameTime.TotalSeconds
                / transitionTime;

            if (animation.Alpha >= 1)
            {
                animation.Alpha = 1;
                animation.AnimatedBorderRect = display.BorderRect;

                return(true);
            }

            const float shrinkMax = 0.1f;
            float       shrink    = shrinkMax * MathF.Pow(1 - animation.Alpha, 3);

            float leftRightMargin = shrink * display.BorderRect.Width;
            float topBottomMargin = shrink * display.BorderRect.Height;

            animation.AnimatedBorderRect = new Rectangle(
                display.BorderRect.X + (int)leftRightMargin,
                display.BorderRect.Y + (int)leftRightMargin,
                display.BorderRect.Width - (int)(2 * leftRightMargin),
                display.BorderRect.Height - (int)(2 * leftRightMargin));

            Log.Debug($"Alpha: {animation.Alpha} BorderRect: {display.BorderRect} AnimatedBorderRect: {animation.AnimatedBorderRect}");

            return(false);
        }
Ejemplo n.º 2
0
        private bool AnimateExit(RenderElementDisplay display, IUserInterfaceRenderContext renderContext, RenderElementAnimator animation)
        {
            animation.Alpha -=
                (float)renderContext.GameTime.ElapsedGameTime.TotalSeconds
                / transitionTime;

            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 * display.BorderRect.Width;
            float topBottomMargin = shrink * display.BorderRect.Height;

            animation.AnimatedBorderRect = new Rectangle(
                display.BorderRect.X + (int)leftRightMargin,
                display.BorderRect.Y + (int)leftRightMargin,
                display.BorderRect.Width - (int)(2 * leftRightMargin),
                display.BorderRect.Height - (int)(2 * leftRightMargin));

            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks if the render target needs to be initialized and does it.
        /// Returns true if a new render target was created. False othewise.
        /// </summary>
        /// <param name="display"></param>
        /// <returns></returns>
        public bool InitializeRenderTarget(RenderElementDisplay display, GraphicsDevice graphicsDevice)
        {
            var animation = display.Animation;


            if (animation.RenderTarget == null ||
                animation.RenderTarget.Width != display.MarginRect.Width ||
                animation.RenderTarget.Height != display.MarginRect.Height)
            {
                animation.RenderTarget?.Dispose();

                var size = display.MarginRect;

                if (size.Width < 1)
                {
                    size.Width = 1;
                }
                if (size.Height < 1)
                {
                    size.Height = 1;
                }

                animation.RenderTarget = new RenderTarget2D(
                    graphicsDevice,
                    size.Width,
                    size.Height);

                return(true);
            }

            return(false);
        }
        public void DrawBackground(IUserInterfaceRenderContext renderContext, RenderElementDisplay display, Rectangle clientDest)
        {
            if (display.Style.Background == null)
            {
                return;
            }

            // 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
            var borderLayout = display.Style.Border.ToLayoutBox();

            Rectangle backgroundRect = new Rectangle(
                clientDest.X - display.Region.BorderToContentOffset.Left + borderLayout.Left / 2,
                clientDest.Y - display.Region.BorderToContentOffset.Top + borderLayout.Top / 2,
                display.BorderRect.Width - borderLayout.Width / 2,
                display.BorderRect.Height - borderLayout.Height / 2);

            styleRenderer.DrawBackground(
                renderContext.SpriteBatch,
                display.Style.Background,
                backgroundRect);
        }
 public void DrawFrame(IUserInterfaceRenderContext renderContext, RenderElementDisplay display, Rectangle clientDest)
 {
     styleRenderer.DrawFrame(
         renderContext.SpriteBatch,
         display.Style.Border,
         new Rectangle(
             new Point(clientDest.X - display.Region.BorderToContentOffset.Left,
                       clientDest.Y - display.Region.BorderToContentOffset.Top),
             display.BorderRect.Size));
 }
Ejemplo n.º 6
0
        public bool Update(RenderElementDisplay display, IUserInterfaceRenderContext renderContext)
        {
            var animator = display.Animation;

            animator.IsVisible           = display.IsVisible;
            animator.AnimatedContentRect = display.ContentRect;
            animator.AnimatedBorderRect  = display.BorderRect;
            animator.Alpha = 1;

            return(true);
        }
Ejemplo n.º 7
0
        public bool Update(RenderElementDisplay display, IUserInterfaceRenderContext renderContext)
        {
            var animation = display.Animation;

            animation.IsVisible = true;

            if (animation.State == AnimationState.TransitionIn)
            {
                return(AnimateEntry(display, renderContext, animation));
            }
            else if (animation.State == AnimationState.TransitionOut)
            {
                return(AnimateExit(display, renderContext, animation));
            }

            return(true);
        }
Ejemplo n.º 8
0
        public static void Configure(this IAnimationFactory animationFactory, RenderElementDisplay display)
        {
            if (display.Style.Animation == null)
            {
                display.Animation.In     = display.Animation.In ?? animationFactory.Create("default", null);
                display.Animation.Out    = display.Animation.Out ?? animationFactory.Create("default", null);
                display.Animation.Static = display.Animation.Static ?? animationFactory.Create("default", null);

                return;
            }

            // Currently, we don't support updating animators when the style changes unless the name of the
            // animator type has changed. I don't see a good use case for supporting this at the moment. -EY
            if (display.Animation.InType != display.Style.Animation.EntryName)
            {
                display.Animation.InType = display.Style.Animation.EntryName;
                display.Animation.In     = animationFactory.Create(display.Style.Animation.EntryName, display.Style.Animation.EntryArgs);
            }

            if (display.Animation.OutType != display.Style.Animation.ExitName)
            {
                display.Animation.OutType = display.Style.Animation.ExitName;
                display.Animation.Out     = animationFactory.Create(display.Style.Animation.ExitName, display.Style.Animation.ExitArgs);
            }

            if (display.Animation.StaticType != display.Style.Animation.StaticName)
            {
                display.Animation.StaticType = display.Style.Animation.StaticName;
                display.Animation.Static     = animationFactory.Create(display.Style.Animation.StaticName, display.Style.Animation.StaticArgs);
            }

            if (display.Animation.In == null)
            {
                display.Animation.In = display.Animation.In ?? animationFactory.Create("default", null);
            }

            if (display.Animation.Out == null)
            {
                display.Animation.Out = display.Animation.Out ?? animationFactory.Create("default", null);
            }

            if (display.Animation.Static == null)
            {
                display.Animation.Static = display.Animation.Static ?? animationFactory.Create("default", null);
            }
        }
Ejemplo n.º 9
0
 public void Initialize(RenderElementDisplay display)
 {
 }
Ejemplo n.º 10
0
 public void ContentRectUpdated(RenderElementDisplay display)
 {
     display.Animation.AnimatedContentRect = display.ContentRect;
     display.Animation.AnimatedBorderRect  = display.BorderRect;
 }
Ejemplo n.º 11
0
 public void Initialize(RenderElementDisplay display)
 {
     display.Animation.Alpha = 0;
 }
Ejemplo n.º 12
0
 public void ContentRectUpdated(RenderElementDisplay display)
 {
 }
Ejemplo n.º 13
0
 public RenderElementAnimator(RenderElementDisplay display)
 {
     this.display = display;
 }