public void FillRectangle(Rectangle bounds, TextureSlice2D texture, TextureRepeatMode repeatMode, Vector2?scale = null) { if (scale == null) { scale = Vector2.One; } if (repeatMode == TextureRepeatMode.NoRepeat) { SpriteBatch.Draw(texture, bounds); } else if (repeatMode == TextureRepeatMode.Stretch) { SpriteBatch.Draw(texture, bounds); } else if (repeatMode == TextureRepeatMode.ScaleToFit) { } else if (repeatMode == TextureRepeatMode.Tile) { Vector2 size = texture.ClipBounds.Size.ToVector2() * scale.Value; var repeatX = Math.Ceiling((float)bounds.Width / size.X); var repeatY = Math.Ceiling((float)bounds.Height / size.Y); for (int i = 0; i < repeatX; i++) { for (int j = 0; j < repeatY; j++) { var p = bounds.Location.ToVector2() + new Vector2(i * size.X, j * size.Y); SpriteBatch.Draw(texture, p, scale); } } } else if (repeatMode == TextureRepeatMode.NoScaleCenterSlice) { var halfWidth = bounds.Width / 2f; var halfHeight = bounds.Height / 2f; int xOffset = bounds.X + (int)Math.Max(0, (bounds.Width - texture.Width) / 2f); int yOffset = bounds.Y + (int)Math.Max(0, (bounds.Height - texture.Height) / 2f); int dstLeftWidth = (int)Math.Floor(halfWidth); int dstRightWidth = (int)Math.Ceiling(halfWidth); int dstLeftHeight = (int)Math.Floor(halfHeight); int dstRightHeight = (int)Math.Ceiling(halfHeight); var srcHalfWidth = Math.Min(texture.Width / 2f, halfWidth); var srcHalfHeight = Math.Min(texture.Height / 2f, halfHeight); var srcX = texture.ClipBounds.X; var srcY = texture.ClipBounds.Y; int srcLeftWidth = (int)Math.Floor(srcHalfWidth); int srcRightWidth = (int)Math.Ceiling(srcHalfWidth); int srcLeftHeight = (int)Math.Floor(srcHalfHeight); int srcRightHeight = (int)Math.Ceiling(srcHalfHeight); // MinY MinX SpriteBatch.Draw(texture, new Rectangle(xOffset, yOffset, dstLeftWidth, dstLeftHeight), new Rectangle(srcX, srcY, srcLeftWidth, srcLeftHeight), Color.White); // MinY MaxX SpriteBatch.Draw(texture, new Rectangle(xOffset + dstLeftWidth, yOffset, dstRightWidth, dstRightHeight), new Rectangle(srcX + texture.Width - srcRightWidth, srcY, srcRightWidth, srcRightHeight), Color.White); // MaxY MinX SpriteBatch.Draw(texture, new Rectangle(xOffset, yOffset + dstLeftHeight, dstLeftWidth, dstLeftHeight), new Rectangle(srcX, srcY + texture.Height - srcRightHeight, srcLeftWidth, srcLeftHeight), Color.White); // MaxY MaxX SpriteBatch.Draw(texture, new Rectangle(xOffset + dstLeftWidth, yOffset + dstRightHeight, dstRightWidth, dstRightHeight), new Rectangle(srcX + texture.Width - srcRightWidth, srcY + texture.Height - srcRightHeight, srcRightWidth, srcRightHeight), Color.White); } }
protected override void OnInit(IGuiRenderer renderer) { SelectedBackground = renderer.GetTexture(GuiTextures.Inventory_HotBar_SelectedItemOverlay); //_counTextElement.Font = renderer.Font; base.OnInit(renderer); }