1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
51 private readonly
float minBorderScale = 0.1f, maxBorderScale = 10.0f;
67 if (Enum.TryParse(transitionMode, ignoreCase:
true, out
TransitionMode transition))
74 if (sliceVec != Vector4.Zero)
79 Rectangle slice =
new Rectangle((
int)sliceVec.X, (
int)sliceVec.Y, (
int)(sliceVec.Z - sliceVec.X), (
int)(sliceVec.W - sliceVec.Y));
112 if (!
Slice) {
return 1.0f; }
114 Vector2 scale =
new Vector2(
115 MathHelper.Clamp((
float)drawSize.X / (
Slices[0].Height +
Slices[6].Height), 0, 1),
116 MathHelper.Clamp((
float)drawSize.Y / (
Slices[0].Width +
Slices[2].Width), 0, 1));
117 return MathHelper.Clamp(Math.Min(Math.Min(scale.X, scale.Y), GUI.SlicedSpriteScale), minBorderScale, maxBorderScale);
120 public void Draw(SpriteBatch spriteBatch, RectangleF rect, Color color, SpriteEffects spriteEffects = SpriteEffects.None, Vector2? uvOffset =
null)
121 =>
Draw(spriteBatch,
new Rectangle(rect.Location.ToPoint(), rect.Size.ToPoint()), color, spriteEffects, uvOffset);
123 public void Draw(SpriteBatch spriteBatch, Rectangle rect, Color color, SpriteEffects spriteEffects = SpriteEffects.None, Vector2? uvOffset =
null)
125 uvOffset ??= Vector2.Zero;
128 GUI.DrawRectangle(spriteBatch, rect, Color.Magenta);
134 Vector2 pos =
new Vector2(rect.X, rect.Y);
139 int centerHeight = rect.Height - (int)((
Slices[0].Height +
Slices[6].Height) * scale);
140 int centerWidth = rect.Width - (int)((
Slices[0].Width +
Slices[2].Width) * scale * aspectScale);
142 for (
int x = 0; x < 3; x++)
145 int width = (int)(x == 1 ? centerWidth :
Slices[x].Width * scale * aspectScale);
146 if (width <= 0) {
continue; }
147 for (
int y = 0; y < 3; y++)
149 int height = (int)(y == 1 ? centerHeight :
Slices[x + y * 3].Height * scale);
150 if (height <= 0) {
continue; }
153 new Rectangle((
int)pos.X, (int)pos.Y, width, height),
165 Vector2 startPos =
new Vector2(rect.X, rect.Y);
166 Sprite.
DrawTiled(spriteBatch, startPos,
new Vector2(rect.Width, rect.Height), color: color, startOffset: uvOffset);
180 effects: spriteEffects, layerDepth: 0.0f);
string? GetAttributeString(string key, string? def)
Vector4 GetAttributeVector4(string key, in Vector4 def)
float GetAttributeFloat(string key, float def)
bool GetAttributeBool(string key, bool def)
void DrawTiled(ISpriteBatch spriteBatch, Vector2 position, Vector2 targetSize, float rotation=0f, Vector2? origin=null, Color? color=null, Vector2? startOffset=null, Vector2? textureScale=null, float? depth=null, SpriteEffects? spriteEffects=null)
Point NonSliceSize
The size of fixed area around the slice area
UISprite(ContentXElement element)
bool MaintainBorderAspectRatio
float GetSliceBorderScale(Point drawSize)
Get the scale of the sliced sprite's borders when it's draw inside an area of a specific size
void Draw(SpriteBatch spriteBatch, RectangleF rect, Color color, SpriteEffects spriteEffects=SpriteEffects.None, Vector2? uvOffset=null)
void Draw(SpriteBatch spriteBatch, Rectangle rect, Color color, SpriteEffects spriteEffects=SpriteEffects.None, Vector2? uvOffset=null)