本文整理汇总了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);
}