//------------------------------------------------------------------------------ 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 AirspaceLabelRenderer::DrawInternal(Canvas &canvas, #ifndef ENABLE_OPENGL Canvas &stencil_canvas, #endif const WindowProjection &projection, const AirspaceRendererSettings &settings, const AirspaceWarningCopy &awc, const AirspacePredicate &visible, const AirspaceWarningConfig &config) { AirspaceLabelList labels; for (const auto &i : airspaces->QueryWithinRange(projection.GetGeoScreenCenter(), projection.GetScreenDistanceMeters())) { const AbstractAirspace &airspace = i.GetAirspace(); if (visible(airspace)) labels.Add(airspace.GetCenter(), airspace.GetType(), airspace.GetBase(), airspace.GetTop()); } if(settings.label_selection == AirspaceRendererSettings::LabelSelection::ALL) { labels.Sort(config); // default paint settings canvas.SetTextColor(look.label_text_color); canvas.Select(*look.name_font); canvas.Select(look.label_pen); canvas.Select(look.label_brush); canvas.SetBackgroundTransparent(); // draw TCHAR topText[NAME_SIZE + 1]; TCHAR baseText[NAME_SIZE + 1]; for (const auto &label : labels) { // size of text AirspaceFormatter::FormatAltitudeShort(topText, label.top, false); PixelSize topSize = canvas.CalcTextSize(topText); AirspaceFormatter::FormatAltitudeShort(baseText, label.base, false); PixelSize baseSize = canvas.CalcTextSize(baseText); int labelWidth = std::max(topSize.cx, baseSize.cx) + 2 * Layout::GetTextPadding(); int labelHeight = topSize.cy + baseSize.cy; // box const auto pos = projection.GeoToScreen(label.pos); PixelRect rect; rect.left = pos.x - labelWidth / 2; rect.top = pos.y; rect.right = rect.left + labelWidth; rect.bottom = rect.top + labelHeight; canvas.Rectangle(rect.left, rect.top, rect.right, rect.bottom); #ifdef USE_GDI canvas.DrawLine(rect.left + Layout::GetTextPadding(), rect.top + labelHeight / 2, rect.right - Layout::GetTextPadding(), rect.top + labelHeight / 2); #else canvas.DrawHLine(rect.left + Layout::GetTextPadding(), rect.right - Layout::GetTextPadding(), rect.top + labelHeight / 2, look.label_pen.GetColor()); #endif // top text int x = rect.right - Layout::GetTextPadding() - topSize.cx; int y = rect.top; canvas.DrawText(x, y, topText); // base text x = rect.right - Layout::GetTextPadding() - baseSize.cx; y = rect.bottom - baseSize.cy; canvas.DrawText(x, y, baseText); } } }