Exemple #1
0
 public void CombineAndBreak(DirH horiz, DirV vert, Dir8 dir)
 {
     Assert.That(DirExt.Combine(horiz, vert), Is.EqualTo(dir));
     dir.Separate(out DirH resH, out DirV resV);
     Assert.AreEqual(resH, horiz);
     Assert.AreEqual(resV, vert);
 }
Exemple #2
0
 public MenuText(string text, Loc loc, DirV alignV, DirH alignH, Color color)
 {
     Text   = text;
     Loc    = loc;
     AlignV = alignV;
     AlignH = alignH;
     Color  = color;
 }
Exemple #3
0
        public static Dir8 Combine(DirH horiz, DirV vert)
        {
            switch (vert)
            {
            case DirV.Down:
                switch (horiz)
                {
                case DirH.Right:
                    return(Dir8.DownRight);

                case DirH.Left:
                    return(Dir8.DownLeft);

                case DirH.None:
                    return(Dir8.Down);

                default:
                    throw new ArgumentOutOfRangeException(nameof(horiz), horiz, "Invalid enum value.");
                }

            case DirV.Up:
                switch (horiz)
                {
                case DirH.Right:
                    return(Dir8.UpRight);

                case DirH.Left:
                    return(Dir8.UpLeft);

                case DirH.None:
                    return(Dir8.Up);

                default:
                    throw new ArgumentOutOfRangeException(nameof(horiz), horiz, "Invalid enum value.");
                }

            case DirV.None:
                switch (horiz)
                {
                case DirH.Right:
                    return(Dir8.Right);

                case DirH.Left:
                    return(Dir8.Left);

                case DirH.None:
                    return(Dir8.None);

                default:
                    throw new ArgumentOutOfRangeException(nameof(horiz), horiz, "Invalid enum value.");
                }

            default:
                throw new ArgumentOutOfRangeException(nameof(vert), vert, "Invalid enum value.");
            }
        }
Exemple #4
0
 public void ToDir8(DirH dir, Dir8 expected, bool exception = false)
 {
     if (exception)
     {
         Assert.Throws <ArgumentOutOfRangeException>(() => { dir.ToDir8(); });
     }
     else
     {
         Assert.That(dir.ToDir8(), Is.EqualTo(expected));
     }
 }
Exemple #5
0
 public void Reverse(DirH dir, DirH expected, bool exception = false)
 {
     if (exception)
     {
         Assert.Throws <ArgumentOutOfRangeException>(() => { dir.Reverse(); });
     }
     else
     {
         Assert.That(dir.Reverse(), Is.EqualTo(expected));
         Assert.That(expected.Reverse(), Is.EqualTo(dir));
     }
 }
Exemple #6
0
        public static bool Validate(this DirH dir)
        {
            switch (dir)
            {
            case DirH.None:
            case DirH.Left:
            case DirH.Right:
                return(true);

            default:
                return(false);
            }
        }
Exemple #7
0
        public static Dir8 ToDir8(this DirH dir)
        {
            switch (dir)
            {
            case DirH.None: return(Dir8.None);

            case DirH.Left: return(Dir8.Left);

            case DirH.Right: return(Dir8.Right);

            default:
                throw new ArgumentOutOfRangeException(nameof(dir), dir, "Invalid enum value.");
            }
        }
Exemple #8
0
        public static Loc GetLoc(this DirH dir)
        {
            switch (dir)
            {
            case DirH.None:
                return(Loc.Zero);

            case DirH.Left:
                return(-Loc.UnitX);

            case DirH.Right:
                return(Loc.UnitX);

            default:
                throw new ArgumentOutOfRangeException(nameof(dir), dir, "Invalid enum value.");
            }
        }
Exemple #9
0
        public static void Separate(this Dir8 dir, out DirH horiz, out DirV vert)
        {
            if (!dir.Validate())
            {
                throw new ArgumentOutOfRangeException(nameof(dir), dir, "Invalid enum value.");
            }
            switch (dir)
            {
            case Dir8.Down:
            case Dir8.DownLeft:
            case Dir8.DownRight:
                vert = DirV.Down;
                break;

            case Dir8.Up:
            case Dir8.UpLeft:
            case Dir8.UpRight:
                vert = DirV.Up;
                break;

            default:
                vert = DirV.None;
                break;
            }

            switch (dir)
            {
            case Dir8.Left:
            case Dir8.UpLeft:
            case Dir8.DownLeft:
                horiz = DirH.Left;
                break;

            case Dir8.Right:
            case Dir8.UpRight:
            case Dir8.DownRight:
                horiz = DirH.Right;
                break;

            default:
                horiz = DirH.None;
                break;
            }
        }
Exemple #10
0
 public void CombineEx(DirH horiz, DirV vert)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => { DirExt.Combine(horiz, vert); });
 }
Exemple #11
0
        public void DrawText(SpriteBatch spriteBatch, int x, int y, string text, Rectangle?area, DirV vOrigin, DirH hOrigin, Color color)
        {
            if (String.IsNullOrWhiteSpace(text))
            {
                return;
            }

            int lineSpace = CharHeight + LineSpace;

            //Draw positions
            int dX = x;
            int dY = y;

            //If the text needs to be aligned
            if (area == null)
            {
                area = new Rectangle(x, y, 0, 0);
            }

            //Set origin (vertical)
            switch (vOrigin)
            {
            case DirV.Up:
                dY = area.Value.Top;
                break;

            case DirV.Down:
                dY = area.Value.Bottom - StringHeight(text, LineSpace);
                break;

            default:
                dY = (area.Value.Top + area.Value.Bottom - StringHeight(text, LineSpace)) / 2;
                break;
            }
            //Set origin (horizontal)
            switch (hOrigin)
            {
            case DirH.Left:
                dX = area.Value.Left;
                break;

            case DirH.Right:
                dX = area.Value.Right - SubstringWidth(text);
                break;

            default:
                dX = (area.Value.Left + area.Value.Right - SubstringWidth(text)) / 2;
                break;
            }
            int startDX = dX;

            //Go through string
            for (int ii = 0; ii < text.Length; ii++)
            {
                //Space
                if (text[ii] == ' ' || text[ii] == ' ')
                {
                    dX += SpaceWidth;
                }
                else if (text[ii] == '\u2060' || text[ii] == '\u202F')
                {
                    dX++;
                }
                //Newline
                else if (text[ii] == '\n')
                {
                    //Handle horizontal alignment
                    int targetX = x;
                    switch (hOrigin)
                    {
                    case DirH.Left:
                        targetX = area.Value.Left;
                        break;

                    case DirH.Right:
                        targetX = area.Value.Right - SubstringWidth(text[ii + 1].ToString());
                        break;

                    default:
                        targetX = (area.Value.Left + area.Value.Right - SubstringWidth(text.Substring(ii + 1).ToString())) / 2;
                        break;
                    }
                    dY += lineSpace;
                    dX  = targetX;
                }
                //Character
                else
                {
                    int texture_char = charMap[0];//default null

                    if (dX > startDX)
                    {
                        dX += CharSpace;
                    }

                    //Get corresponding texture
                    if (charMap.ContainsKey(text[ii]))
                    {
                        texture_char = charMap[text[ii]];
                    }

                    Rectangle char_rect = spriteRects[texture_char];
                    DrawSprite(spriteBatch, new Vector2(dX, dY), texture_char, color);

                    //Move over
                    dX += char_rect.Width;
                }
            }
        }
Exemple #12
0
 public void DrawText(SpriteBatch spriteBatch, int x, int y, string text, Rectangle?area, DirV vOrigin, DirH hOrigin)
 {
     DrawText(spriteBatch, x, y, text, area, vOrigin, hOrigin, Color.White);
 }
Exemple #13
0
 public void DrawText(SpriteBatch spriteBatch, int x, int y, string text, Rectangle?area, DirV vOrigin, DirH hOrigin, Color color)
 {
     DrawText(spriteBatch, x, y, text, area, vOrigin, hOrigin, color, 0, text.Length);
 }
Exemple #14
0
 public MenuText(string text, Loc loc, DirH align)
     : this(text, loc, DirV.Up, align, Color.White)
 {
 }