public void Draw(SpriteBatch spriteBatch, string label, Texture2D icon, Rectangle frame) { image.Draw(spriteBatch, frame, fillColor); // MagicUI.Draw9Grid(spriteBatch, texture, frame, fillColor); // spriteBatch.Draw(texture, frame, fillColor); if (icon != null) { if (font != null) { // icon and text Vector2 labelSize = font.MeasureString(label); float iconSpacing = 2; Vector2 iconOrigin = frame.Center.ToVector2() + textOffset - new Vector2(labelSize.X + icon.Width + iconSpacing, icon.Height) / 2; Vector2 textOrigin = new Vector2((int)(iconOrigin.X + icon.Width + iconSpacing), (int)(frame.Center.Y + textOffset.Y - labelSize.Y / 2)); spriteBatch.Draw(icon, iconOrigin, Color.White); spriteBatch.DrawString(font, label, textOrigin, textColor); } else { // icon only spriteBatch.Draw(icon, frame.Center.ToVector2() + textOffset - icon.Size() / 2, Color.White); } } else if (font != null) { // text only Vector2 labelSize = font.MeasureString(label); spriteBatch.DrawString(font, label, new Vector2((float)Math.Floor(frame.Center.X + textOffset.X - labelSize.X / 2), (float)Math.Floor(frame.Center.Y + textOffset.Y - labelSize.Y / 2)), textColor); } }
public static void DrawTooltip(SpriteBatch spriteBatch, SpriteFont font, RichImage bg, List <string> text, Vector2 origin, Align align) { float lineHeight = 0; float maxWidth = 0; foreach (string s in text) { Vector2 lineSize = font.MeasureString(s); if (lineSize.X > maxWidth) { maxWidth = lineSize.X; } if (lineSize.Y > lineHeight) { lineHeight = lineSize.Y; } } Vector2 padding = new Vector2(4, 2); if (align == Align.RIGHT) { origin.X -= (maxWidth + padding.X * 2); } else if (align == Align.CENTER) { origin.X -= (int)((maxWidth + padding.X * 2) / 2); } bg.Draw(spriteBatch, new Rectangle((int)origin.X, (int)origin.Y, (int)(maxWidth + padding.X * 2), (int)(text.Count * lineHeight + padding.Y * 2))); Vector2 stringPos = origin + new Vector2(padding.X, padding.Y); foreach (string s in text) { spriteBatch.DrawString(font, s, stringPos, Color.Black); stringPos = new Vector2(stringPos.X, stringPos.Y + lineHeight); } }
public static void Draw(this SpriteBatch spriteBatch, RichImage image, Rectangle rect, Color col) { image.Draw(spriteBatch, rect, col); }
public void Draw(SpriteBatch spriteBatch, Rectangle rect, Color col, Rotation90 aRotation) { image.Draw(spriteBatch, rect, col, rotation.rotateBy(aRotation)); }