public void FillRectangle(Rectangle rectangle, ITexture2D texture, TextureRepeatMode repeatMode, Vector2?scale, Color?colorMask) { if (texture?.Texture == null) { return; } var mask = colorMask.HasValue ? colorMask.Value : Color.White; if (repeatMode == TextureRepeatMode.NoScaleCenterSlice) { DrawTextureCenterSliced(rectangle, texture, mask); } else if (repeatMode == TextureRepeatMode.Tile) { DrawTextureTiled(rectangle, texture, mask); } else if (repeatMode == TextureRepeatMode.ScaleToFit) { DrawTextureScaledToFit(rectangle, texture, mask); } else if (texture is NinePatchTexture2D ninePatchTexture) { DrawTextureNinePatch(rectangle, ninePatchTexture, mask); } else if (scale.HasValue) { SpriteBatch.Draw(texture.Texture, rectangle.Location.ToVector2(), texture.ClipBounds, mask, 0f, Vector2.Zero, scale.Value, SpriteEffects.None, 0f); } else { SpriteBatch.Draw(texture, rectangle, mask); } }
public GuiImage(NinePatchTexture2D background, TextureRepeatMode mode = TextureRepeatMode.Stretch) { Background = background; Background.RepeatMode = mode; Width = background.ClipBounds.Width; Height = background.ClipBounds.Height; }
public void Draw(TextureSlice2D texture, Rectangle bounds, TextureRepeatMode repeatMode = TextureRepeatMode.Stretch, Vector2?scale = null) { if (texture is NinePatchTexture2D ninePatch) { DrawNinePatch(bounds, ninePatch, repeatMode, scale); } else { FillRectangle(bounds, texture, repeatMode, scale); } }
public void FillRectangle(Rectangle rectangle, ITexture2D texture, TextureRepeatMode repeatMode = TextureRepeatMode.Stretch) { FillRectangle(rectangle, texture, repeatMode, null, Color.White); }
public GuiTexture2D(GuiTextures guiTexture, TextureRepeatMode repeatMode = TextureRepeatMode.Stretch, Vector2?scale = null) : this() { TextureResource = guiTexture; RepeatMode = repeatMode; Scale = scale; }
public GuiTexture2D(ITexture2D texture, TextureRepeatMode repeatMode = TextureRepeatMode.Stretch, Vector2?scale = null) : this() { Texture = texture; RepeatMode = repeatMode; Scale = scale; }
public GuiImage(GuiTextures texture, TextureRepeatMode mode = TextureRepeatMode.Stretch) { Background = texture; Background.RepeatMode = mode; }
public void SetWrapMode(TextureRepeatMode horizontal, TextureRepeatMode vertical, Color borderColor) { SetWrapMode(horizontal, vertical); GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureBorderColor, new[] { borderColor.Rgba }); }
public void SetWrapMode(TextureRepeatMode mode) { SetWrapMode(mode, mode); }
public void SetWrapMode(TextureRepeatMode horizontal, TextureRepeatMode vertical) { GL.BindTexture(TextureTarget.Texture2D, Id); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapR, (int)horizontal); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)vertical); }
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); } }
public void DrawNinePatch(Rectangle bounds, NinePatchTexture2D ninePatchTexture, TextureRepeatMode repeatMode, Vector2?scale = null) { if (scale == null) { scale = Vector2.One; } if (ninePatchTexture.Padding == Thickness.Zero) { FillRectangle(bounds, ninePatchTexture.Texture, repeatMode); return; } var sourceRegions = ninePatchTexture.SourceRegions; var destRegions = ninePatchTexture.ProjectRegions(bounds); for (var i = 0; i < sourceRegions.Length; i++) { var srcPatch = sourceRegions[i]; var dstPatch = destRegions[i]; if (dstPatch.Width > 0 && dstPatch.Height > 0) { SpriteBatch.Draw(ninePatchTexture, sourceRectangle: srcPatch, destinationRectangle: dstPatch); } } }