当前位置: 首页>>代码示例>>C#>>正文


C# Alignment.HasFlag方法代码示例

本文整理汇总了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);
        }
开发者ID:Haedrian,项目名称:Divine-Right,代码行数:20,代码来源:Extensions.cs

示例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);
        }
开发者ID:matheus2984,项目名称:SoulEngine,代码行数:21,代码来源:FontAlignment.cs

示例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);
        }
开发者ID:patrykos91,项目名称:Laikos,代码行数:20,代码来源:StringTypingEffect.cs

示例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);
        }
开发者ID:careid,项目名称:myheartisinthework,代码行数:24,代码来源:Drawer2D.cs

示例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);
        }
开发者ID:scorvi,项目名称:dwarfcorp,代码行数:39,代码来源:Drawer2D.cs

示例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);
        }
开发者ID:scorvi,项目名称:dwarfcorp,代码行数:36,代码来源:Drawer2D.cs


注:本文中的Alignment.HasFlag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。