From 9bfcf13ef81ab41f2ac69676709979a136e341cd Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Thu, 29 Jul 2021 20:04:36 +0100 Subject: [PATCH] Issues #72, #110 Use label and text colors settings in xswiftbus and XP driver --- src/plugins/simulator/xplane/simulatorxplane.cpp | 12 +++++++----- src/xswiftbus/traffic.cpp | 12 +++++++----- src/xswiftbus/traffic.h | 4 +++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 561a9c583..2b8869a71 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -569,7 +569,8 @@ namespace BlackSimPlugin if (isInFunction) { return; } isInFunction = true; - QColor color = "cyan"; + std::vector msgBoxValues = m_xSwiftBusServerSettings.getThreadLocal().getMessageBoxValuesVector(); + QColor color = msgBoxValues[9]; /* switch (message.getSeverity()) { case CStatusMessage::SeverityDebug: color = "teal"; break; @@ -587,11 +588,12 @@ namespace BlackSimPlugin // avoid issues during shutdown if (this->isShuttingDownOrDisconnected()) { return; } + std::vector msgBoxValues = m_xSwiftBusServerSettings.getThreadLocal().getMessageBoxValuesVector(); QColor color; - if (message.isServerMessage()) { color = "orchid"; } - else if (message.isSupervisorMessage()) { color = "yellow"; } - else if (message.isPrivateMessage()) { color = "magenta"; } - else { color = "lime"; } + if (message.isServerMessage()) { color = msgBoxValues[8]; } + else if (message.isSupervisorMessage()) { color = msgBoxValues[10]; } + else if (message.isPrivateMessage()) { color = msgBoxValues[7]; } + else { color = msgBoxValues[6]; } m_serviceProxy->addTextMessage(message.getSenderCallsign().toQString() + ": " + message.getMessage(), color.redF(), color.greenF(), color.blueF()); } diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index c86d9581f..2d76e1f77 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -261,7 +261,7 @@ namespace XSwiftBus XPMPSetDefaultPlaneICAO(defaultIcao.c_str()); } - void CTraffic::setDrawingLabels(bool drawing) + void CTraffic::setDrawingLabels(bool drawing, int rgb) { CSettings s = this->getSettings(); if (s.isDrawingLabels() != drawing) @@ -269,7 +269,10 @@ namespace XSwiftBus s.setDrawingLabels(drawing); this->setSettings(s); } - + if (rgb >= 0) + { + m_labels.setColor((rgb & 0xff0000) >> 16, (rgb & 0x00ff00) >> 8, rgb & 0x0000ff); + } if (drawing) { m_labels.show(); @@ -828,7 +831,7 @@ namespace XSwiftBus { invokeQueuedDBusCalls(); doPlaneUpdates(); - setDrawingLabels(getSettings().isDrawingLabels()); + setDrawingLabels(getSettings().isDrawingLabels(), getSettings().getLabelColor()); emitSimFrame(); m_countFrame++; return 1; @@ -901,7 +904,6 @@ namespace XSwiftBus { static const double maxRangeM = 10000; static const double metersPerFt = 0.3048; - static float color[3]{ 1.0f, 0.75f, 0.0f }; std::array worldMat = m_worldMat.getAll(); std::array projMat = m_projMat.getAll(); double windowWidth = static_cast(m_windowWidth.get()); @@ -931,7 +933,7 @@ namespace XSwiftBus { continue; // plane is behind camera } - XPLMDrawString(color, + XPLMDrawString(m_color.data(), static_cast(std::lround(windowWidth * (windowPos[0] * 0.5 + 0.5))), static_cast(std::lround(windowHeight * (windowPos[1] * 0.5 + 0.5))), text, nullptr, xplmFont_Basic); diff --git a/src/xswiftbus/traffic.h b/src/xswiftbus/traffic.h index 6bda2f09b..b7f892132 100644 --- a/src/xswiftbus/traffic.h +++ b/src/xswiftbus/traffic.h @@ -76,7 +76,7 @@ namespace XSwiftBus void setDefaultIcao(const std::string &defaultIcao); //! Set whether the plugin draws type and callsign labels above aircraft - void setDrawingLabels(bool drawing); + void setDrawingLabels(bool drawing, int rgb = -1); //! Get whether the plugin draws type and callsign labels above aircraft bool isDrawingLabels() const; @@ -194,12 +194,14 @@ namespace XSwiftBus { public: Labels(CTraffic *traffic) : CDrawable(xplm_Phase_Window, false), m_traffic(traffic) {} + void setColor(int r, int g, int b) { m_color = {{ static_cast(r) / 255.f, static_cast(g) / 255.f, static_cast(b) / 255.f }}; } protected: virtual void draw() override; private: static void matrixMultVec(double out[4], const float m[16], const double v[4]); double distanceSquared(const double pos[3]) const; CTraffic *m_traffic = nullptr; + std::array m_color{{ 1.0f, 0.75f, 0.0f }}; ArrayDataRef m_worldMat; ArrayDataRef m_projMat; DataRef m_windowWidth;