diff --git a/Eu07.BlackBox.Views/CabPanel.cs b/Eu07.BlackBox.Views/CabPanel.cs
index 88a8f09..03388ec 100644
--- a/Eu07.BlackBox.Views/CabPanel.cs
+++ b/Eu07.BlackBox.Views/CabPanel.cs
@@ -123,99 +123,145 @@ public sealed class CabPanel : Control
}
Measure(recording);
var culture = CultureInfo.CurrentCulture;
- var extra = s.Extra;
- // The vehicle at the left; who drives, from which cab, at the right.
+ DrawHeader(context, recording.Vehicle(s.Vehicle)?.Name ?? "", s, right);
+ DrawSpeed(context, s, width, right, culture);
+ DrawControls(context, s, width, right, culture);
+ double y = DrawBrakes(context, s, width, right, culture);
+
+ // The traction at the left, as fits what drives the vehicle; the lights of both ends of the train at the right.
+ double half = Pad + width / 2;
+ double driveTop = y + BrakeRow + 4;
+ double top = Section(context, Strings["CabSectionDrive"], Pad, driveTop, half - 10);
+ Section(context, Strings["CabLights"], half + 4, driveTop, right);
+ DrawDrive(context, s, top, half - 10 - Pad, culture);
+ DrawLights(context, s, new Rect(half, top, right - half, 0), culture);
+
+ top = DrawDevices(context, s, new Rect(Pad, top + 3 * DriveRow + 6, width, size.Height), culture);
+ DrawDoors(context, s, top, width, size.Height);
+ }
+
+ private const double BrakeRow = 17;
+
+ /// The vehicle at the left; who drives, from which cab, at the right.
+ private void DrawHeader(DrawingContext context, string name, CabSample s, double right)
+ {
+ string? end = s.CabEnd == 0 ? null : Strings[s.CabEnd > 0 ? "CabEndFront" : "CabEndRear"];
double chipX = right;
- if (s.CabEnd != 0)
- chipX -= ChipLeft(context, Strings[s.CabEnd > 0 ? "CabEndFront" : "CabEndRear"], Palette.Text, chipX, 4) + 5;
- var (driverText, driverBrush) = !s.InCab ? (Strings["CabOutside"], Palette.DimText)
- : s.Driving == Driver.Ai ? (Strings["CabDriverAi"], Palette.Autopilot)
- : (Strings["CabDriverUser"], Palette.UserTrain);
+ if (end is not null)
+ chipX -= ChipLeft(context, end, Palette.Text, chipX, 4) + 5;
+ var (driverText, driverBrush) = DriverChip(s);
chipX -= ChipLeft(context, driverText, driverBrush, chipX, 4) + 10;
- Say(recording.Vehicle(s.Vehicle)?.Name ?? "");
+ Say(name);
Say(driverText);
- if (s.CabEnd != 0)
- Say(Strings[s.CabEnd > 0 ? "CabEndFront" : "CabEndRear"]);
+ if (end is not null)
+ Say(end);
using (context.PushClip(new Rect(Pad, 0, Math.Max(0, chipX - Pad), 28)))
- context.DrawText(MapView.Text(recording.Vehicle(s.Vehicle)?.Name ?? "", Palette.Text, 12, FontWeight.SemiBold), new Point(Pad, 6));
+ context.DrawText(MapView.Text(name, Palette.Text, 12, FontWeight.SemiBold), new Point(Pad, 6));
+ }
- // The speed, large, what the AI would do under it, the accelerations at the right.
- var judgement = DrivingSummary.Judge(s);
- var speed = MapView.Text(s.AbsSpeedKmh.ToString("0", culture), judgement is SpeedJudgement.Over ? Palette.Bad
- : judgement is SpeedJudgement.Slightly ? Palette.Warn : Palette.Text, 36, FontWeight.SemiBold);
+ private (string Text, IBrush Brush) DriverChip(CabSample s)
+ {
+ if (!s.InCab)
+ return (Strings["CabOutside"], Palette.DimText);
+ return s.Driving == Driver.Ai ? (Strings["CabDriverAi"], Palette.Autopilot) : (Strings["CabDriverUser"], Palette.UserTrain);
+ }
+
+ /// The speed, large, what the AI would do under it, the accelerations at the right.
+ private void DrawSpeed(DrawingContext context, CabSample s, double width, double right, CultureInfo culture)
+ {
+ string kmh = s.AbsSpeedKmh.ToString("0", culture);
+ var speed = MapView.Text(kmh, SpeedBrush(DrivingSummary.Judge(s)), 36, FontWeight.SemiBold);
context.DrawText(speed, new Point(Pad, 24));
- Say($"{s.AbsSpeedKmh.ToString("0", culture)} km/h");
+ Say($"{kmh} km/h");
context.DrawText(MapView.Text("km/h", Palette.DimText, 12), new Point(Pad + speed.Width + 4, 24 + speed.Height - 21));
double gaugeX = Pad + Math.Max(150, width * 0.42);
if (s.AiValid)
{
using (context.PushClip(new Rect(Pad, 76, gaugeX - Pad - 8, 40)))
{
- context.DrawText(MapView.Text(string.Format(culture, Strings["CabAiTarget"], s.Ai.TargetKmh), Palette.Target, 12), new Point(Pad, 76));
- Say(string.Format(culture, Strings["CabAiTarget"], s.Ai.TargetKmh));
+ string target = string.Format(culture, Strings["CabAiTarget"], s.Ai.TargetKmh);
+ context.DrawText(MapView.Text(target, Palette.Target, 12), new Point(Pad, 76));
+ Say(target);
if (s.Ai.HasNextLimit)
- Say(string.Format(culture, Strings["LimitAt"], s.Ai.NextLimitKmh, s.Ai.NextLimitDistance));
- if (s.Ai.HasNextLimit)
- context.DrawText(MapView.Text(string.Format(culture, Strings["LimitAt"], s.Ai.NextLimitKmh, s.Ai.NextLimitDistance), Palette.Limit, 11),
- new Point(Pad, 93));
+ {
+ string limit = string.Format(culture, Strings["LimitAt"], s.Ai.NextLimitKmh, s.Ai.NextLimitDistance);
+ Say(limit);
+ context.DrawText(MapView.Text(limit, Palette.Limit, 11), new Point(Pad, 93));
+ }
}
}
double gaugeWidth = right - gaugeX;
Balance(context, Strings["CabAcceleration"], s.Acceleration, 1.5, gaugeX, 34, gaugeWidth);
Balance(context, Strings["CabLateral"], s.LateralAcceleration, 1.5, gaugeX, 70, gaugeWidth);
+ }
- // The controllers.
+ private static IBrush SpeedBrush(SpeedJudgement judgement) => judgement switch
+ {
+ SpeedJudgement.Over => Palette.Bad,
+ SpeedJudgement.Slightly => Palette.Warn,
+ _ => Palette.Text
+ };
+
+ /// The controllers.
+ private void DrawControls(DrawingContext context, CabSample s, double width, double right, CultureInfo culture)
+ {
double top = Section(context, Strings["CabSectionControls"], Pad, 118, right);
double column = width / 4;
Value(context, Strings["CabController"], s.MainController.ToString(culture), Pad, top);
Steps(context, s.MainController, _controllerTop, Pad, top + 34, column - 14);
- if (extra is { } handle && _integrated.Contains(s.Vehicle))
+ if (s.Extra is { } handle && _integrated.Contains(s.Vehicle))
Value(context, Strings["CabIntegrated"], (handle.IntegratedController * 100).ToString("+0;−0;0", culture) + " %", Pad + column, top);
else
Value(context, Strings["CabShunt"], s.ScndController.ToString(culture), Pad + column, top);
- Value(context, Strings["CabReverser"], Strings[s.Reverser > 0 ? "CabForward" : s.Reverser < 0 ? "CabBackward" : "CabNeutral"], Pad + 2 * column, top);
+ string reverser = s.Reverser switch { > 0 => "CabForward", < 0 => "CabBackward", _ => "CabNeutral" };
+ Value(context, Strings["CabReverser"], Strings[reverser], Pad + 2 * column, top);
Value(context, Strings["CabTrainBrake"], s.TrainBrake.ToString("0.0", culture), Pad + 3 * column, top);
+ }
- // The brakes, as gauges, the setting (G, P, R) at the right of the title.
+ /// The brakes, as gauges, the setting (G, P, R) at the right of the title.
+ /// Where the last gauge stands.
+ private double DrawBrakes(DrawingContext context, CabSample s, double width, double right, CultureInfo culture)
+ {
+ var extra = s.Extra;
string? setting = extra is { } e && (e.BrakeDelay | e.BrakeMode) != 0
? string.Format(culture, Strings["CabBrakeSetting"], string.Join(" · ", new[] { BrakeSetting(e.BrakeDelay), BrakeMode(e.BrakeMode) }.Where(t => t.Length > 0)))
: null;
- top = Section(context, Strings["CabSectionBrakes"], Pad, 180, right, setting);
- const double gauge = 17;
- Gauge(context, Strings["CabPipe"], s.BrakePipe, 6, 5, $"{s.BrakePipe:0.00} bar", Palette.Station, Pad, top, width);
- double y = top + gauge;
- if (extra is { } x1)
+ double y = Section(context, Strings["CabSectionBrakes"], Pad, 180, right, setting);
+ var gauges = new List
{
- // what the driver's brake valve shows: its equalizing reservoir, the FV4a's time reservoir
- Gauge(context, Strings["CabDriverValve"], x1.DriverValve, 6, null, $"{x1.DriverValve:0.00} bar", Palette.Target, Pad, y, width);
- y += gauge;
- }
- Gauge(context, Strings["CabCylinder"], s.BrakeCylinder, 6, null, $"{s.BrakeCylinder:0.0} bar", Palette.Brakes, Pad, y, width);
- y += gauge;
- if (extra is { } x3)
- {
- // the most braked vehicle of the train
- Gauge(context, Strings["CabConsistCylinder"], x3.ConsistBrakeCylinder, 6, null, $"{x3.ConsistBrakeCylinder:0.0} bar", Palette.Brakes, Pad, y, width);
- y += gauge;
- }
- Gauge(context, Strings["CabReservoir"], s.MainReservoir, 10, null, $"{s.MainReservoir:0.0} bar", Palette.Controller, Pad, y, width);
- y += gauge;
- if (extra is { } x2)
- {
- bool has = _feedPipe.Contains(s.Vehicle);
- Gauge(context, Strings["CabFeedPipe"], has ? x2.FeedPipe : 0, 10, null, has ? $"{x2.FeedPipe:0.0} bar" : "—", Palette.Controller, Pad, y, width);
- y += gauge;
- }
- Gauge(context, Strings["CabLocalBrake"], s.LocalBrake, 1, null, $"{s.LocalBrake * 100:0} %", Palette.Brakes, Pad, y, width);
+ new(Strings["CabPipe"], s.BrakePipe, 6, 5, $"{s.BrakePipe:0.00} bar", Palette.Station)
+ };
+ // what the driver's brake valve shows: its equalizing reservoir, the FV4a's time reservoir
+ if (extra is { } valve)
+ gauges.Add(new(Strings["CabDriverValve"], valve.DriverValve, 6, null, $"{valve.DriverValve:0.00} bar", Palette.Target));
+ gauges.Add(new(Strings["CabCylinder"], s.BrakeCylinder, 6, null, $"{s.BrakeCylinder:0.0} bar", Palette.Brakes));
+ // the most braked vehicle of the train
+ if (extra is { } most)
+ gauges.Add(new(Strings["CabConsistCylinder"], most.ConsistBrakeCylinder, 6, null, $"{most.ConsistBrakeCylinder:0.0} bar", Palette.Brakes));
+ gauges.Add(new(Strings["CabReservoir"], s.MainReservoir, 10, null, $"{s.MainReservoir:0.0} bar", Palette.Controller));
+ if (extra is { } feed)
+ gauges.Add(FeedPipe(s, feed));
+ gauges.Add(new(Strings["CabLocalBrake"], s.LocalBrake, 1, null, $"{s.LocalBrake * 100:0} %", Palette.Brakes));
- // The traction at the left, as fits what drives the vehicle; the lights of both ends of the train at the right.
- double half = Pad + width / 2;
- double driveTop = y + gauge + 4;
- top = Section(context, Strings["CabSectionDrive"], Pad, driveTop, half - 10);
- Section(context, Strings["CabLights"], half + 4, driveTop, right);
- DrawDrive(context, s, top, half - 10 - Pad, culture);
- double row = top;
+ for (int i = 0; i < gauges.Count; i++)
+ {
+ if (i > 0)
+ y += BrakeRow;
+ Gauge(context, gauges[i], Pad, y, width);
+ }
+ return y;
+ }
+
+ private GaugeReading FeedPipe(CabSample s, CabExtra feed) => _feedPipe.Contains(s.Vehicle)
+ ? new(Strings["CabFeedPipe"], feed.FeedPipe, 10, null, $"{feed.FeedPipe:0.0} bar", Palette.Controller)
+ : new(Strings["CabFeedPipe"], 0, 10, null, "—", Palette.Controller);
+
+ /// The lights of both ends: the signal shown, green as it is to be, red otherwise with the one it is to show.
+ /// Left edge, top and width of the column; its height is not used.
+ private void DrawLights(DrawingContext context, CabSample s, Rect area, CultureInfo culture)
+ {
+ double half = area.X, right = area.Right, row = area.Y;
foreach (var (key, lights, equipped, required, isRight) in new[]
{
("CabLightsHead", s.LightsHead, s.EquippedHead, HeadCodes.RequiredHead(s), HeadCodes.HeadRight(s)),
@@ -223,14 +269,8 @@ public sealed class CabPanel : Control
})
{
DrawFace(context, lights, new Point(half + 4 + 17, row + 15));
- // the end, and under it the signal it shows: green as it is to be (with the lamps the vehicle has),
- // red otherwise with the one it is to show
- var shown = HeadCodes.Of(lights);
- var text = HeadCodes.NoLamps(equipped) ? Strings["CabLightsNone"]
- : isRight == false && required is { } want
- ? string.Format(culture, Strings["CabLightsWant"], HeadCodes.Name(shown), HeadCodes.Name(want))
- : isRight == true && required is { } met ? HeadCodes.Name(met) : HeadCodes.Name(shown);
- var brush = isRight is null ? Palette.DimText : isRight.Value ? Palette.Good : Palette.Bad;
+ string text = LightsText(HeadCodes.Of(lights), HeadCodes.NoLamps(equipped), required, isRight, culture);
+ IBrush brush = isRight switch { null => Palette.DimText, true => Palette.Good, false => Palette.Bad };
Say($"{Strings[key]}: {text}");
using (context.PushClip(new Rect(half + 44, row, right - half - 44, 28)))
{
@@ -239,9 +279,24 @@ public sealed class CabPanel : Control
}
row += 27;
}
+ }
- // The devices, in three groups side by side: lit as their lamps are in the cab, the ones off faint.
- top = Section(context, Strings["CabSectionDevices"], Pad, top + 3 * DriveRow + 6, right);
+ private string LightsText(HeadCode shown, bool noLamps, HeadCode? required, bool? isRight, CultureInfo culture)
+ {
+ if (noLamps)
+ return Strings["CabLightsNone"];
+ if (isRight == false && required is { } want)
+ return string.Format(culture, Strings["CabLightsWant"], HeadCodes.Name(shown), HeadCodes.Name(want));
+ return isRight == true && required is { } met ? HeadCodes.Name(met) : HeadCodes.Name(shown);
+ }
+
+ /// The devices, in three groups side by side: lit as their lamps are in the cab, the ones off faint.
+ /// Left edge, top, width and the height of the whole panel.
+ /// Where the doors go, under them.
+ private double DrawDevices(DrawingContext context, CabSample s, Rect area, CultureInfo culture)
+ {
+ double width = area.Width, height = area.Height;
+ double top = Section(context, Strings["CabSectionDevices"], area.X, area.Y, area.X + width);
var groups = Devices(s, culture);
var widths = new double[groups.Length];
for (int g = 0; g < groups.Length; g++)
@@ -252,27 +307,34 @@ public sealed class CabPanel : Control
}
// each group as wide as its longest name, what is left shared between them
double spare = (width - widths.Sum()) / groups.Length;
- double x = Pad, bottom = top;
+ double x = area.X, bottom = top;
for (int g = 0; g < groups.Length; g++)
{
double groupWidth = Math.Max(20, widths[g] + spare);
- using (context.PushClip(new Rect(x, top, groupWidth, size.Height - top)))
- {
- context.DrawText(MapView.Text(Strings[groups[g].Title], Palette.DimText, 10, FontWeight.SemiBold), new Point(x, top));
- Say(Strings[groups[g].Title]);
- double lampY = top + 16;
- foreach (var (text, brush) in groups[g].Lamps)
- {
- Lamp(context, text, brush, x, lampY);
- lampY += LampRow;
- }
- bottom = Math.Max(bottom, lampY);
- }
+ using (context.PushClip(new Rect(x, top, groupWidth, height - top)))
+ bottom = Math.Max(bottom, DrawGroup(context, groups[g], x, top));
x += groupWidth;
}
+ return Math.Max(bottom, top + 16 + 9 * LampRow) + 6;
+ }
- // The doors under them, in two columns: open, permitted, the departure signal, the steps and the lock.
- top = Math.Max(bottom, top + 16 + 9 * LampRow) + 6;
+ /// Where the group ends.
+ private double DrawGroup(DrawingContext context, (string Title, (string Text, IBrush? Lit)[] Lamps) group, double x, double top)
+ {
+ context.DrawText(MapView.Text(Strings[group.Title], Palette.DimText, 10, FontWeight.SemiBold), new Point(x, top));
+ Say(Strings[group.Title]);
+ double lampY = top + 16;
+ foreach (var (text, brush) in group.Lamps)
+ {
+ Lamp(context, text, brush, x, lampY);
+ lampY += LampRow;
+ }
+ return lampY;
+ }
+
+ /// The doors, in two columns: open, permitted, the departure signal, the steps and the lock.
+ private void DrawDoors(DrawingContext context, CabSample s, double top, double width, double height)
+ {
context.DrawText(MapView.Text(Strings["CabGroupDoors"], Palette.DimText, 10, FontWeight.SemiBold), new Point(Pad, top));
Say(Strings["CabGroupDoors"]);
var doors = Doors(s);
@@ -280,7 +342,7 @@ public sealed class CabPanel : Control
for (int i = 0; i < doors.Length; i++)
{
double doorX = Pad + i % DoorColumns * doorColumn;
- using (context.PushClip(new Rect(doorX, top, doorColumn, size.Height - top)))
+ using (context.PushClip(new Rect(doorX, top, doorColumn, height - top)))
Lamp(context, doors[i].Text, doors[i].Lit, doorX, top + 16 + i / DoorColumns * LampRow);
}
}
@@ -450,9 +512,9 @@ public sealed class CabPanel : Control
}
/// A gauge: its name, a bar up to the value against the scale, a mark where it should stand, the value.
- private void Gauge(DrawingContext context, string label, float value, double scale, double? mark, string text,
- IBrush brush, double x, double y, double width)
+ private void Gauge(DrawingContext context, GaugeReading reading, double x, double y, double width)
{
+ var (label, value, scale, mark, text, brush) = reading;
Say($"{label}: {text}");
const double labelWidth = 118, valueWidth = 64;
context.DrawText(MapView.Text(label, Palette.DimText, 11), new Point(x, y));
@@ -632,4 +694,7 @@ public sealed class CabPanel : Control
doors.Add(On("DevDepartureSignal", CabDevices.DepartureSignal, Palette.LampWarning));
return doors.ToArray();
}
+
+ /// What one gauge shows: its name, the value against the scale, the mark, the value written out.
+ private readonly record struct GaugeReading(string Label, float Value, double Scale, double? Mark, string Text, IBrush Brush);
}
diff --git a/Eu07.BlackBox.Views/Eu07.BlackBox.Views.csproj b/Eu07.BlackBox.Views/Eu07.BlackBox.Views.csproj
index 53efe37..9f92822 100644
--- a/Eu07.BlackBox.Views/Eu07.BlackBox.Views.csproj
+++ b/Eu07.BlackBox.Views/Eu07.BlackBox.Views.csproj
@@ -14,6 +14,10 @@
+
+
+
+
diff --git a/StarterNG.Tests/AnnouncerTests.cs b/StarterNG.Tests/AnnouncerTests.cs
index b407b3d..1d16702 100644
--- a/StarterNG.Tests/AnnouncerTests.cs
+++ b/StarterNG.Tests/AnnouncerTests.cs
@@ -2,6 +2,7 @@ using Avalonia.Automation;
using Avalonia.Automation.Peers;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
+using Avalonia.VisualTree;
using StarterNG.Controls;
namespace StarterNG.Tests;
@@ -49,7 +50,12 @@ public class AnnouncerTests
[Fact]
public void A_control_outside_any_announcer_is_not_heard()
{
- Announcer.Say(new Button(), "Godzina: 07:05");
+ var button = new Button();
+
+ var thrown = Record.Exception(() => Announcer.Say(button, "Godzina: 07:05"));
+
+ Assert.Null(thrown);
+ Assert.Null(button.FindAncestorOfType());
}
[Fact]
diff --git a/StarterNG.Tests/BlackBox/BlackBoxViewsTests.cs b/StarterNG.Tests/BlackBox/BlackBoxViewsTests.cs
new file mode 100644
index 0000000..6102433
--- /dev/null
+++ b/StarterNG.Tests/BlackBox/BlackBoxViewsTests.cs
@@ -0,0 +1,284 @@
+using Avalonia.Automation;
+using Avalonia.Automation.Peers;
+using Avalonia.Automation.Provider;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.VisualTree;
+using Eu07.BlackBox;
+using Eu07.BlackBox.Views;
+
+namespace StarterNG.Tests.BlackBox;
+
+///
+/// The black box's own drawn panels as a screen reader user meets them: reached with Tab,
+/// walked with the keys, their value and description read, what they show said aloud.
+///
+[Collection(AvaloniaControls.Name)]
+public class BlackBoxViewsTests
+{
+ private const uint Head = 1;
+
+ ///
+ /// The user in vehicle 1 from t = 0 to 120: timetable ROJ1 standing at A, stopping at B
+ /// from 60 to 70, passing C at 100; the clock at 10:34 (634 min).
+ ///
+ private static Recording Journey(bool extended = true, byte? engine = null)
+ {
+ var f = new BlackBoxFile().Info()
+ .Vehicle(Head, "EU07-005", "ROJ1")
+ .User(0, Head, true, 1)
+ .Timetable(0, Head, "ROJ1", "A", "C", ("A", -1, 634), ("Stacja_B", 635, 635.5f), ("C", 637.5f, 638))
+ .Station(1, Head, 4, 1, "A", 1150);
+ for (double t = 0; t <= 120; t += 0.5)
+ {
+ float speed = t is >= 55 and < 70 ? 0 : 40;
+ f.Cab(t, Head, 1150 + t * 10, speed, extended: extended, engine: engine, nextLimit: 60, nextDistance: 500,
+ brakeCylinder: t is >= 50 and < 70 ? 2.5f : 0, devices: 0x0207);
+ }
+ f.Station(60, Head, 1, 2, "Stacja_B", 1300)
+ .Station(100, Head, 3, 3, "C", 2150);
+ return BlackBoxReader.Read(f.End(120).Stream());
+ }
+
+ private static IValueProvider Value(Control control) =>
+ Assert.IsAssignableFrom(Controls.Peer(control));
+
+ // --- timeline ---
+
+ [Fact]
+ public void The_timeline_is_a_slider_read_as_the_moment_with_how_to_walk_it()
+ {
+ var timeline = new TimelineView { Spoken = "10:35:12, 40 km/h" };
+ var peer = Controls.Peer(timeline);
+ var value = Value(timeline);
+
+ Assert.Equal(AutomationControlType.Slider, peer.GetAutomationControlType());
+ Assert.Equal("10:35:12, 40 km/h", value.Value);
+ Assert.True(value.IsReadOnly);
+ Assert.False(string.IsNullOrEmpty(peer.GetHelpText()));
+ Assert.True(peer.IsContentElement());
+ Assert.True(peer.IsControlElement());
+ Assert.Throws(() => value.SetValue("x"));
+
+ timeline.Spoken = "10:35:22, 40 km/h";
+ Assert.Equal("10:35:22, 40 km/h", value.Value);
+ }
+
+ [Fact]
+ public void A_description_set_on_the_timeline_wins_over_its_own()
+ {
+ var timeline = new TimelineView();
+ AutomationProperties.SetHelpText(timeline, "own words");
+
+ Assert.Equal("own words", Controls.Peer(timeline).GetHelpText());
+ }
+
+ [Theory]
+ [InlineData(Key.Right, KeyModifiers.None, 70)]
+ [InlineData(Key.Left, KeyModifiers.None, 50)]
+ [InlineData(Key.Right, KeyModifiers.Control, 120)]
+ [InlineData(Key.Left, KeyModifiers.Control, 0)]
+ [InlineData(Key.PageDown, KeyModifiers.None, 120)]
+ [InlineData(Key.PageUp, KeyModifiers.None, 0)]
+ [InlineData(Key.Home, KeyModifiers.None, 0)]
+ [InlineData(Key.End, KeyModifiers.None, 120)]
+ public void The_keys_take_the_timeline_through_the_recording(Key key, KeyModifiers modifiers, double expected)
+ {
+ var timeline = new TimelineView { Recording = Journey(), Time = 60 };
+ double? sought = null;
+ timeline.Seek += t => sought = t;
+
+ Assert.True(Controls.Press(timeline, key, modifiers));
+ Assert.Equal(expected, sought);
+ }
+
+ [Fact]
+ public void Other_keys_and_an_empty_timeline_are_left_alone()
+ {
+ var empty = new TimelineView();
+ var timeline = new TimelineView { Recording = Journey(), Time = 60 };
+ bool sought = false;
+ empty.Seek += _ => sought = true;
+ timeline.Seek += _ => sought = true;
+
+ Assert.False(Controls.Press(empty, Key.Right));
+ Assert.False(Controls.Press(timeline, Key.A));
+ Assert.False(sought);
+ }
+
+ [Fact]
+ public void The_timeline_draws_with_and_without_the_focus()
+ {
+ var timeline = new TimelineView { Recording = Journey(), Time = 60 };
+ var window = Controls.Show(timeline, 900, 300);
+ try
+ {
+ timeline.Fit();
+ Controls.Draw(timeline);
+ Assert.True(timeline.IsFocused);
+ timeline.Time = 119;
+ Controls.Draw(timeline);
+ window.Focus();
+ Controls.Draw(timeline);
+ }
+ finally
+ {
+ window.Close();
+ }
+ }
+
+ // --- timetable ---
+
+ [Fact]
+ public void The_timetable_is_a_list_read_row_by_row_from_the_keys()
+ {
+ var table = new TimetablePanel { Recording = Journey(), Time = 30 };
+ var peer = Controls.Peer(table);
+ var value = Value(table);
+
+ Assert.Equal(AutomationControlType.List, peer.GetAutomationControlType());
+ Assert.False(string.IsNullOrEmpty(peer.GetHelpText()));
+ Assert.StartsWith("1/3. A", value.Value);
+
+ Assert.True(Controls.Press(table, Key.Down));
+ Assert.StartsWith("2/3. Stacja B", value.Value);
+ Assert.True(Controls.Press(table, Key.Up));
+ Assert.StartsWith("1/3. A", value.Value);
+ Assert.True(Controls.Press(table, Key.End));
+ Assert.StartsWith("3/3. C", value.Value);
+ Assert.True(Controls.Press(table, Key.Down));
+ Assert.StartsWith("3/3. C", value.Value);
+ Assert.True(Controls.Press(table, Key.Home));
+ Assert.StartsWith("1/3. A", value.Value);
+ Assert.Contains("km 2.5", value.Value.Replace(',', '.'));
+ Assert.False(Controls.Press(table, Key.A));
+ }
+
+ [Fact]
+ public void Enter_on_a_station_passed_goes_to_a_little_before_it()
+ {
+ var table = new TimetablePanel { Recording = Journey(), Time = 110 };
+ double? sought = null;
+ table.Seek += t => sought = t;
+
+ Controls.Press(table, Key.Home);
+ Controls.Press(table, Key.Down);
+
+ Assert.True(Controls.Press(table, Key.Enter));
+ Assert.Equal(55, sought);
+ }
+
+ [Fact]
+ public void A_recording_without_a_timetable_says_so_and_ignores_the_keys()
+ {
+ var recording = BlackBoxReader.Read(new BlackBoxFile().Info().Vehicle(Head, "EU07-005")
+ .Cab(0, Head, 1150, 40).End(1).Stream());
+ var table = new TimetablePanel { Recording = recording, Time = 0 };
+
+ Assert.False(string.IsNullOrEmpty(Value(table).Value));
+ Assert.False(Controls.Press(table, Key.Down));
+ table.Recording = null;
+ Controls.Lay(table);
+ Controls.Draw(table);
+ }
+
+ [Fact]
+ public void The_timetable_draws_its_rows_and_the_one_the_keys_stand_at()
+ {
+ var table = new TimetablePanel { Recording = Journey(), Time = 65 };
+ var window = Controls.Show(table, 600, 400);
+ try
+ {
+ Controls.Draw(table);
+ Controls.Press(table, Key.Down);
+ Controls.Draw(table);
+ window.Focus();
+ Controls.Draw(table);
+ }
+ finally
+ {
+ window.Close();
+ }
+ }
+
+ // --- cab ---
+
+ [Theory]
+ [InlineData(true, null)]
+ [InlineData(true, (byte)1)]
+ [InlineData(true, (byte)2)]
+ [InlineData(false, null)]
+ public void The_cab_says_what_it_draws(bool extended, byte? engine)
+ {
+ var cab = new CabPanel { Recording = Journey(extended, engine), Time = 30 };
+ Controls.Lay(cab, 600, 900);
+
+ Controls.Draw(cab);
+
+ Assert.NotNull(cab.Said);
+ Assert.Contains("EU07-005", cab.Said);
+ Assert.Contains("40 km/h", cab.Said);
+ Assert.Equal(AutomationControlType.Pane, Controls.Peer(cab).GetAutomationControlType());
+ Assert.Equal(cab.Said, Controls.Peer(cab).GetHelpText());
+ }
+
+ [Fact]
+ public void The_cab_stopped_under_the_brakes_and_out_of_the_recording()
+ {
+ var cab = new CabPanel { Recording = Journey(), Time = 60 };
+ var window = Controls.Show(cab, 600, 900);
+ try
+ {
+ Controls.Draw(cab);
+ Assert.Contains("0 km/h", cab.Said);
+
+ cab.Time = 500;
+ Controls.Draw(cab);
+ Assert.DoesNotContain("km/h", cab.Said);
+ }
+ finally
+ {
+ window.Close();
+ }
+ }
+
+ [Fact]
+ public void An_empty_cab_says_there_is_nothing_to_show()
+ {
+ var cab = new CabPanel();
+ Controls.Lay(cab);
+
+ Controls.Draw(cab);
+
+ Assert.False(string.IsNullOrEmpty(cab.Said));
+ }
+
+ // --- segmented choice ---
+
+ [Fact]
+ public void A_segmented_choice_is_a_row_of_tabs_one_of_them_selected()
+ {
+ var choice = new UiKit.Segmented("Mapa", "Profil", "Rozkład");
+ int? picked = null;
+ choice.SelectedChanged += i => picked = i;
+ var tabs = choice.GetVisualDescendants().OfType