public void DrawHorizontalThreepatch(SpriteBatch spriteBatch, NinepatchRects destinationRects, Depth layerDepth) { Debug.Assert(this.rects.IsValidHorizontalThreepatch, "Attempted to draw an invalid horizontal Threepatch"); DrawSection(spriteBatch, NinepatchIndex.LeftCenter, destinationRects.LeftCenter, layerDepth); DrawSection(spriteBatch, NinepatchIndex.Center, destinationRects.Center, layerDepth); DrawSection(spriteBatch, NinepatchIndex.RightCenter, destinationRects.RightCenter, layerDepth); }
public void DrawVerticalThreepatch(SpriteBatch spriteBatch, NinepatchRects destinationRects, Depth layerDepth) { Debug.Assert(this.rects.IsValidVerticalThreepatch, "Attempted to draw an invalid vertical Threepatch"); DrawSection(spriteBatch, NinepatchIndex.TopCenter, destinationRects.TopCenter, layerDepth); DrawSection(spriteBatch, NinepatchIndex.Center, destinationRects.Center, layerDepth); DrawSection(spriteBatch, NinepatchIndex.BottomCenter, destinationRects.BottomCenter, layerDepth); }
public void DrawFullNinepatch(SpriteBatch spriteBatch, NinepatchRects destinationRects, Depth layerDepth, float opacity = 1f) { Debug.Assert(this.rects.isValidNinepatch, "Attempted to draw an invalid Ninepatch."); for (var i = 0; i < 9; i++) { var dest = destinationRects.raw[i]; var source = new Rectangle(0, 0, dest.Width, dest.Height); // Source is the size of the destination rect so we tile spriteBatch.Draw(this.textures[i], dest.Location.ToVector2(), source, Color.White.WithMultipliedOpacity(opacity), 0f, new Vector2(), Vector2.One, SpriteEffects.None, layerDepth.AsFloat); } }
public NinepatchSheet(Texture2D sourceTexture, Rectangle outerRect, Rectangle innerRect, Painter painter) { this.originalTexture = sourceTexture; Debug.Assert(sourceTexture.Width >= outerRect.Width, "Texture is to small"); Debug.Assert(sourceTexture.Height >= outerRect.Height, "Texture is to small"); this.rects = new NinepatchRects(outerRect, innerRect); this.textures = new Texture2D[9]; for (var i = 0; i < 9; i++) { var rect = this.rects.raw[i]; if (rect.Width * rect.Height > 0) { var cropTexture = painter.CropTexture(rect, sourceTexture); this.textures[i] = cropTexture; } } }