//绘制左边速度(空速 )矩形 private void RedrawSpeed() { Rectangle rectangle = new Rectangle(); rectangle.Width = 50; rectangle.Height = 150; rectangle.StrokeThickness = 2; rectangle.Stroke = Brushes.White; Canvas.SetTop(rectangle, -rectangle.Height / 2); Canvas.SetLeft(rectangle, 0); Canvas_ViewPortLeft.Children.Add(rectangle); double from = AirSpeed - AirSpeed % 5 + 15; if (from < 25) { from = 25; } double space = (rectangle.Height - 20) / 5; for (int i = 0; i < 6; i++) { Line li = new Line(); li.X1 = rectangle.Width; li.Y1 = -rectangle.Height / 2 + 10 + space * i; li.X2 = li.X1 - 10; li.Y2 = li.Y1; li.StrokeThickness = 2; li.Stroke = Brushes.White; Canvas_ViewPortLeft.Children.Add(li); BorderTextLabel texti = new BorderTextLabel(); texti.Width = 22; texti.Stroke = Brushes.DimGray; texti.HorizontalContentAlignment = HorizontalAlignment.Right; texti.Text = (from - i * 5).ToString("##0"); texti.Foreground = Brushes.White; texti.FontSize = 16; texti.FontWeight = FontWeights.Bold; Canvas.SetLeft(texti, li.X2 - texti.Width - 4); Canvas.SetTop(texti, li.Y1 - 10); Canvas_ViewPortLeft.Children.Add(texti); } TextBlock textblock = new TextBlock(); textblock.Width = 30; textblock.Padding = new Thickness(2, 0, 0, 0); textblock.TextAlignment = TextAlignment.Left; textblock.Text = AirSpeed.ToString("##0.#"); textblock.Foreground = Brushes.White; textblock.Background = Brushes.Red; textblock.FontSize = 12; textblock.FontWeight = FontWeights.Bold; double offset = (from - AirSpeed) / 25 * (rectangle.Height - 20) - rectangle.Height / 2 + 10; Canvas.SetTop(textblock, offset - 8); Canvas.SetLeft(textblock, 0); Canvas_ViewPortLeft.Children.Add(textblock); }
private void RedrawOthersInfoText() { BorderTextLabel airspeedlabel = new BorderTextLabel(); airspeedlabel.Stroke = Brushes.DimGray; airspeedlabel.Foreground = Brushes.White; airspeedlabel.FontSize = 14; airspeedlabel.FontWeight = FontWeights.Bold; airspeedlabel.Text = "空速 " + AirSpeed.ToString("0.0"); Canvas.SetLeft(airspeedlabel, 4); Canvas.SetTop(airspeedlabel, 80); Canvas_ViewPortLeft.Children.Add(airspeedlabel); BorderTextLabel groundspeedlabel = new BorderTextLabel(); groundspeedlabel.Stroke = Brushes.DimGray; groundspeedlabel.Foreground = Brushes.White; groundspeedlabel.FontSize = 14; groundspeedlabel.FontWeight = FontWeights.Bold; groundspeedlabel.Text = "地速 " + GroundSpeed.ToString("0.0"); Canvas.SetLeft(groundspeedlabel, 4); Canvas.SetTop(groundspeedlabel, 100); Canvas_ViewPortLeft.Children.Add(groundspeedlabel); BorderTextLabel batteryabel = new BorderTextLabel(); batteryabel.Stroke = Brushes.DimGray; batteryabel.Foreground = Brushes.White; batteryabel.FontSize = 14; batteryabel.FontWeight = FontWeights.Bold; batteryabel.Text = string.Format("电池 {0} v {1} A {2}%", Voltage.ToString("0.00"), Galvanic.ToString("0.0"), BatteryPercent * 100); Canvas.SetLeft(batteryabel, 10); Canvas.SetTop(batteryabel, 130); Canvas_ViewPortLeft.Children.Add(batteryabel); if (HasEKF) { BorderTextLabel ekflabel = new BorderTextLabel(); ekflabel.Stroke = Brushes.DimGray; ekflabel.Foreground = Brushes.White; ekflabel.FontSize = 14; ekflabel.FontWeight = FontWeights.Bold; ekflabel.Text = "EKF"; Canvas.SetLeft(ekflabel, 200); Canvas.SetTop(ekflabel, 130); Canvas_ViewPortLeft.Children.Add(ekflabel); } if (HasVibe) { BorderTextLabel vibelabel = new BorderTextLabel(); vibelabel.Stroke = Brushes.DimGray; vibelabel.Foreground = Brushes.Red; vibelabel.FontSize = 14; vibelabel.FontWeight = FontWeights.Bold; vibelabel.Text = "Vibe"; Canvas.SetLeft(vibelabel, 250); Canvas.SetTop(vibelabel, 130); Canvas_ViewPortLeft.Children.Add(vibelabel); } BorderTextLabel gpslabel = new BorderTextLabel(); gpslabel.Stroke = Brushes.DimGray; gpslabel.Foreground = Brushes.Red; gpslabel.FontSize = 14; gpslabel.FontWeight = FontWeights.Bold; string s = HasGPS ? "有GPS" : "无GPS"; gpslabel.Text = "GPS: " + s; Canvas.SetLeft(gpslabel, 300); Canvas.SetTop(gpslabel, 130); Canvas_ViewPortLeft.Children.Add(gpslabel); BorderTextLabel flytimelabel = new BorderTextLabel(); flytimelabel.Stroke = Brushes.DimGray; flytimelabel.Foreground = Brushes.White; flytimelabel.FontSize = 14; flytimelabel.FontWeight = FontWeights.Bold; flytimelabel.Text = new TimeSpan(FlyTime).ToString(@"hh\:mm\:ss"); Canvas.SetLeft(flytimelabel, -80); Canvas.SetTop(flytimelabel, -110); Canvas_ViewPortRight.Children.Add(flytimelabel); }
private void DrawLeftScale(Graphics g, RectangleF screenRect) { var middleX = screenRect.Left + screenRect.Width / 2.0f; var middleY = screenRect.Top + screenRect.Height / 2.0f; var halfHeight = screenRect.Height / 2.0f; var leftScaleRight = middleX - WingsThickness * 20.0f - 15; var scaleDim = new SolidBrush(Color.FromArgb(100, Color.Gray)); var borderPen = new Pen(Color.FromArgb(200, Color.Gray)); using (var p = new PointF(leftScaleRight, middleY) .StartDrawing() .MoveRel(0, -15) .MoveRel(-12, 0) .MoveRel(0, -halfHeight + 30) .MoveRel(-30, 0) .MoveRel(0, halfHeight - 30) .MoveRel(-12, 0) .MoveRel(0, 30) .MoveRel(12, 0) .MoveRel(0, halfHeight - 30) .MoveRel(30, 0) .MoveRel(0, -halfHeight + 30) .MoveRel(12, 0) .MoveRel(0, -15) .ConvertToPath()) { p.CloseFigure(); g.FillPath(scaleDim, p); g.DrawPath(borderPen, p); } var middleText = leftScaleRight - 27; var value = AirSpeed.ToString(AirSpeedFormat); var airSpeedColor = (AirSpeed > AirSpeedSafetyTop || AirSpeed < AirSpeedSafetyBottom) ? AirSpeedColorWarn : ScaleNormalColor; using (var p = new PointF(leftScaleRight + 5, middleY) .StartDrawing() .MoveRel(-5, -5) .MoveRel(0, -10) .MoveRel(-54, 0) .MoveRel(0, 30) .MoveRel(54, 0) .MoveRel(0, -10) .MoveRel(5, -5) .ConvertToPath()) { p.CloseFigure(); g.DrawPath(new Pen(airSpeedColor), p); } var counter = 1; var normalBrush = new SolidBrush(ScaleNormalColor); var safetyBad = new HatchBrush(HatchStyle.WideUpwardDiagonal, Color.Orange, Color.Black); var safetyGood = new SolidBrush(Color.Green); var normalPen = new Pen(ScaleNormalColor); var middleOfScaleLeft = leftScaleRight - 12; for (float up = middleY - 30, down = middleY + 30; up > screenRect.Top + 20; up -= 25, down += 25, counter++) { var valUp = AirSpeed + counter * AirSpeedStep; var valDown = AirSpeed - counter * AirSpeedStep; var sUp = valUp.ToString(AirSpeedFormat); var sDown = valDown.ToString(AirSpeedFormat); var sizeUp = g.MeasureString(sUp, ScaleFontSmall); var sizeDown = g.MeasureString(sDown, ScaleFontSmall); g.DrawString(sUp, ScaleFontSmall, normalBrush, middleText - sizeUp.Width / 2.0f, up - sizeUp.Height / 2.0f); g.DrawString(sDown, ScaleFontSmall, normalBrush, middleText - sizeDown.Width / 2.0f, down - sizeDown.Height / 2.0f); g.DrawLine(normalPen, middleOfScaleLeft, up, middleOfScaleLeft - 3, up); g.DrawLine(normalPen, middleOfScaleLeft, down, middleOfScaleLeft - 3, down); var bUp = (valUp > AirSpeedSafetyTop || valUp < AirSpeedSafetyBottom) ? (Brush)safetyBad : safetyGood; var bDown = (valDown > AirSpeedSafetyTop || valDown < AirSpeedSafetyBottom) ? (Brush)safetyBad : safetyGood; g.FillRectangle(bUp, middleOfScaleLeft, up - 15, 5, 30); g.FillRectangle(bDown, middleOfScaleLeft, down - 15, 5, 30); } g.FillRectangle(Brushes.Black, middleOfScaleLeft - 29, middleY + halfHeight - 35, 29, 19); g.FillRectangle(Brushes.Black, middleOfScaleLeft - 29, middleY - halfHeight + 15, 29, 19); var sizeU = g.MeasureString(AirSpeedUnits, ScaleFontSmall); g.DrawString(AirSpeedUnits, ScaleFontSmall, Brushes.White, middleText - sizeU.Width / 2.0f, middleY + halfHeight - 27 - sizeU.Height / 2.0f); sizeU = g.MeasureString("TAS", ScaleFontSmall); g.DrawString("TAS", ScaleFontSmall, Brushes.White, middleText - sizeU.Width / 2.0f, middleY - halfHeight + 24 - sizeU.Height / 2.0f); var size = g.MeasureString(value, ScaleFontBig); using (var p = new PointF(leftScaleRight + 4, middleY) .StartDrawing() .MoveRel(-5, -5) .MoveRel(0, -9) .MoveRel(-52, 0) .MoveRel(0, 29) .MoveRel(52, 0) .MoveRel(0, -9) .MoveRel(4, -4) .ConvertToPath()) { p.CloseFigure(); g.FillPath(Brushes.Black, p); } g.DrawString(value, ScaleFontBig, new SolidBrush(airSpeedColor), middleText - size.Width / 2.0f, middleY - size.Height / 2.0f); }