예제 #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);
 }
예제 #2
0
 public ScanLineTile(IntRange x, int y, DirV dir, bool goLeft, bool goRight)
 {
     this.X       = x;
     this.Y       = y;
     this.Dir     = dir;
     this.GoLeft  = goLeft;
     this.GoRight = goRight;
 }
예제 #3
0
 public MenuText(string text, Loc loc, DirV alignV, DirH alignH, Color color)
 {
     Text   = text;
     Loc    = loc;
     AlignV = alignV;
     AlignH = alignH;
     Color  = color;
 }
예제 #4
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.");
            }
        }
예제 #5
0
 public void ToDir8(DirV dir, Dir8 expected, bool exception = false)
 {
     if (exception)
     {
         Assert.Throws <ArgumentOutOfRangeException>(() => { dir.ToDir8(); });
     }
     else
     {
         Assert.That(dir.ToDir8(), Is.EqualTo(expected));
     }
 }
예제 #6
0
 public void Reverse(DirV dir, DirV 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));
     }
 }
예제 #7
0
        public static bool Validate(this DirV dir)
        {
            switch (dir)
            {
            case DirV.None:
            case DirV.Down:
            case DirV.Up:
                return(true);

            default:
                return(false);
            }
        }
예제 #8
0
        public static Dir8 ToDir8(this DirV dir)
        {
            switch (dir)
            {
            case DirV.None: return(Dir8.None);

            case DirV.Down: return(Dir8.Down);

            case DirV.Up: return(Dir8.Up);

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

            case DirV.Down:
                return(Loc.UnitY);

            case DirV.Up:
                return(-Loc.UnitY);

            default:
                throw new ArgumentOutOfRangeException(nameof(dir), dir, "Invalid enum value.");
            }
        }
예제 #10
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;
            }
        }
예제 #11
0
        private static void ScanFill(
            Rect rect,
            LocTest checkBlock,
            LocTest checkDiagBlock,
            LocAction fillOp,
            int min,
            int max,
            int range_min,
            int range_max,
            int y,
            bool isNext,
            DirV dir,
            Stack <ScanLineTile> stack)
        {
            if (checkBlock == null)
            {
                throw new ArgumentNullException(nameof(checkBlock));
            }
            if (fillOp == null)
            {
                throw new ArgumentNullException(nameof(fillOp));
            }

            // move y down or up
            int new_y = y + dir.GetLoc().Y;

            // for diagonal checking: check slightly further
            int sub = (range_min > rect.Start.X) ? 1 : 0;
            int add = (range_max < rect.Start.X + rect.Size.X - 1) ? 1 : 0;

            int line_start = -1;
            int x          = range_min - sub;

            for (; x <= range_max + add; x++)
            {
                bool unblocked = !checkBlock(new Loc(x, new_y));

                // check diagonal if applicable
                if (x < range_min)
                {
                    unblocked &= !IsDirBlocked(new Loc(range_min, y), DirExt.Combine(DirH.Left, dir), checkBlock, checkDiagBlock);
                }
                else if (x > range_max)
                {
                    unblocked &= !IsDirBlocked(new Loc(range_max, y), DirExt.Combine(DirH.Right, dir), checkBlock, checkDiagBlock);
                }

                // skip testing, if testing previous line within previous range
                bool empty = (isNext || (x <min || x> max)) && unblocked;

                if (line_start == -1 && empty)
                {
                    line_start = x;
                }
                else if (line_start > -1 && !empty)
                {
                    stack.Push(new ScanLineTile(new IntRange(line_start, x - 1), new_y, dir, line_start <= range_min, x > range_max));
                    line_start = -1;
                }

                if (line_start > -1)
                {
                    fillOp(new Loc(x, new_y));
                }

                if (!isNext && x == min)
                {
                    x = max;
                }
            }

            if (line_start > -1)
            {
                stack.Push(new ScanLineTile(new IntRange(line_start, x - 1), new_y, dir, line_start <= range_min, true));
            }
        }
예제 #12
0
 public void CombineEx(DirH horiz, DirV vert)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => { DirExt.Combine(horiz, vert); });
 }
예제 #13
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;
                }
            }
        }
예제 #14
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);
 }
예제 #15
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);
 }