From 7025186ef29c4f93d5d8025379b29f8dcf400cba Mon Sep 17 00:00:00 2001 From: nakajimayoshi Date: Fri, 3 Mar 2023 22:56:35 +0900 Subject: [PATCH 1/6] initial commit --- B78XH/B78XH.vcxproj | 2 +- B78XH/PFDAirspeedIndicatorApplication.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/B78XH/B78XH.vcxproj b/B78XH/B78XH.vcxproj index 963b842..c588506 100644 --- a/B78XH/B78XH.vcxproj +++ b/B78XH/B78XH.vcxproj @@ -51,7 +51,7 @@ true .wasm $(MSFS_IncludePath);$(CPP_EXTERNALS)\include\NANOVG; - ..\..\..\..\WebstormProjects\B78XH-INTERIOR\SimObjects\Airplanes\Asobo_B787_10\panel + ..\..\..\..\Desktop\msfs_addons\Aircraft\787-10_Heavy_Division\B78XH-experimental\SimObjects\Airplanes\Heavy-Division-B78XH-mod\panel false diff --git a/B78XH/PFDAirspeedIndicatorApplication.h b/B78XH/PFDAirspeedIndicatorApplication.h index 16b80d6..991086c 100644 --- a/B78XH/PFDAirspeedIndicatorApplication.h +++ b/B78XH/PFDAirspeedIndicatorApplication.h @@ -44,6 +44,7 @@ class PFDAirspeedIndicatorApplication: public Application { void drawGraduations(); void drawCursor(); void drawTargetPointer(); + void drawMach(); public: auto render(sGaugeDrawData* data) -> void override; }; \ No newline at end of file From d5c925aac937121c622c112059a68e73415d07f9 Mon Sep 17 00:00:00 2001 From: nakajimayoshi Date: Sat, 4 Mar 2023 20:40:55 +0900 Subject: [PATCH 2/6] render mach above 0.4 --- B78XH/B78XH.vcxproj | 3 +- B78XH/B78XH.vcxproj.filters | 7 ++- B78XH/{Timer.cpp => Counter.cpp} | 20 ++++----- B78XH/Counter.h | 45 +++++++++++++++++++ B78XH/PFDAirspeedIndicatorApplication.cpp | 37 +++++++++++++-- B78XH/PFDAirspeedIndicatorApplication.h | 14 +++++- B78XH/PFDRadioAltitudeIndicator.h | 4 +- B78XH/PFDRadioAltitudeIndicatorApplication.h | 4 +- B78XH/SimConnectConnector.cpp | 3 ++ B78XH/SimConnectData.h | 1 + B78XH/Simplane.h | 5 +++ B78XH/Timer.h | 47 ++++---------------- Tools/Tools.cpp | 18 ++++++++ Tools/Tools.h | 3 ++ 14 files changed, 151 insertions(+), 60 deletions(-) rename B78XH/{Timer.cpp => Counter.cpp} (77%) create mode 100644 B78XH/Counter.h diff --git a/B78XH/B78XH.vcxproj b/B78XH/B78XH.vcxproj index c588506..a151daf 100644 --- a/B78XH/B78XH.vcxproj +++ b/B78XH/B78XH.vcxproj @@ -303,7 +303,7 @@ - + @@ -535,6 +535,7 @@ + diff --git a/B78XH/B78XH.vcxproj.filters b/B78XH/B78XH.vcxproj.filters index 6ca7e02..cbaba28 100644 --- a/B78XH/B78XH.vcxproj.filters +++ b/B78XH/B78XH.vcxproj.filters @@ -184,7 +184,7 @@ Source Files\Gauges\PFD - + Source Files\Tools\Timers @@ -867,7 +867,7 @@ Source Files\Gauges\PFD - + Source Files\Tools\Timers @@ -1332,6 +1332,9 @@ Source Files\Controls\Controls\MFD\ND + + Source Files\Tools\Timers + diff --git a/B78XH/Timer.cpp b/B78XH/Counter.cpp similarity index 77% rename from B78XH/Timer.cpp rename to B78XH/Counter.cpp index 04671c9..a65d092 100644 --- a/B78XH/Timer.cpp +++ b/B78XH/Counter.cpp @@ -15,32 +15,32 @@ // along with this program. If not, see . -#include "Timer.h" +#include "Counter.h" -auto Timer::start() -> void { +auto Counter::start() -> void { this->isStarted = true; this->isFinished = false; } -auto Timer::restart() -> void { +auto Counter::restart() -> void { this->reset(); this->isFinished = false; } -auto Timer::stop() -> void { +auto Counter::stop() -> void { this->isStarted = false; } -auto Timer::stop(bool force) -> void { +auto Counter::stop(bool force) -> void { this->autoStart = false; this->isStarted = false; } -auto Timer::reset() -> void { +auto Counter::reset() -> void { this->internalValue = 0; } -auto Timer::update(double value) -> void { +auto Counter::update(double value) -> void { if (this->isFinished) { return; } @@ -53,14 +53,14 @@ auto Timer::update(double value) -> void { } } -auto Timer::value() const -> double { +auto Counter::value() const -> double { return this->internalValue; } -auto Timer::finished() const -> bool { +auto Counter::finished() const -> bool { return this->isFinished; } -auto Timer::started() const -> bool { +auto Counter::started() const -> bool { return this->isStarted; } diff --git a/B78XH/Counter.h b/B78XH/Counter.h new file mode 100644 index 0000000..0f21bce --- /dev/null +++ b/B78XH/Counter.h @@ -0,0 +1,45 @@ +// B78XH-wasm +// Copyright (C) 2022 Heavy Division +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + + +#pragma once + +class Counter { + +public: + + Counter(double target_value, bool auto_start = false) + : targetValue(target_value), autoStart(auto_start) {} + + auto reset() -> void; + auto update(double value) -> void; + + auto start() -> void; + auto restart() -> void; + auto stop() -> void; + auto stop(bool force) -> void; + auto value() const -> double; + auto finished() const -> bool; + auto started() const -> bool; + +protected: + double targetValue; + double internalValue = 0; + bool isStarted = false; + bool isFinished = false; + bool autoStart = false; + +}; diff --git a/B78XH/PFDAirspeedIndicatorApplication.cpp b/B78XH/PFDAirspeedIndicatorApplication.cpp index a8a7342..66af947 100644 --- a/B78XH/PFDAirspeedIndicatorApplication.cpp +++ b/B78XH/PFDAirspeedIndicatorApplication.cpp @@ -14,17 +14,19 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - + #include "PFDAirspeedIndicatorApplication.h" #include - +#include #include "Tools/Tools.h" #include "Simplane.h" - +#include "Tools/Console.h" +#include "Timer.h" using Colors = Tools::Colors; void PFDAirspeedIndicatorApplication::render(sGaugeDrawData* data) { + this->machSpeed = Simplane::aircraft::state::machSpeed(); nvgSave(this->nvgContext); drawBackground(); drawGraduations(); @@ -32,7 +34,11 @@ void PFDAirspeedIndicatorApplication::render(sGaugeDrawData* data) { drawCursor(); drawStallStrips(); drawOverSpeedStrips(); + drawSpeedMarkers(data->dt); + + drawMach(this->shouldDrawMach()); + nvgRestore(this->nvgContext); } @@ -567,3 +573,28 @@ void PFDAirspeedIndicatorApplication::drawTargetPointer() { nvgResetTransform(this->nvgContext); nvgRestore(this->nvgContext); } + +void PFDAirspeedIndicatorApplication::drawMach(bool render) { + nvgFontFace(this->nvgContext, "roboto"); + nvgFontSize(this->nvgContext, 30.0f); + nvgFillColor(this->nvgContext, Colors::white); + nvgTextAlign(this->nvgContext, NVG_ALIGN_LEFT); + + if (render) { + nvgBeginPath(this->nvgContext); + { + nvgText(this->nvgContext, 10, 495, Tools::formatToFixed(machSpeed, 3).c_str(), nullptr); + nvgFill(this->nvgContext); + } + } + +} + +bool PFDAirspeedIndicatorApplication::shouldStartTimer() const { + return this->lastMachSpeed > 4 && this->machSpeed >= 0.4; +} + +bool PFDAirspeedIndicatorApplication::shouldDrawMach() const { + return this->machSpeed >= 0.4; +} + diff --git a/B78XH/PFDAirspeedIndicatorApplication.h b/B78XH/PFDAirspeedIndicatorApplication.h index 991086c..2272c5a 100644 --- a/B78XH/PFDAirspeedIndicatorApplication.h +++ b/B78XH/PFDAirspeedIndicatorApplication.h @@ -22,6 +22,8 @@ #include "V2SpeedMarker.h" #include "VRefSpeedMarker.h" #include "VRSpeedMarker.h" +#include "Counter.h" +#include "Timer.h" class PFDAirspeedIndicatorApplication: public Application { @@ -32,6 +34,11 @@ class PFDAirspeedIndicatorApplication: public Application { inline static VRefSpeedMarker vRefSpeedMarker = VRefSpeedMarker("REF", false); inline static FlapsSpeedMarker currentFlapsMarker = FlapsSpeedMarker("", true); inline static FlapsSpeedMarker nextFlapsMarker = FlapsSpeedMarker("", true); + + Timer timer = Timer(10); + double lastMachSpeed; + double machSpeed = Simplane::aircraft::state::machSpeed(); + void drawVSpeedMarkers(double v1, double v2, double vR, double deltaTime); void drawNOVSpeedMessage(); void drawSpeedMarkers(double deltaTime); @@ -44,7 +51,10 @@ class PFDAirspeedIndicatorApplication: public Application { void drawGraduations(); void drawCursor(); void drawTargetPointer(); - void drawMach(); + void drawMach(bool render); + bool shouldStartTimer() const; + bool shouldDrawMach() const; + public: auto render(sGaugeDrawData* data) -> void override; -}; \ No newline at end of file +}; diff --git a/B78XH/PFDRadioAltitudeIndicator.h b/B78XH/PFDRadioAltitudeIndicator.h index 45af1f6..6b87255 100644 --- a/B78XH/PFDRadioAltitudeIndicator.h +++ b/B78XH/PFDRadioAltitudeIndicator.h @@ -16,7 +16,7 @@ #pragma once -#include "Timer.h" +#include "Counter.h" #include "MSFS/Render/nanovg.h" @@ -32,5 +32,5 @@ class PFDRadioAltitudeIndicator { double passDelta = -1; double altitude = 0; double lastAltitude = 0; - Timer deltaTimer = Timer(10); + Counter deltaTimer = Counter(10); }; diff --git a/B78XH/PFDRadioAltitudeIndicatorApplication.h b/B78XH/PFDRadioAltitudeIndicatorApplication.h index a358b96..0795b84 100644 --- a/B78XH/PFDRadioAltitudeIndicatorApplication.h +++ b/B78XH/PFDRadioAltitudeIndicatorApplication.h @@ -17,7 +17,7 @@ #pragma once #include "Application.h" -#include "Timer.h" +#include "Counter.h" class PFDRadioAltitudeIndicatorApplication : public Application { public: @@ -33,5 +33,5 @@ class PFDRadioAltitudeIndicatorApplication : public Application { double passDelta = -1; double altitude = 0; double lastAltitude = 0; - Timer deltaTimer = Timer(10); + Counter deltaTimer = Counter(10); }; diff --git a/B78XH/SimConnectConnector.cpp b/B78XH/SimConnectConnector.cpp index 7e8b97e..b1c995d 100644 --- a/B78XH/SimConnectConnector.cpp +++ b/B78XH/SimConnectConnector.cpp @@ -182,6 +182,9 @@ auto SimConnectConnector::prepareDataDefinitions() -> void { this->connectionResult = SimConnect_AddToDataDefinition(simConnectHandle, DEFINITION_AIRCRAFT_STATE, "MAX GROSS WEIGHT", "Pounds"); + this->connectionResult = SimConnect_AddToDataDefinition(simConnectHandle, DEFINITION_AIRCRAFT_STATE, + "AIRSPEED MACH", "mach"); + /* * Autopilot - State */ diff --git a/B78XH/SimConnectData.h b/B78XH/SimConnectData.h index 4adaec8..892d407 100644 --- a/B78XH/SimConnectData.h +++ b/B78XH/SimConnectData.h @@ -121,6 +121,7 @@ namespace SimConnectData { double headingMagneticGround; double weight; double maxWeight; + double machSpeed; /* * Calculated diff --git a/B78XH/Simplane.h b/B78XH/Simplane.h index d90ea3c..0a13425 100644 --- a/B78XH/Simplane.h +++ b/B78XH/Simplane.h @@ -82,6 +82,7 @@ namespace Simplane { auto weight() -> double; auto maxWeight() -> double; auto maxGrossWeight() -> double; + auto machSpeed() -> double; } } @@ -1407,3 +1408,7 @@ inline auto Simplane::equipment::radioNav::unit4::name() -> char* { inline auto Simplane::equipment::radioNav::unit4::ident() -> char* { return SimConnectData::Equipment::RadioNav::unit4.ident; } + +inline auto Simplane::aircraft::state::machSpeed() -> double { + return SimConnectData::Aircraft::state.machSpeed; +} diff --git a/B78XH/Timer.h b/B78XH/Timer.h index f5ece24..7db3326 100644 --- a/B78XH/Timer.h +++ b/B78XH/Timer.h @@ -1,42 +1,13 @@ -// B78XH-wasm -// Copyright (C) 2022 Heavy Division -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - - #pragma once -class Timer { - public: - Timer(double target_value, bool auto_start = false) - : targetValue(target_value), - autoStart(auto_start) { - } +#include +#include "Counter.h" +#include "Simplane.h" - auto start() -> void; - auto restart() -> void; - auto stop() -> void; - auto stop(bool force) -> void; - auto reset() -> void; - auto update(double value) -> void; - auto value() const -> double; - auto finished() const -> bool; - auto started() const -> bool; - private: - double targetValue; - double internalValue = 0; - bool isStarted = false; - bool isFinished = false; - bool autoStart = false; +class Timer : public Counter { +public: + Timer(double target_value, bool auto_start = false) + : Counter(target_value, auto_start) { + } }; + diff --git a/Tools/Tools.cpp b/Tools/Tools.cpp index a83ce0b..c448ea7 100644 --- a/Tools/Tools.cpp +++ b/Tools/Tools.cpp @@ -142,4 +142,22 @@ namespace Tools { auto clamp(double value, double lo, double hi) -> double { return std::min(hi, std::max(value, lo)); }; + + auto formatToFixed(int data, int decimals) -> std::string { + + return fmt::format("{:." + std::to_string(decimals) + "f}", data); + + } + + auto formatToFixed(double data, int decimals) -> std::string { + + return fmt::format("{:." + std::to_string(decimals) + "f}", data); + + } + + auto formatToFixed(float data, int decimals) -> std::string { + + return fmt::format("{:." + std::to_string(decimals) + "f}", data); + + } } diff --git a/Tools/Tools.h b/Tools/Tools.h index 2e57533..b8fe065 100644 --- a/Tools/Tools.h +++ b/Tools/Tools.h @@ -75,4 +75,7 @@ namespace Tools { auto smoothPow(double start, double end, double factor, double deltaTime) -> double; auto clamp(double value, double lo, double hi) -> double; + auto formatToFixed(int data, int decimals) -> std::string; + auto formatToFixed(double data, int decimals) -> std::string; + auto formatToFixed(float data, int decimals) -> std::string; } \ No newline at end of file From 2cd86edb4bc7a0fd0e09073018d66c3310abfc80 Mon Sep 17 00:00:00 2001 From: nakajimayoshi Date: Sat, 4 Mar 2023 22:45:30 +0900 Subject: [PATCH 3/6] mach highlight --- B78XH/PFDAirspeedIndicatorApplication.cpp | 42 ++++++++++++++++++----- B78XH/PFDAirspeedIndicatorApplication.h | 5 +-- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/B78XH/PFDAirspeedIndicatorApplication.cpp b/B78XH/PFDAirspeedIndicatorApplication.cpp index 66af947..59eb508 100644 --- a/B78XH/PFDAirspeedIndicatorApplication.cpp +++ b/B78XH/PFDAirspeedIndicatorApplication.cpp @@ -37,7 +37,23 @@ void PFDAirspeedIndicatorApplication::render(sGaugeDrawData* data) { drawSpeedMarkers(data->dt); - drawMach(this->shouldDrawMach()); + this->machSpeed = Simplane::aircraft::state::machSpeed(); + if (this->shouldDrawMach()) { + if (this->shouldStartTimer()) { + this->timer.start(); + } + this->timer.update(data->dt); + if (!this->timer.finished() && this->timer.started()) { + Console::log("DRAWING HIGHLIGHT"); + this->drawHighlight(); + } + this->drawMach(); + } + else { + this->timer.restart(); + this->timer.stop(); + } + this->lastMachSpeed = this->machSpeed; nvgRestore(this->nvgContext); } @@ -574,24 +590,32 @@ void PFDAirspeedIndicatorApplication::drawTargetPointer() { nvgRestore(this->nvgContext); } -void PFDAirspeedIndicatorApplication::drawMach(bool render) { +void PFDAirspeedIndicatorApplication::drawMach() { nvgFontFace(this->nvgContext, "roboto"); nvgFontSize(this->nvgContext, 30.0f); nvgFillColor(this->nvgContext, Colors::white); nvgTextAlign(this->nvgContext, NVG_ALIGN_LEFT); - if (render) { - nvgBeginPath(this->nvgContext); - { - nvgText(this->nvgContext, 10, 495, Tools::formatToFixed(machSpeed, 3).c_str(), nullptr); - nvgFill(this->nvgContext); - } + nvgBeginPath(this->nvgContext); + { + nvgText(this->nvgContext, 12, 495, Tools::formatToFixed(machSpeed, 3).c_str(), nullptr); + nvgFill(this->nvgContext); } +} + +void PFDAirspeedIndicatorApplication::drawHighlight() { + nvgStrokeColor(this->nvgContext, Colors::white); + nvgStrokeWidth(this->nvgContext, 2.0f); + nvgBeginPath(this->nvgContext); + { + nvgRect(this->nvgContext, 5, 475, 70, 25); + nvgStroke(this->nvgContext); + } } bool PFDAirspeedIndicatorApplication::shouldStartTimer() const { - return this->lastMachSpeed > 4 && this->machSpeed >= 0.4; + return this->lastMachSpeed < 0.4 && this->machSpeed >= 0.4; } bool PFDAirspeedIndicatorApplication::shouldDrawMach() const { diff --git a/B78XH/PFDAirspeedIndicatorApplication.h b/B78XH/PFDAirspeedIndicatorApplication.h index 2272c5a..ee241a1 100644 --- a/B78XH/PFDAirspeedIndicatorApplication.h +++ b/B78XH/PFDAirspeedIndicatorApplication.h @@ -37,7 +37,7 @@ class PFDAirspeedIndicatorApplication: public Application { Timer timer = Timer(10); double lastMachSpeed; - double machSpeed = Simplane::aircraft::state::machSpeed(); + double machSpeed; void drawVSpeedMarkers(double v1, double v2, double vR, double deltaTime); void drawNOVSpeedMessage(); @@ -51,7 +51,8 @@ class PFDAirspeedIndicatorApplication: public Application { void drawGraduations(); void drawCursor(); void drawTargetPointer(); - void drawMach(bool render); + void drawMach(); + void drawHighlight(); bool shouldStartTimer() const; bool shouldDrawMach() const; From 1c1704c1e6a431945a147661231c8c67f5fdb5e7 Mon Sep 17 00:00:00 2001 From: nakajimayoshi Date: Sun, 5 Mar 2023 16:51:48 +0900 Subject: [PATCH 4/6] increase font size --- B78XH/PFDAirspeedIndicatorApplication.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/B78XH/PFDAirspeedIndicatorApplication.cpp b/B78XH/PFDAirspeedIndicatorApplication.cpp index 59eb508..e45029a 100644 --- a/B78XH/PFDAirspeedIndicatorApplication.cpp +++ b/B78XH/PFDAirspeedIndicatorApplication.cpp @@ -592,7 +592,7 @@ void PFDAirspeedIndicatorApplication::drawTargetPointer() { void PFDAirspeedIndicatorApplication::drawMach() { nvgFontFace(this->nvgContext, "roboto"); - nvgFontSize(this->nvgContext, 30.0f); + nvgFontSize(this->nvgContext, 38.0f); nvgFillColor(this->nvgContext, Colors::white); nvgTextAlign(this->nvgContext, NVG_ALIGN_LEFT); From 77845ef23cb28e331bb20383c60e0fe209b44023 Mon Sep 17 00:00:00 2001 From: nakajimayoshi Date: Wed, 8 Mar 2023 00:30:41 +0900 Subject: [PATCH 5/6] dynamically set mach limit --- B78XH/B78XH.vcxproj | 3 +- B78XH/PFDAirspeedIndicatorApplication.cpp | 31 ++++++----- B78XH/PFDAirspeedIndicatorApplication.h | 65 ++++++++++++----------- Tools/Tools.cpp | 13 +++++ Tools/Tools.h | 2 + 5 files changed, 68 insertions(+), 46 deletions(-) diff --git a/B78XH/B78XH.vcxproj b/B78XH/B78XH.vcxproj index a151daf..d5ef6c7 100644 --- a/B78XH/B78XH.vcxproj +++ b/B78XH/B78XH.vcxproj @@ -51,8 +51,7 @@ true .wasm $(MSFS_IncludePath);$(CPP_EXTERNALS)\include\NANOVG; - ..\..\..\..\Desktop\msfs_addons\Aircraft\787-10_Heavy_Division\B78XH-experimental\SimObjects\Airplanes\Heavy-Division-B78XH-mod\panel - + ..\..\..\..\WebstormProjects\B78XH-INTERIOR\SimObjects\Airplanes\Asobo_B787_10\panel false .wasm diff --git a/B78XH/PFDAirspeedIndicatorApplication.cpp b/B78XH/PFDAirspeedIndicatorApplication.cpp index e45029a..bedaf37 100644 --- a/B78XH/PFDAirspeedIndicatorApplication.cpp +++ b/B78XH/PFDAirspeedIndicatorApplication.cpp @@ -16,17 +16,14 @@ #include "PFDAirspeedIndicatorApplication.h" - -#include -#include #include "Tools/Tools.h" #include "Simplane.h" -#include "Tools/Console.h" #include "Timer.h" +#include "string" + using Colors = Tools::Colors; void PFDAirspeedIndicatorApplication::render(sGaugeDrawData* data) { - this->machSpeed = Simplane::aircraft::state::machSpeed(); nvgSave(this->nvgContext); drawBackground(); drawGraduations(); @@ -34,25 +31,29 @@ void PFDAirspeedIndicatorApplication::render(sGaugeDrawData* data) { drawCursor(); drawStallStrips(); drawOverSpeedStrips(); - drawSpeedMarkers(data->dt); this->machSpeed = Simplane::aircraft::state::machSpeed(); + if (this->shouldDrawMach()) { + this->machLimit = 0.38; if (this->shouldStartTimer()) { this->timer.start(); } + this->timer.update(data->dt); if (!this->timer.finished() && this->timer.started()) { - Console::log("DRAWING HIGHLIGHT"); this->drawHighlight(); } + this->drawMach(); } else { + this->machLimit = 0.4; this->timer.restart(); this->timer.stop(); } + this->lastMachSpeed = this->machSpeed; nvgRestore(this->nvgContext); @@ -592,14 +593,16 @@ void PFDAirspeedIndicatorApplication::drawTargetPointer() { void PFDAirspeedIndicatorApplication::drawMach() { nvgFontFace(this->nvgContext, "roboto"); - nvgFontSize(this->nvgContext, 38.0f); + nvgFontSize(this->nvgContext, 34.0f); nvgFillColor(this->nvgContext, Colors::white); nvgTextAlign(this->nvgContext, NVG_ALIGN_LEFT); - nvgBeginPath(this->nvgContext); + auto machSpeed_string = Tools::formatToFixed(machSpeed, 3); + machSpeed_string.erase(0, machSpeed_string.find_first_not_of('0')); { - nvgText(this->nvgContext, 12, 495, Tools::formatToFixed(machSpeed, 3).c_str(), nullptr); + nvgText(this->nvgContext, 8, 512, machSpeed_string.c_str(), nullptr); nvgFill(this->nvgContext); + } } @@ -609,16 +612,18 @@ void PFDAirspeedIndicatorApplication::drawHighlight() { nvgStrokeWidth(this->nvgContext, 2.0f); nvgBeginPath(this->nvgContext); { - nvgRect(this->nvgContext, 5, 475, 70, 25); + nvgRect(this->nvgContext, 0, 490, 62, 25); nvgStroke(this->nvgContext); } } bool PFDAirspeedIndicatorApplication::shouldStartTimer() const { + return this->lastMachSpeed < 0.4 && this->machSpeed >= 0.4; + } bool PFDAirspeedIndicatorApplication::shouldDrawMach() const { - return this->machSpeed >= 0.4; -} + return this->machSpeed > this->machLimit; +} diff --git a/B78XH/PFDAirspeedIndicatorApplication.h b/B78XH/PFDAirspeedIndicatorApplication.h index ee241a1..38e6bc2 100644 --- a/B78XH/PFDAirspeedIndicatorApplication.h +++ b/B78XH/PFDAirspeedIndicatorApplication.h @@ -27,35 +27,38 @@ class PFDAirspeedIndicatorApplication: public Application { - private: - inline static V1SpeedMarker v1SpeedMarker = V1SpeedMarker("V1", false); - inline static V2SpeedMarker v2SpeedMarker = V2SpeedMarker("V2", false); - inline static VRSpeedMarker vRSpeedMarker = VRSpeedMarker("VR", false); - inline static VRefSpeedMarker vRefSpeedMarker = VRefSpeedMarker("REF", false); - inline static FlapsSpeedMarker currentFlapsMarker = FlapsSpeedMarker("", true); - inline static FlapsSpeedMarker nextFlapsMarker = FlapsSpeedMarker("", true); - - Timer timer = Timer(10); - double lastMachSpeed; - double machSpeed; - - void drawVSpeedMarkers(double v1, double v2, double vR, double deltaTime); - void drawNOVSpeedMessage(); - void drawSpeedMarkers(double deltaTime); - bool shouldDrawFlapsMarkers(double indicatedAltitude, double flightPhase); - void drawOverSpeedStrips(); - void drawStallStrips(); - void drawProtStrip(); - void drawStrips(); - void drawBackground(); - void drawGraduations(); - void drawCursor(); - void drawTargetPointer(); - void drawMach(); - void drawHighlight(); - bool shouldStartTimer() const; - bool shouldDrawMach() const; - - public: - auto render(sGaugeDrawData* data) -> void override; +private: + inline static V1SpeedMarker v1SpeedMarker = V1SpeedMarker("V1", false); + inline static V2SpeedMarker v2SpeedMarker = V2SpeedMarker("V2", false); + inline static VRSpeedMarker vRSpeedMarker = VRSpeedMarker("VR", false); + inline static VRefSpeedMarker vRefSpeedMarker = VRefSpeedMarker("REF", false); + inline static FlapsSpeedMarker currentFlapsMarker = FlapsSpeedMarker("", true); + inline static FlapsSpeedMarker nextFlapsMarker = FlapsSpeedMarker("", true); + + Timer timer = Timer(10); + + double machSpeed; + double lastMachSpeed; + double machLimit; + + + void drawVSpeedMarkers(double v1, double v2, double vR, double deltaTime); + void drawNOVSpeedMessage(); + void drawSpeedMarkers(double deltaTime); + bool shouldDrawFlapsMarkers(double indicatedAltitude, double flightPhase); + void drawOverSpeedStrips(); + void drawStallStrips(); + void drawProtStrip(); + void drawStrips(); + void drawBackground(); + void drawGraduations(); + void drawCursor(); + void drawTargetPointer(); + void drawMach(); + void drawHighlight(); + bool shouldStartTimer() const; + bool shouldDrawMach() const; + +public: + auto render(sGaugeDrawData* data) -> void override; }; diff --git a/Tools/Tools.cpp b/Tools/Tools.cpp index c448ea7..2084f8d 100644 --- a/Tools/Tools.cpp +++ b/Tools/Tools.cpp @@ -160,4 +160,17 @@ namespace Tools { return fmt::format("{:." + std::to_string(decimals) + "f}", data); } + + auto formatToFixed(std::string data, int decimals) -> std::string { + + return fmt::format("{:." + std::to_string(decimals) + "f}", data); + + } + + std::string double_to_string(double value) { + double integral = 0; + double fractional = std::modf(value, &integral); + return fmt::format("{}.{}", static_cast(integral), + static_cast(fractional * 1000)); + } } diff --git a/Tools/Tools.h b/Tools/Tools.h index b8fe065..5809146 100644 --- a/Tools/Tools.h +++ b/Tools/Tools.h @@ -78,4 +78,6 @@ namespace Tools { auto formatToFixed(int data, int decimals) -> std::string; auto formatToFixed(double data, int decimals) -> std::string; auto formatToFixed(float data, int decimals) -> std::string; + auto formatToFixed(std::string data, int decimals) -> std::string; + std::string double_to_string(double value); } \ No newline at end of file From d4a72baa94c687328cbc69328fbcbbdffac245d0 Mon Sep 17 00:00:00 2001 From: nakajimayoshi Date: Wed, 8 Mar 2023 20:03:22 +0900 Subject: [PATCH 6/6] minor font size & position tweaks --- B78XH/PFDAirspeedIndicatorApplication.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/B78XH/PFDAirspeedIndicatorApplication.cpp b/B78XH/PFDAirspeedIndicatorApplication.cpp index bedaf37..ad445c5 100644 --- a/B78XH/PFDAirspeedIndicatorApplication.cpp +++ b/B78XH/PFDAirspeedIndicatorApplication.cpp @@ -593,14 +593,14 @@ void PFDAirspeedIndicatorApplication::drawTargetPointer() { void PFDAirspeedIndicatorApplication::drawMach() { nvgFontFace(this->nvgContext, "roboto"); - nvgFontSize(this->nvgContext, 34.0f); + nvgFontSize(this->nvgContext, 38.0f); nvgFillColor(this->nvgContext, Colors::white); nvgTextAlign(this->nvgContext, NVG_ALIGN_LEFT); nvgBeginPath(this->nvgContext); auto machSpeed_string = Tools::formatToFixed(machSpeed, 3); machSpeed_string.erase(0, machSpeed_string.find_first_not_of('0')); { - nvgText(this->nvgContext, 8, 512, machSpeed_string.c_str(), nullptr); + nvgText(this->nvgContext, 8, 513, machSpeed_string.c_str(), nullptr); nvgFill(this->nvgContext); } @@ -612,7 +612,7 @@ void PFDAirspeedIndicatorApplication::drawHighlight() { nvgStrokeWidth(this->nvgContext, 2.0f); nvgBeginPath(this->nvgContext); { - nvgRect(this->nvgContext, 0, 490, 62, 25); + nvgRect(this->nvgContext, 0, 490, 70, 25); nvgStroke(this->nvgContext); } }