virtual bool isEnabled();
protected:
+ enum Format {
+ INVALID,
+ NONE,
+ INT,
+ LONG,
+ FLOAT,
+ DOUBLE,
+ STRING,
+ };
+
+ Format check_format(const char *) const;
inline float get_span() const { return _scr_span; }
inline int get_digits() const { return _digits; }
virtual void draw();
private:
- enum Format {
- INVALID,
- NONE,
- INT,
- LONG,
- FLOAT,
- DOUBLE,
- STRING,
- };
-
- Format check_format(const char *) const;
bool blink();
Input _input;
protected:
void draw_fixed_pointer(float, float, float, float, float, float);
void zoomed_scale(int, int);
+ char *format_value(float);
private:
float _val_span;
float _marker_offset;
float _label_gap;
bool _pointer;
+ Format _label_fmt;
+ string _format;
int _zoom;
+ enum { BUFSIZE = 64 };
+ char _buf[BUFSIZE];
+
enum PointerType { FIXED, MOVING } _pointer_type;
enum TickType { LINE, CIRCLE } _tick_type;
enum TickLength { VARIABLE, CONSTANT } _tick_length;
_marker_offset(n->getFloatValue("marker-offset", 0.0)),
_label_gap(n->getFloatValue("label-gap-width", 0.0) / 2.0),
_pointer(n->getBoolValue("enable-pointer", true)),
+ _format(n->getStringValue("format", "%d")),
_zoom(n->getIntValue("zoom"))
{
_half_width_units = range_to_show() / 2.0;
s = n->getStringValue("tick-length"); // "variable", "constant"
_tick_length = strcmp(s, "constant") ? VARIABLE : CONSTANT;
+
+ _label_fmt = check_format(_format.c_str());
+ if (_label_fmt != INT && _label_fmt != LONG
+ && _label_fmt != FLOAT && _label_fmt != DOUBLE) {
+ _label_fmt = INT;
+ _format = "%d";
+ }
}
float marker_ys;
float marker_ye;
float text_y = 0.0;
- const int BUFSIZE = 80;
- char buf[BUFSIZE];
int oddtype;
// int k; //odd or even values for ticks // FIXME odd scale
} // end huds both
} else { // major div
- int display_value = int(v);
if (_modulo)
- display_value %= _modulo;
-
- snprintf(buf, BUFSIZE, "%d", display_value);
+ v = fmodf(v + _modulo, _modulo);
float x;
int align;
}
if (!option_notext()) {
+ char *s = format_value(v);
+
float l, r, b, t;
- _hud->_text_list.align(buf, align, &x, &y, &l, &r, &b, &t);
+ _hud->_text_list.align(s, align, &x, &y, &l, &r, &b, &t);
if (b < _y || t > top)
continue;
if (_label_gap == 0.0
|| b < _center_y - _label_gap && t < _center_y - _label_gap
|| b > _center_y + _label_gap && t > _center_y + _label_gap) {
- draw_text(x, y, buf);
+ draw_text(x, y, s);
}
}
}
}
} else { // major divs
- int display_value = int(v);
if (_modulo)
- display_value %= _modulo;
-
- snprintf(buf, BUFSIZE, "%d", display_value);
+ v = fmodf(v + _modulo, _modulo);
float y;
int align;
}
if (!option_notext()) {
+ char *s = format_value(v);
+
float l, r, b, t;
- _hud->_text_list.align(buf, align, &x, &y, &l, &r, &b, &t);
+ _hud->_text_list.align(s, align, &x, &y, &l, &r, &b, &t);
if (l < _x || r > right)
continue;
if (_label_gap == 0.0
|| l < _center_x - _label_gap && r < _center_x - _label_gap
|| l > _center_x + _label_gap && r > _center_x + _label_gap) {
- draw_text(x, y, buf);
+ draw_text(x, y, s);
}
}
}
}
+char *HUD::Tape::format_value(float v)
+{
+ if (_label_fmt == INT)
+ snprintf(_buf, BUFSIZE, _format.c_str(), int(v + 0.5f));
+ else if (_label_fmt == LONG)
+ snprintf(_buf, BUFSIZE, _format.c_str(), long(v + 0.5f));
+ else if (_label_fmt == FLOAT)
+ snprintf(_buf, BUFSIZE, _format.c_str(), v);
+ else // _label_fmt == DOUBLE
+ snprintf(_buf, BUFSIZE, _format.c_str(), double(v));
+ return _buf;
+}
+
+
void HUD::Tape::draw_fixed_pointer(float x1, float y1, float x2, float y2, float x3, float y3)
{
glBegin(GL_LINE_STRIP);