private IPen <Rgba32> getPen(DrawWith d) { if (d.Type == DrawWithTypeEnum.Pen) { return(getPen(d.Id)); } else { throw new ArgumentException("getBrush requires a pen type DrawWith parameter", nameof(d)); } }
private IBrush <Rgba32> getBrush(DrawWith d) { if (d.Type == DrawWithTypeEnum.Brush) { return(getBrush(d.Id)); } else { throw new ArgumentException("getBrush requires a brush type DrawWith parameter", nameof(d)); } }
public void DrawText(int imgID, string text, int fontID, DrawWith d, PointF location, int matrixID) { location = transformByMatrix(matrixID, location); withImage(imgID, ctx => { switch (d.Type) { case DrawWithTypeEnum.Brush: ctx.DrawText(text, GetFont(fontID), getBrush(d), location, createGraphicsOptions()); break; case DrawWithTypeEnum.Pen: ctx.DrawText(text, GetFont(fontID), getPen(d), location, createGraphicsOptions()); break; default: break; } }); }
public void DrawEclipse(int imgID, DrawWith d, PointF position, SizeF size, int matrixID) { position = transformByMatrix(matrixID, position); size = transformByMatrix(matrixID, size); withImage(imgID, ctx => { switch (d.Type) { case DrawWithTypeEnum.Brush: ctx.Draw(getBrush(d), d.Thickness, new SixLabors.Shapes.EllipsePolygon(position, size), createGraphicsOptions()); break; case DrawWithTypeEnum.Pen: ctx.Draw(getPen(d), new SixLabors.Shapes.EllipsePolygon(position, size), createGraphicsOptions()); break; default: break; } }); }
public void DrawLines(int imgId, DrawWith d, IEnumerable <PointF> points, int matrixID) { var p = transformByMatrix(matrixID, points); withImage(imgId, ctx => { switch (d.Type) { case DrawWithTypeEnum.Brush: ctx.DrawLines(getBrush(d), d.Thickness, p, createGraphicsOptions()); break; case DrawWithTypeEnum.Pen: ctx.DrawLines(getPen(d), p, createGraphicsOptions()); break; default: break; } } ); }
/// <summary>Yield all subdirectories of the supplied path as a text outline.</summary> /// <param name="rootPath">Topmost directory.</param> /// <param name="fileFilter">Search pattern or *null* for all.</param> /// <param name="drawWith">Outline characters.</param> /// <param name="order">Output sorting.</param> /// <param name="tab">Number of characters to indent per level.</param> /// <returns>All subdirectories of the supplied path as a text outline.</returns> public static IEnumerable <string> GenerateTextTree(string rootPath, string fileFilter, DrawWith drawWith = DrawWith.Graphic, Ordering order = Ordering.None, int tab = 4) { var sb = new StringBuilder(); for (var dv = new DirNode.Vector(rootPath, null, order, drawWith, tab); dv.Advance(); sb.Length = 0) { sb.AppendIndent(dv, false); sb.Append(dv.Depth == 0 ? dv.Top.Path : dv.Top.Name); yield return(sb.ToString()); if (fileFilter != null) { dv.PregetContents(fileFilter); if (dv.Top.FileInfos.Count > 0) { sb.Length = 0; sb.AppendIndent(dv, true); int indentLength = sb.Length; foreach (var fInfo in dv.Top.FileInfos) { sb.Append(fInfo.Name); yield return(sb.ToString()); sb.Length = indentLength; } yield return(sb.ToString()); } } } }
/// <summary>Initializes a new instance of the <see cref="DirNode.Vector"/> class.</summary> /// <param name="rootPath">Top directory.</param> /// <param name="dirFilter">Search pattern.</param> /// <param name="order">Output sorting.</param> /// <param name="drawWith">Outline characters.</param> /// <param name="tabSize">Number of characters to indent per level.</param> protected Vector(string rootPath, string dirFilter = null, Ordering order = Ordering.None, DrawWith drawWith = DrawWith.Ascii, int tabSize = 4) { this.stack = new QueuedStack <DirNode>(); this.stack.Enqueue(new DirNode(new DirectoryInfo[] { new DirectoryInfo(rootPath) }, -1)); this.TabSize = tabSize; this.DirFilter = dirFilter ?? "*"; if (drawWith == DrawWith.Graphic) { UpDown = '\u2502'; LeftRight = '\u2500'; UpRight = '\u2514'; UpDownRight = '\u251C'; } else { UpDown = '|'; LeftRight = '-'; UpRight = '\\'; UpDownRight = '+'; } if (order == Ordering.Lexical) { this.dirComparer = SafeNativeMethods.LexicalCompareDirectoryInfo.Comparer; this.fileComparer = SafeNativeMethods.LexicalCompareFileInfo.Comparer; } else if (order == Ordering.Natural) { this.dirComparer = SafeNativeMethods.NaturalCompareDirectoryInfo.Comparer; this.fileComparer = SafeNativeMethods.NaturalCompareFileInfo.Comparer; } }
private DirVectorHtml(string rootPath, Ordering order = Ordering.None, DrawWith drawWith = DrawWith.Ascii, int tabSize = 4) : base(rootPath, null, order, drawWith, tabSize) { }
public static IEnumerable <string> GenerateHtmlTree(string rootPath, string fileFilter, DrawWith drawWith = DrawWith.Graphic, Ordering order = Ordering.None, int tab = 4) { var dv = new DirVectorHtml(rootPath, order, drawWith, tab); int buttonId = 0; yield return("<!DOCTYPE html>"); yield return("<html>"); yield return("<head>"); yield return($"<title>{rootPath}</title>"); yield return("<meta charset=\"UTF-8\">"); yield return("<style>"); yield return(" button.bn { border-width:1px; padding:0px 2px; font-family:monospace; font-size:xx-small; color: red; background-color:black; border-color:red; }"); yield return(" div.s1 { display:block; }"); yield return(" div.s2 { display:none; }"); yield return("</style>"); yield return("<script type=\"text/javascript\">"); yield return("function tgl(btn,divName) {"); yield return(" var divId = document.getElementById(divName);"); yield return(" if (divId.className == \"s1\")"); yield return(" { divId.className = 's2'; btn.textContent = \"+\"; }"); yield return(" else"); yield return(" { divId.className = 's1'; btn.textContent = \"-\"; }"); yield return("}"); yield return("</script>"); yield return("</head>"); yield return("<body style='color:orange; background-color:black; font-family:monospace; font-size:medium; white-space:pre;'>"); dv.Advance(); var sb = new StringBuilder(); sb.AppendHtml(dv[0].Path); yield return(sb.ToString()); sb.Clear(); for (bool hasSubdirsOrFiles = dv.PregetContents(fileFilter);;) { if (hasSubdirsOrFiles && dv.Top.FileInfos != null && dv.Top.FileInfos.Count > 0) { string indent = new StringBuilder().AppendIndent(dv, fileFilter != null).ToString(); sb.Append(indent); sb.AppendHtml(dv.Top.FileInfos[0].Name); yield return(sb.ToString()); sb.Clear(); sb.Append(indent); for (int fi = 1; fi < dv.Top.FileInfos.Count; ++fi) { var fileName = dv.Top.FileInfos[fi].Name; sb.AppendHtml(fileName); yield return(sb.ToString()); sb.Length = indent.Length; } yield return(indent); sb.Clear(); } if (dv.Depth >= 1 && !dv.HasSubdirs) { if (dv.Top.FileInfos != null && dv.Top.FileInfos.Count > 0) { sb.Append("</div>"); } for (int dx = dv.Depth; dx > 1 && dv[dx].IsLast; --dx) { sb.Append("</div>"); } } if (!dv.Advance()) { break; } hasSubdirsOrFiles = dv.PregetContents(fileFilter); if (!hasSubdirsOrFiles) { sb.AppendIndent(dv, false); sb.Append("<button class='bn'> </button>"); sb.AppendHtml(dv.Top.Name); yield return(sb.ToString()); sb.Clear(); } else { ++buttonId; sb.AppendIndent(dv, false); sb.Append("<button id='b"); sb.Append(buttonId); sb.Append("' class='bn' onclick=\"tgl(this,'d"); sb.Append(buttonId); sb.Append("')\">+</button>"); sb.AppendHtml(dv.Top.Name); yield return(sb.ToString()); sb.Clear(); sb.Append("<div id='d"); sb.Append(buttonId); sb.Append("' class='s2'>"); } } sb.Append("</body>"); yield return(sb.ToString()); yield return("</html>"); }
static int Main(string[] args) { string err = null; string rootPath = null; string fileFilter = null; int tab = 4; TargetInterface target = TargetInterface.Terminal; DrawWith drawWith = DrawWith.Graphic; Ordering ordering = Ordering.None; for (var ix = 0; ix < args.Length; ++ix) { var arg = args[ix]; if (arg == "/?") { ShowUsage(); return(0); } else if (arg == "/A") { drawWith = DrawWith.Ascii; } else if (arg == "/F") { fileFilter = "*"; } else if (arg == "/SL") { ordering = Ordering.Lexical; } else if (arg == "/SN") { ordering = Ordering.Natural; } else if (arg == "/W") { target = TargetInterface.Browser; } else if (arg.StartsWith("/")) { bool isOk = Int32.TryParse(arg.Substring(1), out int tryTab); if (isOk && tryTab > 0) { tab = tryTab; } else { Console.WriteLine($"Invalid switch - {args[ix]}"); return(1); } } else if (rootPath != null) { Console.WriteLine($"Too many parameters - {args[ix]}"); return(2); } else { rootPath = arg; } } if (rootPath == null) { rootPath = "."; } try { if (target == TargetInterface.Terminal) { foreach (string lx in DirNode.Vector.GenerateTextTree(rootPath, fileFilter, drawWith, ordering, tab)) { Console.WriteLine(lx); } } else { foreach (string lx in DirVectorHtml.GenerateHtmlTree(rootPath, fileFilter, drawWith, ordering, tab)) { Console.WriteLine(lx); } } } catch (IOException ex) { err = ex.Message.Trim(); } catch (UnauthorizedAccessException ex) { err = ex.Message.Trim(); } if (err != null) { Console.Error.WriteLine(err); return(1); } return(0); }