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); }
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); }
/// <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)); }
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); }
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); }
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); } }
public void Initialize(RenderElementDisplay display) { }
public void ContentRectUpdated(RenderElementDisplay display) { display.Animation.AnimatedContentRect = display.ContentRect; display.Animation.AnimatedBorderRect = display.BorderRect; }
public void Initialize(RenderElementDisplay display) { display.Animation.Alpha = 0; }
public void ContentRectUpdated(RenderElementDisplay display) { }
public RenderElementAnimator(RenderElementDisplay display) { this.display = display; }