From 317498fe4a0a5f2764db9c47a7e820c3632d4dd7 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 14 Nov 2015 16:46:28 +0000 Subject: [PATCH] Move airplane drawing into the base class. - ground work for showing airplane on airport diagram --- src/GUI/AirportDiagram.cxx | 4 ++++ src/GUI/BaseDiagram.cxx | 15 +++++++++++++++ src/GUI/BaseDiagram.hxx | 2 ++ src/GUI/NavaidDiagram.cxx | 16 +++------------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/GUI/AirportDiagram.cxx b/src/GUI/AirportDiagram.cxx index 449957dfd..2fd2ce7e9 100644 --- a/src/GUI/AirportDiagram.cxx +++ b/src/GUI/AirportDiagram.cxx @@ -267,6 +267,10 @@ void AirportDiagram::paintContents(QPainter* p) p->setPen(pen); p->drawLine(pt, pt2); } + + + // aircraft pos and heading... + // paintAirplaneIcon(painter, ); } void AirportDiagram::drawILS(QPainter* painter, FGRunwayRef runway) const diff --git a/src/GUI/BaseDiagram.cxx b/src/GUI/BaseDiagram.cxx index bced50f42..4c301a20e 100644 --- a/src/GUI/BaseDiagram.cxx +++ b/src/GUI/BaseDiagram.cxx @@ -115,6 +115,21 @@ void BaseDiagram::paintEvent(QPaintEvent* pe) paintContents(&p); } +void BaseDiagram::paintAirplaneIcon(QPainter* painter, const SGGeod& geod, int headingDeg) +{ + QPointF pos = project(geod); + QPixmap pix(":/airplane-icon"); + pos = painter->transform().map(pos); + painter->resetTransform(); + painter->translate(pos.x(), pos.y()); + painter->rotate(headingDeg); + + painter->setRenderHint(QPainter::SmoothPixmapTransform, true); + QRect airplaneIconRect = pix.rect(); + airplaneIconRect.moveCenter(QPoint(0,0)); + painter->drawPixmap(airplaneIconRect, pix); +} + class MapFilter : public FGPositioned::TypeFilter { public: diff --git a/src/GUI/BaseDiagram.hxx b/src/GUI/BaseDiagram.hxx index 9c82d21ab..5bbd4bf83 100644 --- a/src/GUI/BaseDiagram.hxx +++ b/src/GUI/BaseDiagram.hxx @@ -76,6 +76,8 @@ protected: static QPointF project(const SGGeod &geod, const SGGeod ¢er); static SGGeod unproject(const QPointF &xy, const SGGeod ¢er); + + void paintAirplaneIcon(QPainter *painter, const SGGeod &geod, int headingDeg); private: void paintNavaids(QPainter *p); diff --git a/src/GUI/NavaidDiagram.cxx b/src/GUI/NavaidDiagram.cxx index 29857991e..a621ebd05 100644 --- a/src/GUI/NavaidDiagram.cxx +++ b/src/GUI/NavaidDiagram.cxx @@ -83,8 +83,7 @@ void NavaidDiagram::paintContents(QPainter *painter) { QPointF base = project(m_geod); - QPointF airplaneIconPos = base; - + SGGeod aircraftPos = m_geod; if (m_offsetEnabled) { double d = m_offsetDistanceNm * SG_NM_TO_METER; SGGeod offsetGeod = SGGeodesy::direct(m_geod, m_offsetBearingDeg, d); @@ -95,19 +94,10 @@ void NavaidDiagram::paintContents(QPainter *painter) painter->setPen(pen); painter->drawLine(base, offset); - airplaneIconPos = offset; + aircraftPos = offsetGeod; } - QPixmap pix(":/airplane-icon"); - airplaneIconPos = painter->transform().map(airplaneIconPos); - painter->resetTransform(); - painter->translate(airplaneIconPos.x(), airplaneIconPos.y()); - painter->rotate(m_headingDeg); - - painter->setRenderHint(QPainter::SmoothPixmapTransform, true); - QRect airplaneIconRect = pix.rect(); - airplaneIconRect.moveCenter(QPoint(0,0)); - painter->drawPixmap(airplaneIconRect, pix); + paintAirplaneIcon(painter, aircraftPos, m_headingDeg); } void NavaidDiagram::doComputeBounds() -- 2.39.5