Example #1
0
void
HorizonRenderer::Draw(Canvas &canvas, const PixelRect &rc,
                      const HorizonLook &look,
                      const AttitudeState &attitude)
{
  /*
  This feature of having a backup artificial horizon based on inferred
  orientation from GPS and vario data is useful, and reasonably well
  tested, but has the issue of potentially invalidating use of XCSoar in
  FAI contests due to rule ref Annex A to Section 3 (2010 Edition) 4.1.2
  "No instruments permitting pilots to fly without visual reference to
  the ground may be carried on board, even if made unserviceable."  The
  quality of XCSoar's pseudo-AH is arguably good enough that this
  violates the rule.  We need to seek clarification as to whether this
  is the case or not.
  */

  const RasterPoint center = rc.GetCenter();

  const int radius = std::min(rc.right - rc.left, rc.bottom - rc.top) / 2
    - Layout::Scale(1);

  auto bank_degrees = attitude.IsBankAngleUseable()
    ? attitude.bank_angle.Degrees()
    : 0.;

  auto pitch_degrees = attitude.IsPitchAngleUseable()
    ? attitude.pitch_angle.Degrees()
    : 0.;

  auto phi = Clamp(bank_degrees, -89., 89.);
  auto alpha = Angle::acos(Clamp(pitch_degrees / 50,
                                 -1., 1.));
  auto sphi = Angle::HalfCircle() - Angle::Degrees(phi);
  auto alpha1 = sphi - alpha;
  auto alpha2 = sphi + alpha;

  // draw sky part
  canvas.Select(look.sky_pen);
  canvas.Select(look.sky_brush);
  canvas.DrawSegment(center.x, center.y, radius, alpha2, alpha1, true);

  // draw ground part
  canvas.Select(look.terrain_pen);
  canvas.Select(look.terrain_brush);
  canvas.DrawSegment(center.x, center.y, radius, alpha1, alpha2, true);

  // draw aircraft symbol
  canvas.Select(look.aircraft_pen);
  canvas.DrawLine(center.x + radius / 2, center.y, center.x - radius / 2, center.y);
  canvas.DrawLine(center.x, center.y - radius / 4, center.x, center.y);

  // draw 45 degree dash marks
  const int rr2p = uround(radius * M_SQRT1_2) + Layout::Scale(1);
  const int rr2n = rr2p - Layout::Scale(2);
  canvas.DrawLine(center.x + rr2p, center.y - rr2p,
              center.x + rr2n, center.y - rr2n);
  canvas.DrawLine(center.x - rr2p, center.y - rr2p,
              center.x - rr2n, center.y - rr2n);
}
Example #2
0
void
HorizonRenderer::Draw(Canvas &canvas, const PixelRect &rc, const NMEAInfo &Basic)
{
    /*
    This feature of having a backup artificial horizon based on inferred
    orientation from GPS and vario data is useful, and reasonably well
    tested, but has the issue of potentially invalidating use of XCSoar in
    FAI contests due to rule ref Annex A to Section 3 (2010 Edition) 4.1.2
    "No instruments permitting pilots to fly without visual reference to
    the ground may be carried on board, even if made unserviceable."  The
    quality of XCSoar's pseudo-AH is arguably good enough that this
    violates the rule.  We need to seek clarification as to whether this
    is the case or not.
    */

    RasterPoint center;
    center.y = (rc.top + rc.bottom) / 2;
    center.x = (rc.left + rc.right) / 2;
    const int radius = min(rc.right - rc.left, rc.bottom - rc.top) / 2 -
                       Layout::Scale(1);

    Pen hpHorizonSky(Layout::Scale(1), DarkColor(Graphics::skyColor));
    Brush hbHorizonSky(Graphics::skyColor);
    Pen hpHorizonGround(Layout::Scale(1), DarkColor(Graphics::GroundColor));

#define fixed_div fixed(1.0 / 50.0)
#define fixed_89 fixed_int_constant(89)

    fixed phi = max(-fixed_89,
                    min(fixed_89, Basic.acceleration.bank_angle.Degrees()));
    fixed alpha = fixed_rad_to_deg * acos(max(-fixed_one,min(fixed_one,
                                          Basic.acceleration.pitch_angle.Degrees() * fixed_div)));
    fixed sphi = fixed_180 - phi;
    Angle alpha1 = Angle::Degrees(sphi - alpha);
    Angle alpha2 = Angle::Degrees(sphi + alpha);

    // draw sky part
    canvas.Select(hpHorizonSky);
    canvas.Select(hbHorizonSky);
    canvas.DrawSegment(center.x, center.y, radius, alpha2, alpha1, true);

    // draw ground part
    canvas.Select(hpHorizonGround);
    canvas.Select(Graphics::hbGround);
    canvas.DrawSegment(center.x, center.y, radius, alpha1, alpha2, true);

    // draw aircraft symbol
    Pen aircraft_pen(Layout::Scale(2), COLOR_BLACK);
    canvas.Select(aircraft_pen);
    canvas.line(center.x + radius / 2, center.y, center.x - radius / 2, center.y);
    canvas.line(center.x, center.y - radius / 4, center.x, center.y);

    // draw 45 degree dash marks
    const UPixelScalar rr2p = uround(radius * fixed_sqrt_half) + Layout::Scale(1);
    const UPixelScalar rr2n = rr2p - Layout::Scale(2);
    canvas.line(center.x + rr2p, center.y - rr2p,
                center.x + rr2n, center.y - rr2n);
    canvas.line(center.x - rr2p, center.y - rr2p,
                center.x - rr2n, center.y - rr2n);
}
void 
TaskProgressRenderer::Draw(const TaskSummary& summary, Canvas &canvas,
                           const PixelRect &rc, bool inverse)
{
  const int radius = std::min(rc.right - rc.left, rc.bottom - rc.top) / 2 - 
                     Layout::Scale(3);
  RasterPoint center;
  center.x = (rc.left + rc.right) / 2;
  center.y = (rc.bottom + rc.top) / 2;

  const fixed sweep = fixed_two_pi * fixed(0.9);
  Pen pen_f(1, inverse ? COLOR_WHITE : COLOR_BLACK);

  if (summary.p_remaining < fixed(0.99)) {
    canvas.Select(look.hbGray);
    canvas.SelectNullPen();
    canvas.DrawSegment(center.x, center.y, radius, Angle::Zero(),
                   Angle::Radians(sweep * (fixed(1) -  summary.p_remaining)));
  }

  canvas.Select(pen_f);
  canvas.SelectHollowBrush();
  canvas.DrawCircle(center.x, center.y, radius);

  unsigned i = 0;
  canvas.Select(pen_f);
  for (auto it = summary.pts.begin(); it != summary.pts.end(); ++it, ++i) {
    Angle a = Angle::Radians(it->p * sweep);
    int x = center.x + (int)(radius * a.fastsine());
    int y = center.y - (int)(radius * a.fastcosine());
    int w;
    if (i == summary.active) {
      if (it->achieved)
        canvas.Select(look.hbGreen);
      else
        canvas.Select(look.hbOrange);

      w = Layout::Scale(3);
    } else if (i < summary.active) {
      if (it->achieved)
        canvas.Select(look.hbGreen);
      else
        canvas.Select(look.hbNotReachableTerrain);

      w = Layout::Scale(2);
    } else {
      if (it->achieved)
        canvas.Select(look.hbGreen);
      else
        canvas.Select(look.hbLightGray);

      w = Layout::Scale(1);
    }
    
    canvas.Rectangle(x - w, y - w, x + w, y + w);
  }
}
Example #4
0
//------------------------------------------------------------------------------
int
main(int argc, char *argv[])
  {
  QApplication app(argc, argv);
  Canvas c;
  Pen(Pen::SOLID, 1, Color(0, 0, 0));
    {
    c.Select(Brush(Color(128, 128, 0, Color::TRANSPARENT)));
    c.DrawKeyhole(200, 100, 50, 100, Angle::Degrees(-20), Angle::Degrees(20));
    c.DrawKeyhole(400, 100, 50, 100, Angle::Degrees(70), Angle::Degrees(110));
    c.DrawKeyhole(200, 300, 50, 100, Angle::Degrees(160), Angle::Degrees(200));
    c.DrawKeyhole(400, 300, 50, 100, Angle::Degrees(-110), Angle::Degrees(-70));
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawKeyhole(200, 100, 50, 100, Angle::Degrees(35), Angle::Degrees(55));
    c.DrawKeyhole(400, 100, 50, 100, Angle::Degrees(125), Angle::Degrees(145));
    c.DrawKeyhole(200, 300, 50, 100, Angle::Degrees(215), Angle::Degrees(235));
    c.DrawKeyhole(400, 300, 50, 100, Angle::Degrees(305), Angle::Degrees(325));
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawFilledRectangle(0, 0, 100, 100, Color(128, 128, 128,
                                                Color::TRANSPARENT));
    c.DrawFilledRectangle(100, 100, 200, 200, Color(128, 0, 0,
                                                    Color::TRANSPARENT));
    c.DrawFilledRectangle(150, 150, 250, 250, Color(0, 128, 0,
                                                    Color::TRANSPARENT));
    c.DrawFilledRectangle(200, 200, 300, 300, Color(0, 0, 128,
                                                    Color::TRANSPARENT));
    c.DrawTransparentText(0, 0, "0");
    c.DrawTransparentText(0, 100, "100");
    c.DrawTransparentText(0, 200, "200");
    c.DrawTransparentText(0, 300, "300");
    c.DrawTransparentText(0, 400, "400");
    c.DrawTransparentText(0, 500, "500");
    c.DrawTransparentText(100, c.GetFontHeight(), "100");
    c.DrawTransparentText(200, c.GetFontHeight(), "200");
    c.DrawTransparentText(300, c.GetFontHeight(), "300");
    c.DrawTransparentText(400, c.GetFontHeight(), "400");
    c.DrawTransparentText(500, c.GetFontHeight(), "500");
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawOutlineRectangle(100, 100, 200, 200, Color(255, 0, 0));
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawRoundRectangle(100, 100, 200, 200, 10, 10);
    c.DrawRoundRectangle(200, 200, 300, 300, 100, 100);
    c.DrawRoundRectangle(300, 300, 400, 400, 50, 50);
    c.show();
    app.exec();
    }
    {
    c.Clear();
    PixelRect rc;
    rc.left   = 100;
    rc.top    = 100;
    rc.right  = 200;
    rc.bottom = 200;
    c.DrawRaisedEdge(rc);
    c.show();
    app.exec();
    }
    {
    c.Clear();
    RasterPoint rp[4];
    rp[0] = {100, 100};
    rp[1] = {200, 200};
    rp[2] = {200, 300};
    rp[3] = {300, 400};
    c.DrawPolyline(rp, 4);
    c.show();
    app.exec();
    }
    {
    c.Clear();
    RasterPoint rp[6];
    rp[0] = {100, 100};
    rp[1] = {150,  50};
    rp[2] = {200, 100};
    rp[3] = {200, 200};
    rp[4] = {150, 200};
    rp[5] = {100, 100};
    c.DrawPolygon(rp, 6);
    c.show();
    app.exec();
    }
    {
    c.Clear();
    RasterPoint rp[4];
    rp[0] = {100, 100};
    rp[1] = {200,  50};
    rp[2] = {200, 150};
    rp[3] = {150, 200};
    c.DrawTriangleFan(rp, 4);
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawHLine(100, 200, 100, Color(255, 0, 0));
    c.DrawHLine(100, 200, 200, Color(0, 255, 0));
    c.DrawHLine(100, 200, 300, Color(0, 0, 255));
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawLine(100, 100, 200, 200);
    c.DrawCircle(250, 250, 50);
    c.DrawSegment(100, 250, 50, Angle::Degrees(10), Angle::Degrees(30), false);
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawAnnulus(100, 100, 50, 100, Angle::Degrees(10), Angle::Degrees(60));
    c.DrawAnnulus(300, 100, 50, 100, Angle::Degrees(0),  Angle::Degrees(360));
    c.DrawAnnulus(100, 300, 50, 100, Angle::Degrees(0),  Angle::Degrees(0));
    c.show();
    app.exec();
    }
    {
    PixelSize rc = c.CalcTextSize("Hello");
    std::cout << "Size of \"Hello\": " << rc.cx << ", " << rc.cy << std::endl;
    c.DrawClippedText(100, 100, rc.cx / 2, "Hello");
    c.show();
    app.exec();
    }
    {
    std::cout << "Height of font: " << c.GetFontHeight() << std::endl;
    }
    {
    c.Clear();
    c.DrawText(0, 50, "50");
    c.Clear();
    c.show();
    return app.exec();
    }
  }
Example #5
0
  void paint(Canvas &canvas) {
    canvas.SelectHollowBrush();
    canvas.SelectBlackPen();

    Brush red_brush(COLOR_RED);

    const PixelRect rc = GetClientRect();
    const int width = rc.right - rc.left;
    const int height = rc.bottom - rc.top;
    const int hmiddle = (rc.left + rc.right) / 2;
    const int vmiddle = (rc.top + rc.bottom) / 2;

    RasterPoint p1[3] = {
      { -100, vmiddle },
      { (width * 2) / 3, -100 },
      { hmiddle, height * 2 },
    };

    RasterPoint p2[3] = {
      { -2000, vmiddle },
      { width * 10, -3000 },
      { width * 5, 3000 },
    };

    const TCHAR *label;
    switch (page) {
    case 0:
      canvas.DrawSegment(hmiddle, vmiddle,
                     min(width, height) / 3,
                     Angle::Zero(), Angle::Degrees(90),
                     false);
      label = _T("segment 0-90 horizon=false");
      break;

    case 1:
      canvas.DrawSegment(hmiddle, vmiddle,
                     min(width, height) / 3,
                     Angle::Degrees(45), Angle::Degrees(180),
                     true);
      label = _T("segment 45-180 horizon=true");
      break;

    case 2:
      canvas.DrawCircle(hmiddle, vmiddle,
                    min(width, height) / 3);
      label = _T("circle");
      break;

    case 3:
    case 4:
      PixelRect rc;
      rc.left = hmiddle - 50;
      rc.top = vmiddle - 20;
      rc.right = hmiddle + 50;
      rc.bottom = vmiddle + 20;
      canvas.DrawButton(rc, page == 4);
      label = page == 4
        ? _T("button down=true") : _T("button down=false");
      break;

    case 5:
      canvas.Select(red_brush);
      canvas.DrawPolygon(p1, 3);
      label = _T("big polygon");
      break;

    case 6:
      canvas.Select(red_brush);
      canvas.DrawPolygon(p2, 3);
      label = _T("huge polygon");
      break;
    }

    canvas.SetTextColor(Color(0, 0, 128));
    canvas.SetBackgroundTransparent();
    canvas.Select(normal_font);
    canvas.DrawText(5, 5, label);
#ifndef ENABLE_OPENGL
    canvas.DrawText(5, 25,
                    buffered ? _T("buffered") : _T("not buffered"));
#endif
  }
Example #6
0
void
OZRenderer::Draw(Canvas &canvas, Layer layer, const Projection &projection,
                 const ObservationZonePoint &_oz, int offset)
{
  if (layer == LAYER_SHADE && offset < 0)
    return;

  Prepare(canvas, layer, offset);

  switch (_oz.shape) {
  case ObservationZonePoint::LINE:
  case ObservationZonePoint::FAI_SECTOR: {
    const SectorZone &oz = (const SectorZone &)_oz;

    RasterPoint p_center = projection.GeoToScreen(oz.get_location());
    if (layer != LAYER_ACTIVE)
      canvas.DrawSegment(p_center.x, p_center.y,
                         projection.GeoToScreenDistance(oz.getRadius()),
                         oz.getStartRadial() - projection.GetScreenAngle(),
                         oz.getEndRadial() - projection.GetScreenAngle());
    else {
      RasterPoint p_start = projection.GeoToScreen(oz.get_SectorStart());
      RasterPoint p_end = projection.GeoToScreen(oz.get_SectorEnd());

      canvas.DrawTwoLines(p_start, p_center, p_end);
    }

    break;
  }

  case ObservationZonePoint::CYLINDER: {
    const CylinderZone &oz = (const CylinderZone &)_oz;

    if (layer != LAYER_INACTIVE) {
      RasterPoint p_center = projection.GeoToScreen(oz.get_location());
      canvas.circle(p_center.x, p_center.y,
                    projection.GeoToScreenDistance(oz.getRadius()));
    }

    break;
  }

  case ObservationZonePoint::BGA_START:
  case ObservationZonePoint::SECTOR: {
    const SectorZone &oz = (const SectorZone &)_oz;

    if (layer != LAYER_INACTIVE) {
      RasterPoint p_center = projection.GeoToScreen(oz.get_location());

      canvas.DrawSegment(p_center.x, p_center.y,
                         projection.GeoToScreenDistance(oz.getRadius()),
                         oz.getStartRadial() - projection.GetScreenAngle(),
                         oz.getEndRadial() - projection.GetScreenAngle());

      RasterPoint p_start = projection.GeoToScreen(oz.get_SectorStart());
      RasterPoint p_end = projection.GeoToScreen(oz.get_SectorEnd());
      canvas.DrawTwoLines(p_start, p_center, p_end);
    }

    break;
  }

  case ObservationZonePoint::KEYHOLE:
  case ObservationZonePoint::BGAFIXEDCOURSE:
  case ObservationZonePoint::BGAENHANCEDOPTION: {
    const SectorZone &oz = (const SectorZone &)_oz;
    RasterPoint p_center = projection.GeoToScreen(oz.get_location());
    canvas.DrawKeyhole(p_center.x, p_center.y,
                       projection.GeoToScreenDistance(fixed(500)),
                       projection.GeoToScreenDistance(oz.getRadius()),
                       oz.getStartRadial() - projection.GetScreenAngle(),
                       oz.getEndRadial() - projection.GetScreenAngle());

    break;
  }

  case ObservationZonePoint::ANNULAR_SECTOR: {
    const AnnularSectorZone &oz = (const AnnularSectorZone &)_oz;
    RasterPoint p_center = projection.GeoToScreen(oz.get_location());
    canvas.DrawAnnulus(p_center.x, p_center.y,
                       projection.GeoToScreenDistance(oz.getInnerRadius()),
                       projection.GeoToScreenDistance(oz.getRadius()),
                       oz.getStartRadial() - projection.GetScreenAngle(),
                       oz.getEndRadial() - projection.GetScreenAngle());
  }

  }

  Finish(canvas, layer);
}
Example #7
0
void
HorizonRenderer::Draw(Canvas &canvas, const PixelRect &rc,
                      const HorizonLook &look,
                      const AttitudeState &attitude)
{
  /*
  This feature of having a backup artificial horizon based on inferred
  orientation from GPS and vario data is useful, and reasonably well
  tested, but has the issue of potentially invalidating use of XCSoar in
  FAI contests due to rule ref Annex A to Section 3 (2010 Edition) 4.1.2
  "No instruments permitting pilots to fly without visual reference to
  the ground may be carried on board, even if made unserviceable."  The
  quality of XCSoar's pseudo-AH is arguably good enough that this
  violates the rule.  We need to seek clarification as to whether this
  is the case or not.
  */

  RasterPoint center;
  center.y = (rc.top + rc.bottom) / 2;
  center.x = (rc.left + rc.right) / 2;
  const int radius = min(rc.right - rc.left, rc.bottom - rc.top) / 2 -
                     Layout::Scale(1);

#define fixed_div fixed(1.0 / 50.0)
#define fixed_89 fixed_int_constant(89)

  fixed bank_degrees = attitude.bank_angle_available ?
                       attitude.bank_angle.Degrees() : fixed_zero;

  fixed pitch_degrees = attitude.pitch_angle_available ?
                        attitude.pitch_angle.Degrees() : fixed_zero;

  fixed phi = max(-fixed_89, min(fixed_89, bank_degrees));
  fixed alpha = fixed_rad_to_deg * acos(max(-fixed_one,min(fixed_one,
                  pitch_degrees * fixed_div)));
  fixed sphi = fixed_180 - phi;
  Angle alpha1 = Angle::Degrees(sphi - alpha);
  Angle alpha2 = Angle::Degrees(sphi + alpha);

  // draw sky part
  canvas.Select(look.sky_pen);
  canvas.Select(look.sky_brush);
  canvas.DrawSegment(center.x, center.y, radius, alpha2, alpha1, true);

  // draw ground part
  canvas.Select(look.terrain_pen);
  canvas.Select(look.terrain_brush);
  canvas.DrawSegment(center.x, center.y, radius, alpha1, alpha2, true);

  // draw aircraft symbol
  canvas.Select(look.aircraft_pen);
  canvas.DrawLine(center.x + radius / 2, center.y, center.x - radius / 2, center.y);
  canvas.DrawLine(center.x, center.y - radius / 4, center.x, center.y);

  // draw 45 degree dash marks
  const UPixelScalar rr2p = uround(radius * fixed_sqrt_half) + Layout::Scale(1);
  const UPixelScalar rr2n = rr2p - Layout::Scale(2);
  canvas.DrawLine(center.x + rr2p, center.y - rr2p,
              center.x + rr2n, center.y - rr2n);
  canvas.DrawLine(center.x - rr2p, center.y - rr2p,
              center.x - rr2n, center.y - rr2n);
}
Example #8
0
  void paint(Canvas &canvas) {
    canvas.SelectHollowBrush();
    canvas.SelectBlackPen();

    Brush red_brush(COLOR_RED);

    const PixelRect rc = get_client_rect();
    const UPixelScalar width = rc.right - rc.left;
    const UPixelScalar height = rc.bottom - rc.top;
    const UPixelScalar hmiddle = (rc.left + rc.right) / 2;
    const UPixelScalar vmiddle = (rc.top + rc.bottom) / 2;

    RasterPoint p1[3] = {
      { -100, PixelScalar(vmiddle) },
      { PixelScalar((width * 2) / 3), -100 },
      { PixelScalar(hmiddle), PixelScalar(height * 2) },
    };

    RasterPoint p2[3] = {
      { -2000, PixelScalar(vmiddle) },
      { PixelScalar(width * 10), -3000 },
      { PixelScalar(width * 5), 3000 },
    };

    const TCHAR *label;
    switch (page) {
    case 0:
      canvas.DrawSegment(hmiddle, vmiddle,
                     min(width, height) / 3,
                     Angle::Degrees(fixed_zero), Angle::Degrees(fixed(90)),
                     false);
      label = _T("segment 0-90 horizon=false");
      break;

    case 1:
      canvas.DrawSegment(hmiddle, vmiddle,
                     min(width, height) / 3,
                     Angle::Degrees(fixed(45)), Angle::Degrees(fixed_180),
                     true);
      label = _T("segment 45-180 horizon=true");
      break;

    case 2:
      canvas.circle(hmiddle, vmiddle,
                    min(width, height) / 3);
      label = _T("circle");
      break;

    case 3:
    case 4:
      PixelRect rc;
      rc.left = hmiddle - 50;
      rc.top = vmiddle - 20;
      rc.right = hmiddle + 50;
      rc.bottom = vmiddle + 20;
      canvas.DrawButton(rc, page == 4);
      label = page == 4
        ? _T("button down=true") : _T("button down=false");
      break;

    case 5:
      canvas.Select(red_brush);
      canvas.polygon(p1, 3);
      label = _T("big polygon");
      break;

    case 6:
      canvas.Select(red_brush);
      canvas.polygon(p2, 3);
      label = _T("huge polygon");
      break;
    }

    canvas.SetTextColor(Color(0, 0, 128));
    canvas.text(5, 5, label);
#ifndef ENABLE_OPENGL
    canvas.text(5, 25,
                buffered ? _T("buffered") : _T("not buffered"));
#endif
  }