}
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)
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;
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:
string _fmt;
float _mult;
float _offs;
+ bool _trunc;
mutable char _buf[1024];
};
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.