当前位置: 首页>>代码示例>>C++>>正文


C++ Canvas::DrawSegment方法代码示例

本文整理汇总了C++中Canvas::DrawSegment方法的典型用法代码示例。如果您正苦于以下问题:C++ Canvas::DrawSegment方法的具体用法?C++ Canvas::DrawSegment怎么用?C++ Canvas::DrawSegment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Canvas的用法示例。


在下文中一共展示了Canvas::DrawSegment方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Clamp

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);
}
开发者ID:kwtskran,项目名称:XCSoar,代码行数:60,代码来源:HorizonRenderer.cpp

示例2: hpHorizonSky

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);
}
开发者ID:,项目名称:,代码行数:60,代码来源:

示例3: pen_f

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);
  }
}
开发者ID:CnZoom,项目名称:XcSoarPull,代码行数:57,代码来源:TaskProgressRenderer.cpp

示例4: app


//.........这里部分代码省略.........
    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();
    }
  }
开发者ID:Exadios,项目名称:YCSoar,代码行数:101,代码来源:ExperimentalScreen.cpp

示例5: paint

  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
  }
开发者ID:Tjeerdm,项目名称:XCSoarDktjm,代码行数:82,代码来源:RunCanvas.cpp

示例6: Prepare

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);
}
开发者ID:mobotics,项目名称:XCSoar,代码行数:90,代码来源:OZRenderer.cpp

示例7: min

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);
}
开发者ID:damianob,项目名称:xcsoar,代码行数:62,代码来源:HorizonRenderer.cpp

示例8: paint

  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
  }
开发者ID:davidswelt,项目名称:XCSoar,代码行数:80,代码来源:RunCanvas.cpp


注:本文中的Canvas::DrawSegment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。