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); }
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); } }
private static void PaintSlopedLine2(Canvass canvass, SlopedLine2 slopedLine2, Model model) { slopedLine2.Segments.Each((segment, i) => { var c = GetLineChar(slopedLine2.GetDirectionOf(i), segment.Type); PaintLineOrCross(canvass, segment.Pos, c, slopedLine2.Id, model); }); }
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); } }
//+~~~~~~~~~~+\ //| |_\ //| | //| | //+~~~~~~~~~~~~~+ private static void PaintNote(Canvass canvass, Note note, bool paintSelectableIds) { int px = note.Pos.X, py = note.Pos.Y; var rows = note.Text.Split('\n'); for (var y = 0; y < note.H; y++) { if (y == 0) { var line = "~".Repeat(note.W - 3); Canvass.PaintString(canvass, $"+{line}+\\", px, py + y, note.Id, ConsoleColor.Black, ConsoleColor.Gray); } else if (y == 1) { var line = "".PadLeft(note.W - 3); Canvass.PaintString(canvass, $"|{line}|_\\", px, py + y, note.Id, ConsoleColor.Black, ConsoleColor.Gray); } else if (y < note.H - 1) { var line = rows[y - 2].PadRight(note.W - 1); Canvass.PaintString(canvass, $"|{line}|", px, py + y, note.Id, ConsoleColor.Black, ConsoleColor.Gray); } else { var line = "~".Repeat(note.W - 1); Canvass.PaintString(canvass, $"+{line}+", px, py + y, note.Id, ConsoleColor.Black, ConsoleColor.Gray); } } if (paintSelectableIds) { canvass.RawPaintString(note.Id.ToString(), note.Pos, ConsoleColor.DarkGreen, ConsoleColor.Green); } }
public static void PaintDatabase(Canvass c, Database d) { foreach (var t in d.Paint()) { c.Paint(t.Item1, t.Item2, t.Item3); } }
private static Canvass PaintCursor(Canvass canvas, Cursor cursor) { var pixel = canvas.Catode[cursor.Y][cursor.X] ?? (canvas.Catode[cursor.Y][cursor.X] = new Pixel()); pixel.BackGroundColor = ConsoleColor.DarkYellow; pixel.ForegroundColor = ConsoleColor.Yellow; return(canvas); }
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); }
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)); } }
public override Canvass Paint() { c = new Canvass(); for (int y = 0; y < msglines.Length; y++) { c.RawPaintString(" " + msglines[y], 0, y, BackGround, Foreground); } return(c); }
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); } }
public static Canvass PaintModel(Model model, bool paintSelectableIds) { var c = new Canvass(); foreach (var x in model.Objects) { if (x is Database) { PaintDatabase(c, x as Database, paintSelectableIds); } if (x is Box) { PaintBox(c, x as Box, paintSelectableIds); } if (x is UmlUser) { PaintUmlUser(c, x as UmlUser, paintSelectableIds); } } // draw lines after boxes so the shortest path does not intersect those objects foreach (var x in model.Objects) { if (x is Line) { PaintLine2(c, x as Line, model); } } // labels may go above lines foreach (var x in model.Objects) { if (x is Label) { PaintLabel(c, x as Label, paintSelectableIds); } if (x is Note) { PaintNote(c, x as Note, paintSelectableIds); } } // lines may not cross boxes, hence drawn afterwards model.Objects.OfType <SlopedLineVectorized>().Each(x => PaintSlopedLine(c, x, model)); model.Objects.OfType <SlopedLine2>().Each(x => PaintSlopedLine2(c, x, model)); return(c); }
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); } }
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); }
private static void PaintUmlUser(Canvass canvass, UmlUser user, bool paintSelectableIds) { var gfx = @" ,-. `-' /|\ | / \ " + (user.Text ?? ""); var lines = gfx.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); lines.Each((line, row) => Canvass.PaintString(canvass, line, user.Pos.X, user.Pos.Y + row, user.Id)); if (paintSelectableIds) { canvass.RawPaintString(user.Id.ToString(), user.Pos, ConsoleColor.DarkGreen, ConsoleColor.Green); } }
public static Canvass PaintModel(List <IPaintable <object> > model) { var c = new Canvass(); foreach (var x in model) { if (x is Database) { PaintDatabase(c, x as Database); } if (x is Box) { PaintBox(c, x as Box); } } // draw lines after boxes and labels so the shortest path does not intersect those objects foreach (var x in model) { if (x is Line) { PaintLine2(c, x as Line, model); } } // labels may go above lines foreach (var x in model) { if (x is Label) { PaintLabel(c, x as Label); } } // lines may not cross boxes, hence drawn afterwards model.OfType <SlopedLine>().Each(x => PaintSlopedLine(c, x)); model.OfType <SlopedLine2>().Each(x => PaintSlopedLine2(c, x)); return(c); }
private static void PaintSlopedLine(Canvass canvass, SlopedLineVectorized slopedLineVectorized, Model model) { foreach (var segment in slopedLineVectorized.Segments) { var c = GetLineChar(segment.Direction, segment.Type); var delta = Math.Abs(segment.From.X - segment.To.X); int direction; direction = segment.From.X < segment.To.X ? 1 : -1; for (var i = 0; i <= delta; i++) { var newPos = new Coord(segment.From.X + i * direction, segment.From.Y); PaintLineOrCross(canvass, newPos, c, segment.Id, model); } direction = segment.From.Y < segment.To.Y ? 1 : -1; delta = Math.Abs(segment.From.Y - segment.To.Y); for (var i = 0; i <= delta; i++) { var newPos = new Coord(segment.From.X, segment.From.Y + i * direction); PaintLineOrCross(canvass, newPos, c, segment.Id, model); } } }
public static void PaintString(Canvass c, string s, int x, int y, int objectId) { PaintString(c, s, x, y, objectId, ConsoleColor.Black, ConsoleColor.Gray); }