]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/BaseDiagram.cxx
Launcher: Maintain aircraft selection better
[flightgear.git] / src / GUI / BaseDiagram.cxx
index 8a1c8e163cf580a443430d71ae1d47a6bdb65109..fa593f8b7cdcc5353bdfea0d233173b5914ece1a 100644 (file)
@@ -30,6 +30,7 @@
 #include <Navaids/navrecord.hxx>
 #include <Navaids/positioned.hxx>
 #include <Airports/airport.hxx>
+#include <Navaids/PolyLine.hxx>
 
 #include "QtLauncher_fwd.hxx"
 
@@ -37,6 +38,8 @@
 const float rec  = 6378137;          // earth radius, equator (?)
 const float rpol = 6356752.314f;      // earth radius, polar   (?)
 
+const double MINIMUM_SCALE = 0.002;
+
 //Returns Earth radius at a given latitude (Ellipsoide equation with two equal axis)
 static float earth_radius_lat( float lat )
 {
@@ -112,6 +115,8 @@ void BaseDiagram::paintEvent(QPaintEvent* pe)
     QTransform t(transform());
     p.setTransform(t);
 
+    paintPolygonData(&p);
+
     paintNavaids(&p);
 
     paintContents(&p);
@@ -132,6 +137,81 @@ void BaseDiagram::paintAirplaneIcon(QPainter* painter, const SGGeod& geod, int h
     painter->drawPixmap(airplaneIconRect, pix);
 }
 
+void BaseDiagram::paintPolygonData(QPainter* painter)
+{
+    QTransform xf = painter->transform();
+    QTransform invT = xf.inverted();
+
+    SGGeod topLeft = unproject(invT.map(rect().topLeft()), m_projectionCenter);
+    SGGeod viewCenter = unproject(invT.map(rect().center()), m_projectionCenter);
+    SGGeod bottomRight = unproject(invT.map(rect().bottomRight()), m_projectionCenter);
+
+    double drawRangeNm = std::max(SGGeodesy::distanceNm(viewCenter, topLeft),
+                                  SGGeodesy::distanceNm(viewCenter, bottomRight));
+
+    flightgear::PolyLineList lines(flightgear::PolyLine::linesNearPos(viewCenter, drawRangeNm,
+                                                                      flightgear::PolyLine::COASTLINE));
+
+    QPen waterPen(QColor(64, 64, 255), 1);
+    waterPen.setCosmetic(true);
+    painter->setPen(waterPen);
+    flightgear::PolyLineList::const_iterator it;
+    for (it=lines.begin(); it != lines.end(); ++it) {
+        paintGeodVec(painter, (*it)->points());
+    }
+
+    lines = flightgear::PolyLine::linesNearPos(viewCenter, drawRangeNm,
+                                              flightgear::PolyLine::URBAN);
+    for (it=lines.begin(); it != lines.end(); ++it) {
+        fillClosedGeodVec(painter, QColor(192, 192, 96), (*it)->points());
+    }
+
+    lines = flightgear::PolyLine::linesNearPos(viewCenter, drawRangeNm,
+                                              flightgear::PolyLine::RIVER);
+
+    painter->setPen(waterPen);
+    for (it=lines.begin(); it != lines.end(); ++it) {
+        paintGeodVec(painter, (*it)->points());
+    }
+
+
+    lines = flightgear::PolyLine::linesNearPos(viewCenter, drawRangeNm,
+                                              flightgear::PolyLine::LAKE);
+
+    for (it=lines.begin(); it != lines.end(); ++it) {
+        fillClosedGeodVec(painter, QColor(128, 128, 255),
+                          (*it)->points());
+    }
+
+
+}
+
+void BaseDiagram::paintGeodVec(QPainter* painter, const flightgear::SGGeodVec& vec)
+{
+    QVector<QPointF> projected;
+    projected.reserve(vec.size());
+    flightgear::SGGeodVec::const_iterator it;
+    for (it=vec.begin(); it != vec.end(); ++it) {
+        projected.append(project(*it));
+    }
+
+    painter->drawPolyline(projected.data(), projected.size());
+}
+
+void BaseDiagram::fillClosedGeodVec(QPainter* painter, const QColor& color, const flightgear::SGGeodVec& vec)
+{
+    QVector<QPointF> projected;
+    projected.reserve(vec.size());
+    flightgear::SGGeodVec::const_iterator it;
+    for (it=vec.begin(); it != vec.end(); ++it) {
+        projected.append(project(*it));
+    }
+
+    painter->setPen(Qt::NoPen);
+    painter->setBrush(color);
+    painter->drawPolygon(projected.data(), projected.size());
+}
+
 class MapFilter : public FGPositioned::TypeFilter
 {
 public:
@@ -469,12 +549,16 @@ void BaseDiagram::wheelEvent(QWheelEvent *we)
     m_wheelAngleDeltaAccumulator += delta;
     if (m_wheelAngleDeltaAccumulator > 120) {
         m_wheelAngleDeltaAccumulator = 0;
-        m_scale *= 2.0;
+
+        m_scale *= 1.5;
+
     } else if (m_wheelAngleDeltaAccumulator < -120) {
         m_wheelAngleDeltaAccumulator = 0;
-        m_scale *= 0.5;
+
+        m_scale *= 0.75;
     }
 
+    SG_CLAMP_RANGE(m_scale, MINIMUM_SCALE, 1.0);
     update();
 }