public void DrawItem(SpriteBatch batch, SObject @object, Vector2 rectLocation, Vector2 rectSize, Color color, UIAnchorSide rectAnchorSide = UIAnchorSide.TopLeft, Vector2?scale = null, float layerDepth = 0f) { var texture = GetItemTexture(@object); var sourceRectangle = GetItemSourceRectangle(@object); var itemSize = new Vector2(sourceRectangle.Size.X, sourceRectangle.Size.Y); if (itemSize.X < rectSize.X && itemSize.Y < rectSize.Y) { itemSize *= Math.Max(rectSize.X, rectSize.Y); } if (itemSize.X > rectSize.X) { itemSize = itemSize / itemSize.X * rectSize.X; } if (itemSize.Y > rectSize.Y) { itemSize = itemSize / itemSize.Y * rectSize.Y; } var itemPosition = rectAnchorSide.GetAnchorPoint( new Vector2( rectLocation.X + (rectSize.X - itemSize.X) * 0.5f, rectLocation.Y + (rectSize.Y - itemSize.Y) * 0.5f ), -rectSize ); var finalScale = itemSize.X / sourceRectangle.Width; var origin = new Vector2(sourceRectangle.Width * 0.5f, sourceRectangle.Height); batch.Draw(texture, itemPosition + origin * finalScale, sourceRectangle, color, 0f, origin, finalScale * (scale ?? Vector2.One), SpriteEffects.None, layerDepth); if (@object is ColoredObject coloredObject) { batch.Draw(texture, itemPosition + origin * finalScale, GetColoredItemSourceRectangle(coloredObject), Color.Lerp(color, coloredObject.color.Value, 0.5f), 0f, origin, finalScale * (scale ?? Vector2.One), SpriteEffects.None, layerDepth); } }
public Vector2 GetAnchoredPoint(Vector2 fromLocation, Vector2 fromSize, Vector2 toSize) => From.GetAnchorPoint(fromLocation, fromSize) - To.GetAnchorPoint(Vector2.Zero, toSize) + Offset;