本文整理匯總了C#中Alignment.HasFlag方法的典型用法代碼示例。如果您正苦於以下問題:C# Alignment.HasFlag方法的具體用法?C# Alignment.HasFlag怎麽用?C# Alignment.HasFlag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Alignment
的用法示例。
在下文中一共展示了Alignment.HasFlag方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DrawString
public static void DrawString(this SpriteBatch batch, SpriteFont font, string text, Rectangle bounds, Alignment align, Color color)
{
Vector2 size = font.MeasureString(text);
Point pos = bounds.Center;
Vector2 origin = size * 0.5f;
if (align.HasFlag(Alignment.Left))
origin.X += bounds.Width / 2 - size.X / 2;
if (align.HasFlag(Alignment.Right))
origin.X -= bounds.Width / 2 - size.X / 2;
if (align.HasFlag(Alignment.Top))
origin.Y += bounds.Height / 2 - size.Y / 2;
if (align.HasFlag(Alignment.Bottom))
origin.Y -= bounds.Height / 2 - size.Y / 2;
batch.DrawString(font, new StringBuilder(text), new Vector2(pos.X,pos.Y), color, 0f, origin, 1, SpriteEffects.None, 0);
}
示例2: DrawString
public static void DrawString(this SpriteBatch spriteBatch, SpriteFont font, string text,
Rectangle bounds, Alignment align, Color color)
{
Vector2 size = font.MeasureString(text);
Vector2 pos = bounds.Center.ToVector2();
Vector2 origin = size*0.5f;
if (align.HasFlag(Alignment.Left))
origin.X += bounds.Width*0.5f - size.X*0.5f;
if (align.HasFlag(Alignment.Right))
origin.X -= bounds.Width*0.5f - size.X*0.5f;
if (align.HasFlag(Alignment.Top))
origin.Y += bounds.Height*0.5f - size.Y*0.5f;
if (align.HasFlag(Alignment.Bottom))
origin.Y -= bounds.Height*0.5f - size.Y*0.5f;
spriteBatch.DrawString(font, text, pos, color, 0, origin, 1, SpriteEffects.None, 0);
}
示例3: DrawString
public void DrawString(SpriteFont spfont, string text, Rectangle bounds, Alignment align, Color color)
{
Vector2 size = spfont.MeasureString(text);
Vector2 pos = new Vector2(bounds.Center.X, bounds.Center.Y);
Vector2 origin = size * 0.5f;
if (align.HasFlag(Alignment.Left))
origin.X += bounds.Width / 2 - size.X / 2;
if (align.HasFlag(Alignment.Right))
origin.X -= bounds.Width / 2 - size.X / 2;
if (align.HasFlag(Alignment.Top))
origin.Y += bounds.Height / 2 - size.Y / 2;
if (align.HasFlag(Alignment.Bottom))
origin.Y -= bounds.Height / 2 - size.Y / 2;
spriteBatch.DrawString(spfont, text, pos, color, 0, origin, 1, SpriteEffects.None, 0);
}
示例4: DrawAlignedStrokedText
public static void DrawAlignedStrokedText(SpriteBatch batch, string text, SpriteFont font, Color textColor, Color strokeColor, Alignment align, Rectangle bounds)
{
Vector2 size = font.MeasureString(text);
Vector2 pos = new Vector2(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2);
Vector2 origin = size * 0.5f;
if (align.HasFlag(Alignment.Left))
origin.X += bounds.Width / 2 - size.X / 2;
if (align.HasFlag(Alignment.Right))
origin.X -= bounds.Width / 2 - size.X / 2;
if (align.HasFlag(Alignment.Top))
origin.Y += bounds.Height / 2 - size.Y / 2;
if (align.HasFlag(Alignment.Bottom))
origin.Y -= bounds.Height / 2 - size.Y / 2;
batch.DrawString(font, text, pos - new Vector2(1, 0), strokeColor, 0, origin, 1, SpriteEffects.None, 0);
batch.DrawString(font, text, pos + new Vector2(1, 0), strokeColor, 0, origin, 1, SpriteEffects.None, 0);
batch.DrawString(font, text, pos + new Vector2(0, 1), strokeColor, 0, origin, 1, SpriteEffects.None, 0);
batch.DrawString(font, text, pos - new Vector2(0, 1), strokeColor, 0, origin, 1, SpriteEffects.None, 0);
batch.DrawString(font, text, pos, textColor, 0, origin, 1, SpriteEffects.None, 0);
}
示例5: DrawAlignedText
public static void DrawAlignedText(SpriteBatch batch, string origText, SpriteFont font, Color textColor, Alignment align, Rectangle bounds, bool wrap = false)
{
string text = origText;
if (wrap)
{
text = DwarfGUI.WrapLines(text, bounds, font);
}
Vector2 size = Datastructures.SafeMeasure(font, text);
Vector2 pos = new Vector2(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2);
Vector2 origin = size * 0.5f;
if(align.HasFlag(Alignment.Left))
{
pos.X -= bounds.Width / 2 - size.X / 2;
}
if(align.HasFlag(Alignment.Right))
{
pos.X += bounds.Width / 2 - size.X / 2;
}
if(align.HasFlag(Alignment.Top))
{
pos.Y -= bounds.Height / 2 - size.Y / 2;
}
if(align.HasFlag(Alignment.Bottom))
{
pos.Y += bounds.Height / 2 - size.Y / 2;
}
if (align.HasFlag(Alignment.Under))
{
pos.Y += bounds.Height/2 + size.Y/2;
}
SafeDraw(batch, text, font, textColor, pos, origin);
}
示例6: Align
public static Rectangle Align(Rectangle bounds, int width, int height, Alignment align)
{
Vector2 size = new Vector2(width, height);
Vector2 pos = new Vector2(bounds.X + bounds.Width / 2 - width/2, bounds.Y + bounds.Height / 2 - height);
Vector2 origin = size * 0.5f;
if (align.HasFlag(Alignment.Left))
{
origin.X -= bounds.Width / 2;
}
if (align.HasFlag(Alignment.Right))
{
origin.X += bounds.Width / 2;
}
if (align.HasFlag(Alignment.Top))
{
origin.Y += bounds.Height / 2;
}
if (align.HasFlag(Alignment.Bottom))
{
origin.Y -= bounds.Height / 2;
}
if (align.HasFlag(Alignment.Under))
{
origin.Y -= bounds.Height;
}
Vector2 corner = origin + pos;
return new Rectangle((int)corner.X, (int)corner.Y, width, height);
}