public RenderElementDisplay(RenderElementProps props) { style = new RenderElementStyle(this, props); Region = new RenderElementRegion(Style); Animation = new RenderElementAnimator(this); }
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); }