當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。