|
@@ -11,10 +11,10 @@ namespace Terminal.Gui.Graphs {
|
|
/// </summary>
|
|
/// </summary>
|
|
public class LineCanvas {
|
|
public class LineCanvas {
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
private List<StraightLine> lines = new List<StraightLine> ();
|
|
private List<StraightLine> lines = new List<StraightLine> ();
|
|
|
|
|
|
- Dictionary<IntersectionRuneType, IntersectionRuneResolver> runeResolvers = new Dictionary<IntersectionRuneType, IntersectionRuneResolver> {
|
|
|
|
|
|
+ Dictionary<IntersectionRuneType, IntersectionRuneResolver> runeResolvers = new Dictionary<IntersectionRuneType, IntersectionRuneResolver> {
|
|
{IntersectionRuneType.ULCorner,new ULIntersectionRuneResolver()},
|
|
{IntersectionRuneType.ULCorner,new ULIntersectionRuneResolver()},
|
|
{IntersectionRuneType.URCorner,new URIntersectionRuneResolver()},
|
|
{IntersectionRuneType.URCorner,new URIntersectionRuneResolver()},
|
|
{IntersectionRuneType.LLCorner,new LLIntersectionRuneResolver()},
|
|
{IntersectionRuneType.LLCorner,new LLIntersectionRuneResolver()},
|
|
@@ -56,16 +56,16 @@ namespace Terminal.Gui.Graphs {
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="bounds"></param>
|
|
/// <param name="bounds"></param>
|
|
/// <returns>Map as 2D array where first index is rows and second is column</returns>
|
|
/// <returns>Map as 2D array where first index is rows and second is column</returns>
|
|
- public Rune? [,] GenerateImage (Rect bounds)
|
|
|
|
|
|
+ public Rune? [,] GenerateImage (Rect inArea)
|
|
{
|
|
{
|
|
- Rune? [,] canvas = new Rune? [bounds.Height, bounds.Width];
|
|
|
|
|
|
+ Rune? [,] canvas = new Rune? [inArea.Height, inArea.Width];
|
|
|
|
|
|
// walk through each pixel of the bitmap
|
|
// walk through each pixel of the bitmap
|
|
- for (int y = 0; y < bounds.Height; y++) {
|
|
|
|
- for (int x = 0; x < bounds.Width; x++) {
|
|
|
|
|
|
+ for (int y = 0; y < inArea.Height; y++) {
|
|
|
|
+ for (int x = 0; x < inArea.Width; x++) {
|
|
|
|
|
|
var intersects = lines
|
|
var intersects = lines
|
|
- .Select (l => l.Intersects (bounds.X + x, bounds.Y + y))
|
|
|
|
|
|
+ .Select (l => l.Intersects (inArea.X + x, inArea.Y + y))
|
|
.Where (i => i != null)
|
|
.Where (i => i != null)
|
|
.ToArray ();
|
|
.ToArray ();
|
|
|
|
|
|
@@ -88,11 +88,10 @@ namespace Terminal.Gui.Graphs {
|
|
public void Draw (View view, Rect bounds)
|
|
public void Draw (View view, Rect bounds)
|
|
{
|
|
{
|
|
var runes = GenerateImage (bounds);
|
|
var runes = GenerateImage (bounds);
|
|
-
|
|
|
|
|
|
+
|
|
for (int y = bounds.Y; y < bounds.Y + bounds.Height; y++) {
|
|
for (int y = bounds.Y; y < bounds.Y + bounds.Height; y++) {
|
|
for (int x = bounds.X; x < bounds.X + bounds.Width; x++) {
|
|
for (int x = bounds.X; x < bounds.X + bounds.Width; x++) {
|
|
var rune = runes [y - bounds.Y, x - bounds.X];
|
|
var rune = runes [y - bounds.Y, x - bounds.X];
|
|
-
|
|
|
|
if (rune.HasValue) {
|
|
if (rune.HasValue) {
|
|
if (view != null) {
|
|
if (view != null) {
|
|
view.AddRune (x - bounds.X, y - bounds.Y, rune.Value);
|
|
view.AddRune (x - bounds.X, y - bounds.Y, rune.Value);
|
|
@@ -105,15 +104,14 @@ namespace Terminal.Gui.Graphs {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private abstract class IntersectionRuneResolver
|
|
|
|
- {
|
|
|
|
|
|
+ private abstract class IntersectionRuneResolver {
|
|
readonly Rune round;
|
|
readonly Rune round;
|
|
readonly Rune doubleH;
|
|
readonly Rune doubleH;
|
|
readonly Rune doubleV;
|
|
readonly Rune doubleV;
|
|
readonly Rune doubleBoth;
|
|
readonly Rune doubleBoth;
|
|
readonly Rune normal;
|
|
readonly Rune normal;
|
|
|
|
|
|
- public IntersectionRuneResolver(Rune round, Rune doubleH, Rune doubleV, Rune doubleBoth, Rune normal)
|
|
|
|
|
|
+ public IntersectionRuneResolver (Rune round, Rune doubleH, Rune doubleV, Rune doubleBoth, Rune normal)
|
|
{
|
|
{
|
|
this.round = round;
|
|
this.round = round;
|
|
this.doubleH = doubleH;
|
|
this.doubleH = doubleH;
|
|
@@ -126,17 +124,15 @@ namespace Terminal.Gui.Graphs {
|
|
{
|
|
{
|
|
var useRounded = intersects.Any (i => i.Line.Style == BorderStyle.Rounded && i.Line.Length != 0);
|
|
var useRounded = intersects.Any (i => i.Line.Style == BorderStyle.Rounded && i.Line.Length != 0);
|
|
|
|
|
|
- bool doubleHorizontal = intersects.Any(l=>l.Line.Orientation == Orientation.Horizontal && l.Line.Style == BorderStyle.Double);
|
|
|
|
- bool doubleVertical = intersects.Any(l=>l.Line.Orientation == Orientation.Vertical && l.Line.Style == BorderStyle.Double);
|
|
|
|
|
|
+ bool doubleHorizontal = intersects.Any (l => l.Line.Orientation == Orientation.Horizontal && l.Line.Style == BorderStyle.Double);
|
|
|
|
+ bool doubleVertical = intersects.Any (l => l.Line.Orientation == Orientation.Vertical && l.Line.Style == BorderStyle.Double);
|
|
|
|
|
|
|
|
|
|
- if(doubleHorizontal)
|
|
|
|
- {
|
|
|
|
- return doubleVertical ? doubleBoth : doubleH;
|
|
|
|
|
|
+ if (doubleHorizontal) {
|
|
|
|
+ return doubleVertical ? doubleBoth : doubleH;
|
|
}
|
|
}
|
|
-
|
|
|
|
- if(doubleVertical)
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ if (doubleVertical) {
|
|
return doubleV;
|
|
return doubleV;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -144,75 +140,71 @@ namespace Terminal.Gui.Graphs {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private class ULIntersectionRuneResolver : IntersectionRuneResolver
|
|
|
|
- {
|
|
|
|
- public ULIntersectionRuneResolver() :
|
|
|
|
- base('╭','╒','╓','╔','┌')
|
|
|
|
|
|
+ private class ULIntersectionRuneResolver : IntersectionRuneResolver {
|
|
|
|
+ public ULIntersectionRuneResolver () :
|
|
|
|
+ base ('╭', '╒', '╓', '╔', '┌')
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- private class URIntersectionRuneResolver : IntersectionRuneResolver
|
|
|
|
- {
|
|
|
|
|
|
+ private class URIntersectionRuneResolver : IntersectionRuneResolver {
|
|
|
|
|
|
- public URIntersectionRuneResolver() :
|
|
|
|
- base('╮','╕','╖','╗','┐')
|
|
|
|
|
|
+ public URIntersectionRuneResolver () :
|
|
|
|
+ base ('╮', '╕', '╖', '╗', '┐')
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- private class LLIntersectionRuneResolver : IntersectionRuneResolver
|
|
|
|
- {
|
|
|
|
|
|
+ private class LLIntersectionRuneResolver : IntersectionRuneResolver {
|
|
|
|
|
|
- public LLIntersectionRuneResolver() :
|
|
|
|
- base('╰','╘','╙','╚','└')
|
|
|
|
|
|
+ public LLIntersectionRuneResolver () :
|
|
|
|
+ base ('╰', '╘', '╙', '╚', '└')
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- private class LRIntersectionRuneResolver : IntersectionRuneResolver
|
|
|
|
- {
|
|
|
|
- public LRIntersectionRuneResolver() :
|
|
|
|
- base('╯','╛','╜','╝','┘')
|
|
|
|
|
|
+ private class LRIntersectionRuneResolver : IntersectionRuneResolver {
|
|
|
|
+ public LRIntersectionRuneResolver () :
|
|
|
|
+ base ('╯', '╛', '╜', '╝', '┘')
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private class TopTeeIntersectionRuneResolver : IntersectionRuneResolver
|
|
|
|
- {
|
|
|
|
- public TopTeeIntersectionRuneResolver():
|
|
|
|
- base('┬','╤','╥','╦','┬'){
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ private class TopTeeIntersectionRuneResolver : IntersectionRuneResolver {
|
|
|
|
+ public TopTeeIntersectionRuneResolver () :
|
|
|
|
+ base ('┬', '╤', '╥', '╦', '┬')
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- private class LeftTeeIntersectionRuneResolver : IntersectionRuneResolver
|
|
|
|
- {
|
|
|
|
- public LeftTeeIntersectionRuneResolver():
|
|
|
|
- base('├','╞','╟','╠','├'){
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ private class LeftTeeIntersectionRuneResolver : IntersectionRuneResolver {
|
|
|
|
+ public LeftTeeIntersectionRuneResolver () :
|
|
|
|
+ base ('├', '╞', '╟', '╠', '├')
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- private class RightTeeIntersectionRuneResolver : IntersectionRuneResolver
|
|
|
|
- {
|
|
|
|
- public RightTeeIntersectionRuneResolver():
|
|
|
|
- base('┤','╡','╢','╣','┤'){
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ private class RightTeeIntersectionRuneResolver : IntersectionRuneResolver {
|
|
|
|
+ public RightTeeIntersectionRuneResolver () :
|
|
|
|
+ base ('┤', '╡', '╢', '╣', '┤')
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- private class BottomTeeIntersectionRuneResolver : IntersectionRuneResolver
|
|
|
|
- {
|
|
|
|
- public BottomTeeIntersectionRuneResolver():
|
|
|
|
- base('┴','╧','╨','╩','┴'){
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ private class BottomTeeIntersectionRuneResolver : IntersectionRuneResolver {
|
|
|
|
+ public BottomTeeIntersectionRuneResolver () :
|
|
|
|
+ base ('┴', '╧', '╨', '╩', '┴')
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- private class CrosshairIntersectionRuneResolver : IntersectionRuneResolver
|
|
|
|
- {
|
|
|
|
- public CrosshairIntersectionRuneResolver():
|
|
|
|
- base('┼','╪','╫','╬','┼'){
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ private class CrosshairIntersectionRuneResolver : IntersectionRuneResolver {
|
|
|
|
+ public CrosshairIntersectionRuneResolver () :
|
|
|
|
+ base ('┼', '╪', '╫', '╬', '┼')
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private Rune? GetRuneForIntersects (ConsoleDriver driver, IntersectionDefinition [] intersects)
|
|
private Rune? GetRuneForIntersects (ConsoleDriver driver, IntersectionDefinition [] intersects)
|
|
@@ -222,7 +214,7 @@ namespace Terminal.Gui.Graphs {
|
|
|
|
|
|
var runeType = GetRuneTypeForIntersects (intersects);
|
|
var runeType = GetRuneTypeForIntersects (intersects);
|
|
|
|
|
|
- if(runeResolvers.ContainsKey (runeType)) {
|
|
|
|
|
|
+ if (runeResolvers.ContainsKey (runeType)) {
|
|
return runeResolvers [runeType].GetRuneForIntersects (driver, intersects);
|
|
return runeResolvers [runeType].GetRuneForIntersects (driver, intersects);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -233,13 +225,13 @@ namespace Terminal.Gui.Graphs {
|
|
// TODO: maybe make these resolvers to for simplicity?
|
|
// TODO: maybe make these resolvers to for simplicity?
|
|
// or for dotted lines later on or that kind of thing?
|
|
// or for dotted lines later on or that kind of thing?
|
|
switch (runeType) {
|
|
switch (runeType) {
|
|
- case IntersectionRuneType.None:
|
|
|
|
|
|
+ case IntersectionRuneType.None:
|
|
return null;
|
|
return null;
|
|
- case IntersectionRuneType.Dot:
|
|
|
|
|
|
+ case IntersectionRuneType.Dot:
|
|
return (Rune)'.';
|
|
return (Rune)'.';
|
|
- case IntersectionRuneType.HLine:
|
|
|
|
|
|
+ case IntersectionRuneType.HLine:
|
|
return useDouble ? driver.HDLine : driver.HLine;
|
|
return useDouble ? driver.HDLine : driver.HLine;
|
|
- case IntersectionRuneType.VLine:
|
|
|
|
|
|
+ case IntersectionRuneType.VLine:
|
|
return useDouble ? driver.VDLine : driver.VLine;
|
|
return useDouble ? driver.VDLine : driver.VLine;
|
|
default: throw new Exception ("Could not find resolver or switch case for " + nameof (runeType) + ":" + runeType);
|
|
default: throw new Exception ("Could not find resolver or switch case for " + nameof (runeType) + ":" + runeType);
|
|
}
|
|
}
|
|
@@ -248,7 +240,7 @@ namespace Terminal.Gui.Graphs {
|
|
|
|
|
|
private IntersectionRuneType GetRuneTypeForIntersects (IntersectionDefinition [] intersects)
|
|
private IntersectionRuneType GetRuneTypeForIntersects (IntersectionDefinition [] intersects)
|
|
{
|
|
{
|
|
- if(intersects.All(i=>i.Line.Length == 0)) {
|
|
|
|
|
|
+ if (intersects.All (i => i.Line.Length == 0)) {
|
|
return IntersectionRuneType.Dot;
|
|
return IntersectionRuneType.Dot;
|
|
}
|
|
}
|
|
|
|
|