| 1 | using System.Globalization; |
| 2 | using Avalonia; |
| 3 | using Avalonia.Media; |
| 4 | using static CascadeIDE.Cockpit.PrimitivesKit.CockpitPrimitivesPalette.Annunciator; |
| 5 | |
| 6 | namespace CascadeIDE.Cockpit.PrimitivesKit; |
| 7 | |
| 8 | /// <summary> |
| 9 | /// Лампа «CMD + зелёная полоса» для CascadeChord (ADR 0060): значение — вооружён ли аккорд; отрисовка в стиле annunciator. |
| 10 | /// </summary> |
| 11 | public readonly record struct CommandArmedStripLampFace(bool IsArmed) |
| 12 | { |
| 13 | /// <summary>IDLE — тёмное лицо; ARMED — подпись CMD и полоса <see cref="CommandArmedStripGreen"/>.</summary> |
| 14 | public void Draw(DrawingContext context, Rect outerRect) |
| 15 | { |
| 16 | AnnunciatorLampChrome.DrawCellHousing(context, outerRect); |
| 17 | |
| 18 | var face = AnnunciatorLampChrome.ComputeFaceSquare(outerRect); |
| 19 | |
| 20 | if (!IsArmed) |
| 21 | { |
| 22 | var offBrush = new LinearGradientBrush |
| 23 | { |
| 24 | StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative), |
| 25 | EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative), |
| 26 | GradientStops = |
| 27 | { |
| 28 | new GradientStop(OffLensTop, 0), |
| 29 | new GradientStop(OffLensBottom, 1), |
| 30 | }, |
| 31 | }; |
| 32 | context.DrawRectangle(offBrush, new Pen(new SolidColorBrush(OffLensBorder), 0.75), face); |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | var faceBase = new LinearGradientBrush |
| 37 | { |
| 38 | StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative), |
| 39 | EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative), |
| 40 | GradientStops = |
| 41 | { |
| 42 | new GradientStop(OffLensTop, 0), |
| 43 | new GradientStop(OffLensBottom, 1), |
| 44 | }, |
| 45 | }; |
| 46 | context.DrawRectangle(faceBase, new Pen(new SolidColorBrush(OffLensBorder), 0.75), face); |
| 47 | |
| 48 | var barH = Math.Max(6.0, face.Height * 0.28); |
| 49 | var padX = Math.Max(2.0, face.Width * 0.08); |
| 50 | var barY = face.Bottom - barH - 2; |
| 51 | var barRect = new Rect(face.X + padX, barY, face.Width - 2 * padX, barH); |
| 52 | |
| 53 | var g = CommandArmedStripGreen; |
| 54 | var gTop = AnnunciatorLampChrome.Lighten(g, 0.18); |
| 55 | var gBot = AnnunciatorLampChrome.Darken(g, 0.22); |
| 56 | var barBrush = new LinearGradientBrush |
| 57 | { |
| 58 | StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative), |
| 59 | EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative), |
| 60 | GradientStops = |
| 61 | { |
| 62 | new GradientStop(gTop, 0), |
| 63 | new GradientStop(g, 0.5), |
| 64 | new GradientStop(gBot, 1), |
| 65 | }, |
| 66 | }; |
| 67 | context.DrawRectangle(barBrush, new Pen(Brushes.Black, 0.5), barRect); |
| 68 | |
| 69 | var labelBottom = barRect.Y - 3; |
| 70 | if (labelBottom <= face.Y + 4) |
| 71 | return; |
| 72 | |
| 73 | var amber = CommandArmedLabelAmber; |
| 74 | var fillBrush = new SolidColorBrush(amber); |
| 75 | var strokeBrush = new SolidColorBrush(OutlinedTextStrokeLit); |
| 76 | const string label = "CMD"; |
| 77 | const double fontSize = 10.5; |
| 78 | var ftFill = new FormattedText( |
| 79 | label, |
| 80 | CultureInfo.InvariantCulture, |
| 81 | FlowDirection.LeftToRight, |
| 82 | AnnunciatorLampChrome.LabelTypeface, |
| 83 | fontSize, |
| 84 | fillBrush); |
| 85 | var ftStroke = new FormattedText( |
| 86 | label, |
| 87 | CultureInfo.InvariantCulture, |
| 88 | FlowDirection.LeftToRight, |
| 89 | AnnunciatorLampChrome.LabelTypeface, |
| 90 | fontSize, |
| 91 | strokeBrush); |
| 92 | var origin = new Point( |
| 93 | face.X + (face.Width - ftFill.Width) / 2, |
| 94 | face.Y + (labelBottom - face.Y - ftFill.Height) / 2); |
| 95 | AnnunciatorLampChrome.DrawOutlinedText(context, ftStroke, ftFill, origin); |
| 96 | } |
| 97 | } |
| 98 | |