public void DrawImage(ITextArrayReader textImage, Point position, bool allowTransparency = true) { Verify.NotNull(textImage, nameof(textImage)); var intersection = new RectangleIntersection(Size.AsRectangle, textImage.Size.AsRectangle.Translate(position)); if (intersection.HasNoIntersection) { return; } var canvasSlice = intersection.RelativelyToRectOne; var imageSlice = intersection.RelativelyToRectTwo; int width = intersection.Intersection.Size.Width; int height = intersection.Intersection.Size.Height; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { TextCell?imageCell = textImage[imageSlice.Position.X + x, imageSlice.Position.Y + y]; if (imageCell is null && allowTransparency) { continue; } var dstPosition = new Point(canvasSlice.Position.X + x, canvasSlice.Position.Y + y); Write(dstPosition, imageCell); } } }
//====== override: GameModule public override void Initialize(GameTime gameTime) { if (!placement.HasValue) { return; } placementImage = new BigDigitsValueRenderer(placement.Value + 1, Lime).RenderImage(); }
//====== ctors protected ScreenTransition(ITextArrayReader prevGameModuleScreenSnapshot, TextCanvas canvas, GameTime gameTime) : base(gameTime) { Verify.NotNull(prevGameModuleScreenSnapshot, nameof(prevGameModuleScreenSnapshot)); this.canvas = Verify.NotNull(canvas, nameof(canvas)); if (prevGameModuleScreenSnapshot.Size.Equals(canvas.Size) == false) { throw new ArgumentException($"Sizes are not equal."); } this.prevGameModuleScreenSnapshot = TextImage.CreateCopyFrom(prevGameModuleScreenSnapshot); }
//====== public methods public void DrawCenter(TextCanvas canvas, int y) { int currentScore = scoreStatus.Value; if (lastScore != currentScore || lastImage is null) { lastImage = new BigDigitsValueRenderer(currentScore, ForeColor).RenderImage(); lastScore = currentScore; } int xOffset = (canvas.Size.Width / 2) - (lastImage.Size.Width / 2); canvas.DrawImage(lastImage, new Point(xOffset, y)); }
//====== public static methods public static TextImage CreateCopyFrom(ITextArrayReader textArray) { Verify.NotNull(textArray, nameof(textArray)); var result = new TextImage(textArray.Size); for (int x = 0; x < textArray.Size.Width; x++) { for (int y = 0; y < textArray.Size.Height; y++) { result.cells[x, y] = textArray[x, y]; } } return(result); }
//====== ctors public TransitionT1(ITextArrayReader prevScreenSnapshot, TextCanvas canvas, GameTime gameTime) : base(prevScreenSnapshot, canvas, gameTime) { borderWidth = GetMaxBorderWidth(); }
//====== ctors public TransitionT2(ITextArrayReader prevScreenSnapshot, TextCanvas canvas, GameTime gameTime) : base(prevScreenSnapshot, canvas, gameTime) { offset = canvas.Size.Width; }
public NullTransition(ITextArrayReader prevScreenSnapshot, TextCanvas canvas, GameTime gameTime) : base(prevScreenSnapshot, canvas, gameTime) { }