void ThermalAssistantWindow::PaintRadarBackground(Canvas &canvas, fixed max_lift) const { canvas.Clear(look.background_color); canvas.SelectHollowBrush(); canvas.Select(look.inner_circle_pen); canvas.DrawCircle(mid.x, mid.y, radius / 2); canvas.Select(look.outer_circle_pen); canvas.DrawCircle(mid.x, mid.y, radius); if (small) return; canvas.SetTextColor(COLOR_BLACK); canvas.Select(look.circle_label_font); canvas.SetBackgroundColor(look.background_color); canvas.SetBackgroundOpaque(); TCHAR lift_string[10]; FormatUserVerticalSpeed(max_lift, lift_string, ARRAY_SIZE(lift_string)); PixelSize s = canvas.CalcTextSize(lift_string); canvas.text(mid.x - s.cx / 2, mid.y + radius - s.cy * 0.75, lift_string); FormatUserVerticalSpeed(fixed_zero, lift_string, ARRAY_SIZE(lift_string)); s = canvas.CalcTextSize(lift_string); canvas.text(mid.x - s.cx / 2, mid.y + radius / 2 - s.cy * 0.75, lift_string); canvas.SetBackgroundTransparent(); }
void TitleBar::MinimizeButton::OnDraw(const Context &context) { Canvas *canvas = context.canvas(); int scale = context.surface()->GetScale(); const RectF &rect = GetBounds(); canvas->Scale(scale, scale); Paint paint; paint.SetAntiAlias(true); if (IsHovered()) { if (IsPressed()) { paint.SetColor(Theme::GetData().title_bar.highlight.foreground.colors[0]); paint.SetStyle(Paint::Style::kStyleFill); canvas->DrawCircle(rect.center_x(), rect.center_y(), 7.f, paint); paint.Reset(); paint.SetAntiAlias(true); } paint.SetStyle(Paint::Style::kStyleStroke); paint.SetColor(Theme::GetData().title_bar.active.foreground.colors[0]); paint.SetStrokeWidth(1.f); canvas->DrawCircle(rect.center_x(), rect.center_y(), 6.5f, paint); } paint.SetColor(Theme::GetData().title_bar.active.foreground.colors[0]); paint.SetStrokeWidth(1.5f); canvas->DrawLine(rect.center_x() - 4.f, rect.center_y(), rect.center_x() + 4.f, rect.center_y(), paint); }
virtual void OnPaint(Canvas &canvas) override { canvas.ClearWhite(); const GeoPoint a(Angle::Degrees(7.70722), Angle::Degrees(51.052)); const GeoPoint b(Angle::Degrees(11.5228), Angle::Degrees(50.3972)); WindowProjection projection; projection.SetScreenOrigin(canvas.GetWidth() / 2, canvas.GetHeight() / 2); projection.SetGeoLocation(a.Middle(b)); projection.SetScreenSize(canvas.GetSize()); projection.SetScaleFromRadius(fixed(400000)); projection.UpdateScreenBounds(); canvas.SelectBlackPen(); canvas.SelectHollowBrush(); RasterPoint pa = projection.GeoToScreen(a); canvas.DrawCircle(pa.x, pa.y, 4); RasterPoint pb = projection.GeoToScreen(b); canvas.DrawCircle(pb.x, pb.y, 4); RenderFAISector(canvas, projection, a, b, false, settings); }
void TitleBar::CloseButton::OnDraw(const Context &context) { Canvas *canvas = context.canvas(); int scale = context.surface()->GetScale(); const RectF &rect = GetBounds(); canvas->Scale(scale, scale); Paint paint; paint.SetAntiAlias(true); base::ColorF background = 0xFFDD6666; if (IsHovered()) { if (IsPressed()) { background -= 45; } else { background += 35; } } paint.SetStyle(Paint::Style::kStyleFill); paint.SetColor(background); canvas->DrawCircle(rect.center_x(), rect.center_y(), 7.f, paint); // paint.SetColor(Theme::GetData().title_bar.active.foreground.color); paint.SetColor(0xFFDDDDDD); paint.SetStrokeWidth(1.5f); canvas->DrawLine(rect.center_x() - 3.f, rect.center_y() - 3.f, rect.center_x() + 3.f, rect.center_y() + 3.f, paint); canvas->DrawLine(rect.center_x() + 3.f, rect.center_y() - 3.f, rect.center_x() - 3.f, rect.center_y() + 3.f, paint); }
void FlarmTrafficControl::PaintID(Canvas &canvas, PixelRect rc, const FlarmTraffic &traffic) const { TCHAR buffer[20]; unsigned font_size; if (traffic.HasName()) { canvas.Select(look.call_sign_font); font_size = look.call_sign_font.GetHeight(); _tcscpy(buffer, traffic.name); } else { canvas.Select(look.info_labels_font); font_size = look.info_labels_font.GetHeight(); traffic.id.Format(buffer); } if (!WarningMode()) { // Team color dot FlarmFriends::Color team_color = FlarmFriends::GetFriendColor(traffic.id); // If no color found but target is teammate if (team_color == FlarmFriends::Color::NONE && settings.team_flarm_tracking && traffic.id == settings.team_flarm_id) // .. use green color team_color = FlarmFriends::Color::GREEN; // If team color found -> draw a colored circle in front of the name if (team_color != FlarmFriends::Color::NONE) { switch (team_color) { case FlarmFriends::Color::GREEN: canvas.Select(look.team_brush_green); break; case FlarmFriends::Color::BLUE: canvas.Select(look.team_brush_blue); break; case FlarmFriends::Color::YELLOW: canvas.Select(look.team_brush_yellow); break; case FlarmFriends::Color::MAGENTA: canvas.Select(look.team_brush_magenta); break; default: break; } canvas.SelectNullPen(); canvas.DrawCircle(rc.left + Layout::FastScale(7), rc.top + (font_size / 2), Layout::FastScale(7)); rc.left += Layout::FastScale(16); } } canvas.DrawText(rc.left, rc.top, buffer); }
void TrafficRenderer::Draw(Canvas &canvas, const TrafficLook &traffic_look, const FlarmTraffic &traffic, const Angle angle, const FlarmColor color, const RasterPoint pt) { // Create point array that will form that arrow polygon RasterPoint arrow[] = { { -4, 6 }, { 0, -8 }, { 4, 6 }, { 0, 3 }, { -4, 6 }, }; // Select brush depending on AlarmLevel switch (traffic.alarm_level) { case FlarmTraffic::AlarmType::LOW: case FlarmTraffic::AlarmType::INFO_ALERT: canvas.Select(traffic_look.warning_brush); break; case FlarmTraffic::AlarmType::IMPORTANT: case FlarmTraffic::AlarmType::URGENT: canvas.Select(traffic_look.alarm_brush); break; case FlarmTraffic::AlarmType::NONE: canvas.Select(traffic_look.safe_brush); break; } // Select black pen canvas.SelectBlackPen(); // Rotate and shift the arrow to the right position and angle PolygonRotateShift(arrow, ARRAY_SIZE(arrow), pt, angle); // Draw the arrow canvas.DrawPolygon(arrow, ARRAY_SIZE(arrow)); switch (color) { case FlarmColor::GREEN: canvas.Select(traffic_look.team_pen_green); break; case FlarmColor::BLUE: canvas.Select(traffic_look.team_pen_blue); break; case FlarmColor::YELLOW: canvas.Select(traffic_look.team_pen_yellow); break; case FlarmColor::MAGENTA: canvas.Select(traffic_look.team_pen_magenta); break; default: return; } canvas.SelectHollowBrush(); canvas.DrawCircle(pt.x, pt.y, Layout::FastScale(11)); }
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); } }
virtual void OnPaint(Canvas &canvas) override { canvas.ClearWhite(); const PixelRect rc = canvas.GetRect(); PixelPoint pt = rc.GetCenter(); canvas.SelectBlackPen(); canvas.SelectHollowBrush(); canvas.DrawCircle(pt.x, pt.y, 2); renderer.Draw(canvas, Angle::Zero(), wind, pt, rc, WindArrowStyle::ARROW_HEAD); }
static void DrawShape(Canvas &canvas, AbstractAirspace::Shape shape, const RasterPoint pt, unsigned radius, const std::vector<RasterPoint> &pts) { if (shape == AbstractAirspace::Shape::CIRCLE) canvas.DrawCircle(pt.x, pt.y, radius); else if (IsAncientHardware()) canvas.Rectangle(pt.x - radius, pt.y - radius, pt.x + radius, pt.y + radius); else canvas.DrawPolygon(&pts[0], (unsigned)pts.size()); }
void TitleBar::FullscreenButton::OnDraw(const Context &context) { Canvas *canvas = context.canvas(); int scale = context.surface()->GetScale(); const RectF &rect = GetBounds(); canvas->Scale(scale, scale); Paint paint; paint.SetAntiAlias(true); if (IsHovered()) { if (IsPressed()) { paint.SetColor(Theme::GetData().title_bar.active.foreground.colors[0]); paint.SetStyle(Paint::Style::kStyleFill); canvas->DrawCircle(rect.center_x(), rect.center_y(), 7.f, paint); paint.Reset(); paint.SetAntiAlias(true); } paint.SetStyle(Paint::Style::kStyleStroke); paint.SetColor(Theme::GetData().title_bar.active.foreground.colors[0]); paint.SetStrokeWidth(1.f); canvas->DrawCircle(rect.center_x(), rect.center_y(), 6.5f, paint); } paint.SetColor(Theme::GetData().title_bar.active.foreground.colors[0]); paint.SetStyle(Paint::Style::kStyleFill); Path path; path.MoveTo(-5.f, 0.f); path.RelativeLineTo(3.5f, -3.5f); path.RelativeLineTo(0.f, 7.f); path.Close(); canvas->Translate(rect.center_x(), rect.center_y()); canvas->Rotate(-45.f); canvas->DrawPath(path, paint); canvas->Rotate(180.f); canvas->DrawPath(path, paint); }
/** * Paints the radar circle on the given canvas * @param canvas The canvas to paint on */ void FlarmTrafficWindow::PaintRadarBackground(Canvas &canvas) const { canvas.SelectHollowBrush(); canvas.Select(look.radar_pen); canvas.SetTextColor(look.radar_color); // Paint circles canvas.DrawCircle(radar_mid.x, radar_mid.y, radius); canvas.DrawCircle(radar_mid.x, radar_mid.y, radius / 2); PaintRadarPlane(canvas); if (small) return; // Paint zoom strings canvas.Select(look.label_font); canvas.SetBackgroundOpaque(); canvas.SetBackgroundColor(look.background_color); TCHAR distance_string[10]; FormatUserDistanceSmart(distance, distance_string, ARRAY_SIZE(distance_string), fixed(1000)); PixelSize s = canvas.CalcTextSize(distance_string); canvas.DrawText(radar_mid.x - s.cx / 2, radar_mid.y + radius - s.cy * 0.75, distance_string); FormatUserDistanceSmart(distance / 2, distance_string, ARRAY_SIZE(distance_string), fixed(1000)); s = canvas.CalcTextSize(distance_string); canvas.DrawText(radar_mid.x - s.cx / 2, radar_mid.y + radius / 2 - s.cy * 0.75, distance_string); canvas.SetBackgroundTransparent(); PaintNorth(canvas); }
/** * This function is called when the Radar needs repainting. * @param canvas The canvas to paint on */ void FlarmTrafficWindow::OnPaintBuffer(Canvas &canvas) { #ifdef ENABLE_OPENGL if (small) { const ScopeAlphaBlend alpha_blend; canvas.SelectBlackPen(); canvas.Select(Brush(look.background_color.WithAlpha(0xd0))); canvas.DrawCircle(radar_mid.x, radar_mid.y, radius); } else #endif canvas.Clear(look.background_color); Paint(canvas); }
/** * This function is called when the Radar needs repainting. * @param canvas The canvas to paint on */ void FlarmTrafficWindow::OnPaint(Canvas &canvas) { #ifdef ENABLE_OPENGL if (small) { const GLBlend blend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); canvas.SelectBlackPen(); canvas.Select(Brush(look.background_color.WithAlpha(0xd0))); canvas.DrawCircle(radar_mid.x, radar_mid.y, radius); } else #endif canvas.Clear(look.background_color); Paint(canvas); }
void OnPaint(Canvas &canvas) { canvas.ClearWhite(); PixelRect rc = { 0, 0, (PixelScalar)canvas.get_width(), (PixelScalar)canvas.get_height() }; RasterPoint pt = { (PixelScalar)(rc.right / 2), (PixelScalar)(rc.bottom / 2) }; canvas.SelectBlackPen(); canvas.SelectHollowBrush(); canvas.DrawCircle(pt.x, pt.y, 2); renderer.Draw(canvas, Angle::Zero(), wind, pt, rc, false); }
/** * Paints the radar circle on the given canvas * @param canvas The canvas to paint on */ void FlarmTrafficWindow::PaintNorth(Canvas &canvas) const { DoublePoint2D p(0, -1); if (!enable_north_up) { p = fr.Rotate(p); } canvas.SetTextColor(look.background_color); canvas.Select(look.radar_pen); canvas.Select(look.radar_brush); canvas.SetBackgroundTransparent(); canvas.Select(look.label_font); PixelSize s = canvas.CalcTextSize(_T("N")); canvas.DrawCircle(radar_mid.x + iround(p.x * radius), radar_mid.y + iround(p.y * radius), s.cy * 0.65); canvas.DrawText(radar_mid.x + iround(p.x * radius) - s.cx / 2, radar_mid.y + iround(p.y * radius) - s.cy / 2, _T("N")); }
static void DrawLandableBase(Canvas &canvas, const PixelPoint &pt, bool airport, const double radius) { int iradius = iround(radius); if (airport) canvas.DrawCircle(pt.x, pt.y, iradius); else { BulkPixelPoint diamond[4]; diamond[0].x = pt.x + 0; diamond[0].y = pt.y - iradius; diamond[1].x = pt.x + iradius; diamond[1].y = pt.y + 0; diamond[2].x = pt.x + 0; diamond[2].y = pt.y + iradius; diamond[3].x = pt.x - iradius; diamond[3].y = pt.y - 0; canvas.DrawTriangleFan(diamond, ARRAY_SIZE(diamond)); } }
/** * Paints the radar circle on the given canvas * @param canvas The canvas to paint on */ void FlarmTrafficWindow::PaintNorth(Canvas &canvas) const { fixed x = fixed(0), y = fixed(-1); if (!enable_north_up) { FastRotation::Pair p = fr.Rotate(x, y); x = p.first; y = p.second; } canvas.SetTextColor(look.background_color); canvas.Select(look.radar_pen); canvas.Select(look.radar_brush); canvas.SetBackgroundTransparent(); canvas.Select(look.label_font); PixelSize s = canvas.CalcTextSize(_T("N")); canvas.DrawCircle(radar_mid.x + iround(x * radius), radar_mid.y + iround(y * radius), s.cy * 0.65); canvas.DrawText(radar_mid.x + iround(x * radius) - s.cx / 2, radar_mid.y + iround(y * radius) - s.cy / 2, _T("N")); }
/** * Paints the basic info for the selected target on the given canvas * @param canvas The canvas to paint on */ void FlarmTrafficControl2::PaintTrafficInfo(Canvas &canvas) const { // Don't paint numbers if no plane selected if (selection == -1 && !WarningMode()) return; // Shortcut to the selected traffic FlarmTraffic traffic = data.list[WarningMode() ? warning : selection]; assert(traffic.IsDefined()); // Temporary string TCHAR tmp[20]; // Temporary string size PixelSize sz; PixelRect rc; rc.left = padding; rc.top = padding; rc.right = canvas.get_width() - padding; rc.bottom = canvas.get_height() - padding; // Set the text color and background switch (traffic.alarm_level) { case FlarmTraffic::AlarmType::LOW: case FlarmTraffic::AlarmType::INFO_ALERT: canvas.SetTextColor(look.warning_color); break; case FlarmTraffic::AlarmType::IMPORTANT: case FlarmTraffic::AlarmType::URGENT: canvas.SetTextColor(look.alarm_color); break; case FlarmTraffic::AlarmType::NONE: canvas.SetTextColor(look.default_color); break; } canvas.SetBackgroundTransparent(); // Climb Rate if (!WarningMode() && traffic.climb_rate_avg30s_available) { FormatUserVerticalSpeed(traffic.climb_rate_avg30s, tmp, 20); canvas.Select(look.info_values_font); sz = canvas.CalcTextSize(tmp); canvas.text(rc.right - sz.cx, rc.top + look.info_labels_font.GetHeight(), tmp); canvas.Select(look.info_labels_font); sz = canvas.CalcTextSize(_("Vario")); canvas.text(rc.right - sz.cx, rc.top, _("Vario")); } // Distance FormatUserDistanceSmart(traffic.distance, tmp, 20, fixed(1000)); canvas.Select(look.info_values_font); sz = canvas.CalcTextSize(tmp); canvas.text(rc.left, rc.bottom - sz.cy, tmp); canvas.Select(look.info_labels_font); canvas.text(rc.left, rc.bottom - look.info_values_font.GetHeight() - look.info_labels_font.GetHeight(), _("Distance")); // Relative Height FormatRelativeUserAltitude(traffic.relative_altitude, tmp, 20); canvas.Select(look.info_values_font); sz = canvas.CalcTextSize(tmp); canvas.text(rc.right - sz.cx, rc.bottom - sz.cy, tmp); canvas.Select(look.info_labels_font); sz = canvas.CalcTextSize(_("Rel. Alt.")); canvas.text(rc.right - sz.cx, rc.bottom - look.info_values_font.GetHeight() - look.info_labels_font.GetHeight(), _("Rel. Alt.")); // ID / Name unsigned font_size; if (traffic.HasName()) { canvas.Select(look.call_sign_font); font_size = look.call_sign_font.GetHeight(); if (!traffic.HasAlarm()) canvas.SetTextColor(look.selection_color); _tcscpy(tmp, traffic.name); } else { font_size = look.info_labels_font.GetHeight(); traffic.id.Format(tmp); } if (!WarningMode()) { // Team color dot FlarmFriends::Color team_color = FlarmFriends::GetFriendColor(traffic.id); // If no color found but target is teammate if (team_color == FlarmFriends::Color::NONE && settings.team_flarm_tracking && traffic.id == settings.team_flarm_id) // .. use yellow color team_color = FlarmFriends::Color::GREEN; // If team color found -> draw a colored circle around the target if (team_color != FlarmFriends::Color::NONE) { switch (team_color) { case FlarmFriends::Color::GREEN: canvas.Select(look.team_brush_green); break; case FlarmFriends::Color::BLUE: canvas.Select(look.team_brush_blue); break; case FlarmFriends::Color::YELLOW: canvas.Select(look.team_brush_green); break; case FlarmFriends::Color::MAGENTA: canvas.Select(look.team_brush_magenta); break; default: break; } canvas.SelectNullPen(); canvas.DrawCircle(rc.left + Layout::FastScale(7), rc.top + (font_size / 2), Layout::FastScale(7)); rc.left += Layout::FastScale(16); } } canvas.text(rc.left, rc.top, tmp); }
void TrailRenderer::Draw(Canvas &canvas, const TraceComputer &trace_computer, const WindowProjection &projection, unsigned min_time, bool enable_traildrift, const RasterPoint pos, const NMEAInfo &basic, const DerivedInfo &calculated, const TrailSettings &settings) { if (settings.length == TrailSettings::Length::OFF) return; if (!LoadTrace(trace_computer, min_time, projection)) return; if (!calculated.wind_available) enable_traildrift = false; GeoPoint traildrift; if (enable_traildrift) { GeoPoint tp1 = FindLatitudeLongitude(basic.location, calculated.wind.bearing, calculated.wind.norm); traildrift = basic.location - tp1; } fixed value_max, value_min; GetMinMax(value_min, value_max, settings.type, trace); bool scaled_trail = settings.scaling_enabled && projection.GetMapScale() <= fixed_int_constant(6000); const GeoBounds bounds = projection.GetScreenBounds().Scale(fixed_four); RasterPoint last_point; bool last_valid = false; for (auto it = trace.begin(), end = trace.end(); it != end; ++it) { const GeoPoint gp = enable_traildrift ? it->GetLocation().Parametric(traildrift, it->CalculateDrift(basic.time)) : it->GetLocation(); if (!bounds.IsInside(gp)) { /* the point is outside of the MapWindow; don't paint it */ last_valid = false; continue; } RasterPoint pt = projection.GeoToScreen(gp); if (last_valid) { if (settings.type == TrailSettings::Type::ALTITUDE) { unsigned index((it->GetAltitude() - value_min) / (value_max - value_min) * (TrailLook::NUMSNAILCOLORS - 1)); index = max(0u, min(TrailLook::NUMSNAILCOLORS - 1, index)); canvas.Select(look.trail_pens[index]); canvas.DrawLinePiece(last_point, pt); } else { const fixed colour_vario = negative(it->GetVario()) ? - it->GetVario() / value_min : it->GetVario() / value_max ; unsigned color_index = GetSnailColorIndex(colour_vario); if (negative(it->GetVario()) && (settings.type == TrailSettings::Type::VARIO_1_DOTS || settings.type == TrailSettings::Type::VARIO_2_DOTS)) { canvas.SelectNullPen(); canvas.Select(look.trail_brushes[color_index]); canvas.DrawCircle((pt.x + last_point.x) / 2, (pt.y + last_point.y) / 2, look.trail_widths[color_index]); } else { if (!scaled_trail) canvas.Select(look.trail_pens[color_index]); else canvas.Select(look.scaled_trail_pens[color_index]); canvas.DrawLinePiece(last_point, pt); } } } last_point = pt; last_valid = true; } if (last_valid) canvas.DrawLine(last_point, pos); }
//------------------------------------------------------------------------------ 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(); } }
void ThermalAssistantWindow::DrawCircle(Canvas &canvas) { canvas.DrawCircle(renderer.GetMiddle().x, renderer.GetMiddle().y, renderer.GetRadius()); }
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.GetReference()); 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.GetSectorStart()); RasterPoint p_end = projection.GeoToScreen(oz.GetSectorEnd()); 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.GetReference()); canvas.DrawCircle(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.GetReference()); 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.GetSectorStart()); RasterPoint p_end = projection.GeoToScreen(oz.GetSectorEnd()); 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.GetReference()); 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.GetReference()); 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); }
void TrailRenderer::Draw(Canvas &canvas, const TraceComputer &trace_computer, const WindowProjection &projection, unsigned min_time, bool enable_traildrift, const RasterPoint pos, const NMEAInfo &basic, const DerivedInfo &calculated, const TrailSettings &settings) { if (settings.length == TrailSettings::Length::OFF) return; if (!LoadTrace(trace_computer, min_time, projection)) return; if (!calculated.wind_available) enable_traildrift = false; GeoPoint traildrift; if (enable_traildrift) { GeoPoint tp1 = FindLatitudeLongitude(basic.location, calculated.wind.bearing, calculated.wind.norm); traildrift = basic.location - tp1; } auto minmax = GetMinMax(settings.type, trace); auto value_min = minmax.first; auto value_max = minmax.second; bool scaled_trail = settings.scaling_enabled && projection.GetMapScale() <= 6000; const GeoBounds bounds = projection.GetScreenBounds().Scale(4); RasterPoint last_point = RasterPoint(0, 0); bool last_valid = false; for (auto it = trace.begin(), end = trace.end(); it != end; ++it) { const GeoPoint gp = enable_traildrift ? it->GetLocation().Parametric(traildrift, it->CalculateDrift(basic.time)) : it->GetLocation(); if (!bounds.IsInside(gp)) { /* the point is outside of the MapWindow; don't paint it */ last_valid = false; continue; } RasterPoint pt = projection.GeoToScreen(gp); if (last_valid) { if (settings.type == TrailSettings::Type::ALTITUDE) { unsigned index = GetAltitudeColorIndex(it->GetAltitude(), value_min, value_max); canvas.Select(look.trail_pens[index]); canvas.DrawLinePiece(last_point, pt); } else { unsigned color_index = GetSnailColorIndex(it->GetVario(), value_min, value_max); if (it->GetVario() < 0 && (settings.type == TrailSettings::Type::VARIO_1_DOTS || settings.type == TrailSettings::Type::VARIO_2_DOTS || settings.type == TrailSettings::Type::VARIO_DOTS_AND_LINES)) { canvas.SelectNullPen(); canvas.Select(look.trail_brushes[color_index]); canvas.DrawCircle((pt.x + last_point.x) / 2, (pt.y + last_point.y) / 2, look.trail_widths[color_index]); } else { // positive vario case if (settings.type == TrailSettings::Type::VARIO_DOTS_AND_LINES) { canvas.Select(look.trail_brushes[color_index]); canvas.Select(look.trail_pens[color_index]); //fixed-width pen canvas.DrawCircle((pt.x + last_point.x) / 2, (pt.y + last_point.y) / 2, look.trail_widths[color_index]); } else if (scaled_trail) // width scaled to vario canvas.Select(look.scaled_trail_pens[color_index]); else // fixed-width pen canvas.Select(look.trail_pens[color_index]); canvas.DrawLinePiece(last_point, pt); } } } last_point = pt; last_valid = true; } if (last_valid) canvas.DrawLine(last_point, pos); }
/** * Paints the traffic symbols on the given canvas * @param canvas The canvas to paint on */ void FlarmTrafficWindow::PaintRadarTarget(Canvas &canvas, const FlarmTraffic &traffic, unsigned i) { // Save relative East/North fixed x = traffic.relative_east; fixed y = -traffic.relative_north; // Calculate the distance in pixels fixed scale = RangeScale(traffic.distance); // Don't display distracting, far away targets in WarningMode if (WarningMode() && !traffic.HasAlarm() && scale == fixed(radius)) return; // x and y are not between 0 and 1 (distance will be handled via scale) if (!traffic.distance.IsZero()) { x /= traffic.distance; y /= traffic.distance; } else { x = fixed(0); y = fixed(0); } if (!enable_north_up) { // Rotate x and y to have a track up display FastRotation::Pair p = fr.Rotate(x, y); x = fixed(p.first); y = fixed(p.second); } // Calculate screen coordinates sc[i].x = radar_mid.x + iround(x * scale); sc[i].y = radar_mid.y + iround(y * scale); const Color *text_color; const Pen *target_pen, *circle_pen; const Brush *target_brush, *arrow_brush; bool hollow_brush = false; unsigned circles = 0; // Set the arrow color depending on alarm level switch (traffic.alarm_level) { case FlarmTraffic::AlarmType::LOW: case FlarmTraffic::AlarmType::INFO_ALERT: text_color = &look.default_color; target_pen = circle_pen = &look.warning_pen; target_brush = &look.warning_brush; arrow_brush = &look.default_brush; circles = 1; break; case FlarmTraffic::AlarmType::IMPORTANT: case FlarmTraffic::AlarmType::URGENT: text_color = &look.default_color; target_pen = circle_pen = &look.alarm_pen; target_brush = &look.alarm_brush; arrow_brush = &look.default_brush; circles = 2; break; case FlarmTraffic::AlarmType::NONE: if (WarningMode()) { text_color = &look.passive_color; target_pen = &look.passive_pen; arrow_brush = &look.passive_brush; hollow_brush = true; } else { // Search for team color const FlarmColor team_color = FlarmFriends::GetFriendColor(traffic.id); // If team color found -> draw a colored circle around the target if (team_color != FlarmColor::NONE) { switch (team_color) { case FlarmColor::GREEN: circle_pen = &look.team_pen_green; break; case FlarmColor::BLUE: circle_pen = &look.team_pen_blue; break; case FlarmColor::YELLOW: circle_pen = &look.team_pen_yellow; break; case FlarmColor::MAGENTA: circle_pen = &look.team_pen_magenta; break; default: break; } circles = 1; } if (!small && static_cast<unsigned> (selection) == i) { text_color = &look.selection_color; target_brush = arrow_brush = &look.selection_brush; target_pen = &look.selection_pen; } else { hollow_brush = true; if (traffic.IsPassive()) { text_color = &look.passive_color; target_pen = &look.passive_pen; arrow_brush = &look.passive_brush; } else { text_color = &look.default_color; target_pen = &look.default_pen; arrow_brush = &look.default_brush; } } } break; } if (circles > 0) { canvas.SelectHollowBrush(); canvas.Select(*circle_pen); canvas.DrawCircle(sc[i].x, sc[i].y, Layout::FastScale(small ? 8 : 16)); if (circles == 2) canvas.DrawCircle(sc[i].x, sc[i].y, Layout::FastScale(small ? 10 : 19)); } // Create an arrow polygon RasterPoint Arrow[5]; if (small) { Arrow[0].x = -3; Arrow[0].y = 4; Arrow[1].x = 0; Arrow[1].y = -5; Arrow[2].x = 3; Arrow[2].y = 4; Arrow[3].x = 0; Arrow[3].y = 2; Arrow[4].x = -3; Arrow[4].y = 4; } else { Arrow[0].x = -6; Arrow[0].y = 8; Arrow[1].x = 0; Arrow[1].y = -10; Arrow[2].x = 6; Arrow[2].y = 8; Arrow[3].x = 0; Arrow[3].y = 5; Arrow[4].x = -6; Arrow[4].y = 8; } // Rotate and shift the arrow PolygonRotateShift(Arrow, 5, sc[i].x, sc[i].y, traffic.track - (enable_north_up ? Angle::Zero() : heading)); // Select pen and brush canvas.Select(*target_pen); if (hollow_brush) canvas.SelectHollowBrush(); else canvas.Select(*target_brush); // Draw the polygon canvas.DrawPolygon(Arrow, 5); if (small) { if (!WarningMode() || traffic.HasAlarm()) PaintTargetInfoSmall(canvas, traffic, i, *text_color, *arrow_brush); return; } // if warning exists -> don't draw vertical speeds if (WarningMode()) return; // if vertical speed to small or negative -> skip this one if (side_display_type == SIDE_INFO_VARIO && (!traffic.climb_rate_avg30s_available || traffic.climb_rate_avg30s < fixed(0.5) || traffic.IsPowered())) return; // Select font canvas.SetBackgroundTransparent(); canvas.Select(look.side_info_font); // Format string TCHAR tmp[10]; if (side_display_type == SIDE_INFO_VARIO) FormatUserVerticalSpeed(traffic.climb_rate_avg30s, tmp, false); else FormatRelativeUserAltitude(traffic.relative_altitude, tmp, true); PixelSize sz = canvas.CalcTextSize(tmp); // Draw vertical speed shadow canvas.SetTextColor(COLOR_WHITE); canvas.DrawText(sc[i].x + Layout::FastScale(11) + 1, sc[i].y - sz.cy / 2 + 1, tmp); canvas.DrawText(sc[i].x + Layout::FastScale(11) - 1, sc[i].y - sz.cy / 2 - 1, tmp); // Select color canvas.SetTextColor(*text_color); // Draw vertical speed canvas.DrawText(sc[i].x + Layout::FastScale(11), sc[i].y - sz.cy / 2, tmp); }
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 }