Skip to content

Commit

Permalink
I will never rely on zero-location-based unit test again.
Browse files Browse the repository at this point in the history
  • Loading branch information
BDisp committed Nov 19, 2023
1 parent 4acf726 commit 62adf6f
Show file tree
Hide file tree
Showing 2 changed files with 334 additions and 249 deletions.
134 changes: 80 additions & 54 deletions Terminal.Gui/View/ViewDrawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ public void DrawFrame (Rect rect, LineStyle lineStyle, Attribute? attribute = nu
/// be greater or equal to the start and for <see cref="Side.Left"/> and <see cref="Side.Bottom"/> the end position must
/// be less or equal to the start.
/// </summary>
/// <param name="startPos">The start and side position screen relative.</param>
/// <param name="endPos">The end and side position screen relative.</param>
/// <param name="startPos">The view relative of the start and side position.</param>
/// <param name="endPos">The view relative of the end and side position.</param>
/// <param name="rect">The view relative location and size of the frame.</param>
/// <param name="lineStyle">The line style.</param>
/// <param name="attribute">The colors to be used.</param>
Expand All @@ -582,20 +582,42 @@ public void DrawIncompleteFrame ((int start, Side side) startPos, (int end, Side
} else {
lc = LineCanvas;
}
var start = startPos.start;
var end = endPos.end;

int pStart = startPos.start;
int pEnd = endPos.end;

switch (startPos.side) {
case Side.Left:
if (start == vts.Y) {
lc.AddLine (new Point (vts.X, start), 1,
case Side.Right:
pStart += vts.Y;
break;
case Side.Top:
case Side.Bottom:
pStart += vts.X;
break;
}
switch (endPos.side) {
case Side.Left:
case Side.Right:
pEnd += vts.Y;
break;
case Side.Top:
case Side.Bottom:
pEnd += vts.X;
break;
}
switch (startPos.side) {
case Side.Left:
if (pStart == vts.Y) {
lc.AddLine (new Point (vts.X, pStart), 1,
Orientation.Vertical, lineStyle, attribute);
} else {
if (end <= start && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.X, start), end - start - 1,
if (pEnd <= pStart && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.X, pStart), pEnd - pStart - 1,
Orientation.Vertical, lineStyle, attribute);
break;
} else {
lc.AddLine (new Point (vts.X, start), vts.Y - start - 1,
lc.AddLine (new Point (vts.X, pStart), vts.Y - pStart - 1,
Orientation.Vertical, lineStyle, attribute);
}
}
Expand All @@ -607,51 +629,53 @@ public void DrawIncompleteFrame ((int start, Side side) startPos, (int end, Side
Orientation.Vertical, lineStyle, attribute);
lc.AddLine (new Point (vts.Right - 1, vts.Bottom - 1), -vts.Width,
Orientation.Horizontal, lineStyle, attribute);
if (end <= vts.Bottom - 1 && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -(vts.Bottom - end),
if (pEnd <= vts.Bottom - 1 && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -(vts.Bottom - pEnd),
Orientation.Vertical, lineStyle, attribute);
}
break;
case Side.Top:
lc.AddLine (new Point (vts.X, vts.Y), end,
lc.AddLine (new Point (vts.X, vts.Y), pEnd - 1,
Orientation.Horizontal, lineStyle, attribute);
break;
case Side.Right:
lc.AddLine (new Point (vts.X, vts.Y), vts.Width,
Orientation.Horizontal, lineStyle, attribute);
lc.AddLine (new Point (vts.Right - 1, vts.Y), end + 1,
lc.AddLine (new Point (vts.Right - 1, vts.Y), pEnd - 1,
Orientation.Vertical, lineStyle, attribute);
break;
case Side.Bottom:
lc.AddLine (new Point (vts.X, vts.Y), vts.Width,
Orientation.Horizontal, lineStyle, attribute);
lc.AddLine (new Point (vts.Right - 1, vts.Y), vts.Height,
Orientation.Vertical, lineStyle, attribute);
lc.AddLine (new Point (vts.Right - 1, vts.Bottom - 1), -end,
lc.AddLine (new Point (vts.Right - 1, vts.Bottom - 1), -(vts.Right - pEnd),
Orientation.Horizontal, lineStyle, attribute);
break;
}
break;

case Side.Top:
if (start == vts.Width - 1) {
lc.AddLine (new Point (vts.X + start, vts.Y), -1,
Orientation.Horizontal, lineStyle, attribute);
} else if (end >= start && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.X + start, vts.Y), end - start + 1,
Orientation.Horizontal, lineStyle, attribute);
break;
} else if (vts.Width - start > 0) {
lc.AddLine (new Point (vts.X + start, vts.Y), Math.Max (vts.Width - start, 0),
if (pStart == vts.Right - 1) {
lc.AddLine (new Point (pStart, vts.Y), -1,
Orientation.Horizontal, lineStyle, attribute);
} else {
if (pEnd >= pStart && startPos.side == endPos.side) {
lc.AddLine (new Point (pStart, vts.Y), pEnd - pStart + 1,
Orientation.Horizontal, lineStyle, attribute);
break;
} else {
lc.AddLine (new Point (pStart, vts.Y), vts.Right - pStart,
Orientation.Horizontal, lineStyle, attribute);
}
}
switch (endPos.side) {
case Side.Left:
lc.AddLine (new Point (vts.Right - 1, vts.Y), vts.Height,
Orientation.Vertical, lineStyle, attribute);
lc.AddLine (new Point (vts.Right - 1, vts.Bottom - 1), -vts.Width,
Orientation.Horizontal, lineStyle, attribute);
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -end,
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -(vts.Bottom - pEnd),
Orientation.Vertical, lineStyle, attribute);
break;
case Side.Top:
Expand All @@ -661,110 +685,112 @@ public void DrawIncompleteFrame ((int start, Side side) startPos, (int end, Side
Orientation.Horizontal, lineStyle, attribute);
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -vts.Height,
Orientation.Vertical, lineStyle, attribute);
if (end >= 0 && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.X, vts.Y), end + 1,
if (pEnd >= vts.X && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.X, vts.Y), pEnd - vts.X + 1,
Orientation.Horizontal, lineStyle, attribute);
}
break;
case Side.Right:
lc.AddLine (new Point (vts.Right - 1, vts.Y), end,
lc.AddLine (new Point (vts.Right - 1, vts.Y), pEnd - pStart + 1,
Orientation.Vertical, lineStyle, attribute);
break;
case Side.Bottom:
lc.AddLine (new Point (vts.Right - 1, vts.Y), vts.Height,
Orientation.Vertical, lineStyle, attribute);
lc.AddLine (new Point (vts.Right - 1, vts.Bottom - 1), -(vts.Width - end),
lc.AddLine (new Point (vts.Right - 1, vts.Bottom - 1), -(vts.Right - pEnd),
Orientation.Horizontal, lineStyle, attribute);
break;
}
break;
case Side.Right:
if (start == vts.Bottom - 1) {
lc.AddLine (new Point (vts.Width - 1, start), -1,
if (pStart == vts.Bottom - 1) {
lc.AddLine (new Point (vts.Right - 1, pStart), -1,
Orientation.Vertical, lineStyle, attribute);
} else {
if (end >= start && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.Width - 1, start), end - start + 1,
if (pEnd >= pStart && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.Right - 1, pStart), pEnd - pStart + 1,
Orientation.Vertical, lineStyle, attribute);
break;
} else {
lc.AddLine (new Point (vts.Width - 1, start), vts.Bottom - start,
lc.AddLine (new Point (vts.Right - 1, pStart), vts.Bottom - pStart,
Orientation.Vertical, lineStyle, attribute);
}
}
switch (endPos.side) {
case Side.Left:
lc.AddLine (new Point (vts.Width - 1, vts.Bottom - 1), -vts.Width,
lc.AddLine (new Point (vts.Right - 1, vts.Bottom - 1), -vts.Width,
Orientation.Horizontal, lineStyle, attribute);
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -(vts.Bottom - end),
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -(vts.Bottom - pEnd),
Orientation.Vertical, lineStyle, attribute);
break;
case Side.Top:
lc.AddLine (new Point (vts.Width - 1, vts.Bottom - 1), -vts.Width,
lc.AddLine (new Point (vts.Right - 1, vts.Bottom - 1), -vts.Width,
Orientation.Horizontal, lineStyle, attribute);
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -vts.Height,
Orientation.Vertical, lineStyle, attribute);
lc.AddLine (new Point (vts.X, vts.Y), end,
lc.AddLine (new Point (vts.X, vts.Y), pEnd - vts.X + 1,
Orientation.Horizontal, lineStyle, attribute);
break;
case Side.Right:
lc.AddLine (new Point (vts.Width - 1, vts.Bottom - 1), -vts.Width,
lc.AddLine (new Point (vts.Right - 1, vts.Bottom - 1), -vts.Width,
Orientation.Horizontal, lineStyle, attribute);
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -vts.Height,
Orientation.Vertical, lineStyle, attribute);
lc.AddLine (new Point (vts.X, vts.Y), vts.Width,
Orientation.Horizontal, lineStyle, attribute);
if (end >= 0 && end < vts.Bottom - 1 && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.Width - 1, vts.Y), end + 1,
if (pEnd >= vts.Y && pEnd < vts.Bottom - 1 && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.Right - 1, vts.Y), pEnd - vts.Y + 1,
Orientation.Vertical, lineStyle, attribute);
}
break;
case Side.Bottom:
lc.AddLine (new Point (vts.Width - 1, vts.Bottom - 1), -(vts.Width - end),
lc.AddLine (new Point (vts.Right - 1, vts.Bottom - 1), -(vts.Right - pEnd),
Orientation.Horizontal, lineStyle, attribute);
break;
}
break;
case Side.Bottom:
if (start == vts.X) {
if (pStart == vts.X) {
lc.AddLine (new Point (vts.X, vts.Bottom - 1), 1,
Orientation.Horizontal, lineStyle, attribute);
} else if (end <= start && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.X + start, vts.Bottom - 1), -(start - end + 1),
Orientation.Horizontal, lineStyle, attribute);
break;
} else {
lc.AddLine (new Point (vts.X + start, vts.Bottom - 1), -(start + 1),
Orientation.Horizontal, lineStyle, attribute);
if (pEnd <= pStart && startPos.side == endPos.side) {
lc.AddLine (new Point (pStart, vts.Bottom - 1), -(pStart - pEnd + 1),
Orientation.Horizontal, lineStyle, attribute);
break;
} else {
lc.AddLine (new Point (pStart, vts.Bottom - 1), -(pStart - 1),
Orientation.Horizontal, lineStyle, attribute);
}
}
switch (endPos.side) {
case Side.Left:
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -(vts.Bottom - end),
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -(vts.Bottom - pEnd),
Orientation.Vertical, lineStyle, attribute);
break;
case Side.Top:
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -vts.Height,
Orientation.Vertical, lineStyle, attribute);
lc.AddLine (new Point (vts.X, vts.Y), end + 1,
lc.AddLine (new Point (vts.X, vts.Y), pEnd - 1,
Orientation.Horizontal, lineStyle, attribute);
break;
case Side.Right:
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -vts.Height,
Orientation.Vertical, lineStyle, attribute);
lc.AddLine (new Point (vts.X, vts.Y), vts.Width,
Orientation.Horizontal, lineStyle, attribute);
lc.AddLine (new Point (vts.Width - 1, vts.Y), end,
lc.AddLine (new Point (vts.Right - 1, vts.Y), pEnd - 1,
Orientation.Vertical, lineStyle, attribute);
break;
case Side.Bottom:
lc.AddLine (new Point (vts.X, vts.Bottom - 1), -vts.Height,
Orientation.Vertical, lineStyle, attribute);
lc.AddLine (new Point (vts.X, vts.Y), vts.Width,
Orientation.Horizontal, lineStyle, attribute);
lc.AddLine (new Point (vts.Width - 1, vts.Y), vts.Height,
lc.AddLine (new Point (vts.Right - 1, vts.Y), vts.Height,
Orientation.Vertical, lineStyle, attribute);
if (vts.Width - end > 0 && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.Width - 1, vts.Bottom - 1), -(vts.Width - end),
if (pEnd <= vts.Right - 1 && startPos.side == endPos.side) {
lc.AddLine (new Point (vts.Right - 1, vts.Bottom - 1), -(vts.Right - pEnd),
Orientation.Horizontal, lineStyle, attribute);
}
break;
Expand Down
Loading

0 comments on commit 62adf6f

Please sign in to comment.