From 6ba351cfc691c52c5e9699cf8a759c567f375004 Mon Sep 17 00:00:00 2001 From: ehofman Date: Thu, 22 Jan 2004 18:42:42 +0000 Subject: [PATCH] Make it possible to truncate the result of a number-value text chunk calculation rather than rounding it by specifying true inside the chunk. --- src/Cockpit/panel.cxx | 9 ++++++--- src/Cockpit/panel.hxx | 4 +++- src/Cockpit/panel_io.cxx | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Cockpit/panel.cxx b/src/Cockpit/panel.cxx index de9a78778..25d6066ca 100644 --- a/src/Cockpit/panel.cxx +++ b/src/Cockpit/panel.cxx @@ -1092,8 +1092,9 @@ FGTextLayer::Chunk::Chunk (const string &text, const string &fmt) } FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node, - const string &fmt, float mult, float offs) - : _type(type), _fmt(fmt), _mult(mult), _offs(offs) + const string &fmt, float mult, float offs, + bool truncation) + : _type(type), _fmt(fmt), _mult(mult), _offs(offs), _trunc(truncation) { if (_fmt.empty()) { if (type == TEXT_VALUE) @@ -1117,7 +1118,9 @@ FGTextLayer::Chunk::getValue () const sprintf(_buf, _fmt.c_str(), _node->getStringValue()); break; case DOUBLE_VALUE: - sprintf(_buf, _fmt.c_str(), _offs + _node->getFloatValue() * _mult); + double d = _offs + _node->getFloatValue() * _mult; + if (_trunc) d = truncf(d); + sprintf(_buf, _fmt.c_str(), d); break; } return _buf; diff --git a/src/Cockpit/panel.hxx b/src/Cockpit/panel.hxx index 01ccc469d..b99889ce1 100644 --- a/src/Cockpit/panel.hxx +++ b/src/Cockpit/panel.hxx @@ -492,7 +492,8 @@ public: public: Chunk (const string &text, const string &fmt = "%s"); Chunk (ChunkType type, const SGPropertyNode * node, - const string &fmt = "", float mult = 1.0, float offs = 0.0); + const string &fmt = "", float mult = 1.0, float offs = 0.0, + bool truncation = false); const char * getValue () const; private: @@ -502,6 +503,7 @@ public: string _fmt; float _mult; float _offs; + bool _trunc; mutable char _buf[1024]; }; diff --git a/src/Cockpit/panel_io.cxx b/src/Cockpit/panel_io.cxx index 55dcb52ac..86e01b758 100644 --- a/src/Cockpit/panel_io.cxx +++ b/src/Cockpit/panel_io.cxx @@ -366,9 +366,10 @@ readTextChunk (const SGPropertyNode * node) string propName = node->getStringValue("property"); float scale = node->getFloatValue("scale", 1.0); float offset = node->getFloatValue("offset", 0.0); + bool truncation = node->getFloatValue("truncate", false); SGPropertyNode * target = fgGetNode(propName.c_str(), true); chunk = new FGTextLayer::Chunk(FGTextLayer::DOUBLE_VALUE, target, - format, scale, offset); + format, scale, offset, truncation); } // Unknown type. -- 2.39.5