Exemplo n.º 1
0
        public static void PaintLine2(Canvass c, Line lineArg, Model model)
        {
            var from         = (IConnectable)model.Objects.First(x => x.Id == lineArg.FromId);
            var to           = (IConnectable)model.Objects.First(x => x.Id == lineArg.ToId);
            var smallestDist = CalcSmallestDist(from.GetFrameCoords(), to.GetFrameCoords());

            var line = ShortestPathFinder.Calculate(smallestDist.Min, smallestDist.Max, c, model);

            if (line.Count < 2)
            {
                return;
            }

            Coord coord;

            // dont draw first nor 2-last elements. First/last elements are box-frames
            var i = 1;

            for (; i < line.Count - 2; i++)
            {
                coord = line[i];
                var lineChar = CalculateDirectionLine(line[i - 1], coord, line[i + 1]);
                c.Paint(coord, lineChar, lineArg.Id);
            }

            // secondlast element is the arrow head
            coord = line[i];
            c.Paint(coord, CalculateDirectionArrowHead(line[i - 1], coord), lineArg.Id);
        }
Exemplo n.º 2
0
        private static void PaintLabel(Canvass canvass, Label label, bool paintSelectableIds)
        {
            var lines = label.Text.Split('\n');

            switch (label.Direction)
            {
            case LabelDirection.LeftToRight:
                lines.Each((line, extraY) => Canvass.PaintString(canvass, line, label.X, label.Y + extraY, label.Id, ConsoleColor.Black,
                                                                 ConsoleColor.Gray));
                break;

            case LabelDirection.TopDown:
                var extraX = 0;
                foreach (var line in lines)
                {
                    for (var i = 0; i < line.Length; i++)
                    {
                        canvass.Paint(new Coord(label.X + extraX, label.Y + i), line[i], label.Id);
                    }
                    extraX++;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (paintSelectableIds)
            {
                canvass.RawPaintString(label.Id.ToString(), label.Pos, ConsoleColor.DarkGreen, ConsoleColor.Green);
            }
        }
Exemplo n.º 3
0
 public static void PaintString(Canvass c, string s, int x, int y, int objectId, ConsoleColor backgroundColor, ConsoleColor foregroundColor)
 {
     for (int i = 0; i < s.Length; i++)
     {
         c.Paint(x + i, y, s[i], objectId, backgroundColor, foregroundColor);
     }
 }
Exemplo n.º 4
0
 public static void PaintDatabase(Canvass c, Database d)
 {
     foreach (var t in d.Paint())
     {
         c.Paint(t.Item1, t.Item2, t.Item3);
     }
 }
Exemplo n.º 5
0
 private static void PaintLineOrCross(Canvass canvass, Coord pos, char c, int id)
 {
     if ((canvass.GetCell(pos) == '-' && c == '|') || (canvass.GetCell(pos) == '|' && c == '-'))
     {
         c = '+';
     }
     canvass.Paint(pos, c, id);
 }
Exemplo n.º 6
0
        public static void PaintBox(Canvass c, Box b)
        {
            b.GetFrameCoords().Each(pos => c.Paint(pos, '*', b.Id));
            const int padX = 2, padY = 1;             // TODO make padding configurable pr. box

            if (!string.IsNullOrWhiteSpace(b.Text))
            {
                b.Text.Split('\n').Each((text, i) => Canvass.PaintString(c, text, b.X + padX, b.Y + padY + i, b.Id, ConsoleColor.Black, ConsoleColor.Gray));
            }
        }
Exemplo n.º 7
0
        public static void PaintDatabase(Canvass c, Database d, bool statePaintSelectableIds)
        {
            foreach (var t in d.Paint())
            {
                c.Paint(t.Item1, t.Item2, t.Item3);
            }

            if (statePaintSelectableIds)
            {
                c.RawPaintString(d.Id.ToString(), d.Pos, ConsoleColor.DarkGreen, ConsoleColor.Green);
            }
        }
Exemplo n.º 8
0
        public static void PaintBox(Canvass c, Box b, bool paintSelectableIds)
        {
            b.GetFrameParts().Each(part => c.Paint(part.Item1, GetCharForStyle(b.Style, part.Item2), b.Id));
            const int padX = 2, padY = 1;             // TODO make padding configurable pr. box

            if (!string.IsNullOrWhiteSpace(b.Text))
            {
                b.Text.Split('\n').Each((text, i) =>
                                        Canvass.PaintString(c, text, b.X + padX, b.Y + padY + i, b.Id, ConsoleColor.Black, ConsoleColor.Gray));
            }

            if (paintSelectableIds)
            {
                c.RawPaintString(b.Id.ToString(), b.Pos, ConsoleColor.DarkGreen, ConsoleColor.Green);
            }
        }
Exemplo n.º 9
0
        private static void PaintLineOrCross(Canvass canvass, Coord pos, char c, int id, Model model)
        {
            var oc = canvass.Occupants[pos.Y, pos.X];

            if (oc.HasValue)
            {
                var elem = model.Objects.First(x => x.Id == oc.Value);
                if (elem is Line || elem is SlopedLineVectorized || elem is SlopedLine2)
                {
                    var cell = canvass.GetCell(pos);
                    if (cell == '-' && c == '|' || cell == '|' && c == '-')
                    {
                        c = '+';
                    }
                }
            }

            canvass.Paint(pos, c, id);
        }