#include "HUD.hxx"
+static const float TICK_OFFSET = 2.f;
+
HUD::Tape::Tape(HUD *hud, const SGPropertyNode *n, float x, float y) :
Scale(hud, n, x, y),
_draw_cap_right(n->getBoolValue("cap-right", false)),
_draw_cap_left(n->getBoolValue("cap-left", false)),
_marker_offset(n->getFloatValue("marker-offset")),
+ _label_offset(n->getFloatValue("label-offset", 3.0)),
_label_gap(n->getFloatValue("label-gap-width") / 2.0),
_pointer(n->getBoolValue("enable-pointer", true)),
_format(n->getStringValue("format", "%d"))
void HUD::Tape::draw_vertical(float value)
{
- float vmin = 0.0, vmax = 0.0;
+ float vmin = 0.0;//, vmax = 0.0;
float marker_xs;
float marker_xe;
float marker_ye;
if (!_pointer) {
vmin = value - _half_width_units; // width units == needle travel
- vmax = value + _half_width_units; // or picture unit span.
+// vmax = value + _half_width_units; // or picture unit span.
text_y = _center_y;
} else if (_pointer_type == MOVING) {
vmin = _input.min();
- vmax = _input.max();
+// vmax = _input.max();
} else { // FIXED
vmin = value - _half_width_units; // width units == needle travel
- vmax = value + _half_width_units; // or picture unit span.
+// vmax = value + _half_width_units; // or picture unit span.
text_y = _center_y;
}
for (int i = 0; ; i++) {
float v = vstart + i * _minor_divs;
- if (!_modulo)
+ if (!_modulo) {
if (v < _input.min())
continue;
else if (v > _input.max())
break;
+ }
float y = _y + (v - vmin) * factor();
- if (y < _y + 0)
+ if (y < _y + TICK_OFFSET)
continue;
- if (y > top - 0)
+ if (y > top - TICK_OFFSET)
break;
if (_div_ratio && i % _div_ratio) { // minor div
draw_bullet(marker_xs + 4, y, 5.0);
if (option_left())
- x = marker_xs, align = RIGHT|VCENTER;
+ x = marker_xs - _label_offset, align = RIGHT|VCENTER;
else
- x = marker_xe, align = LEFT|VCENTER;
+ x = marker_xe + _label_offset, align = LEFT|VCENTER;
}
if (!option_notext()) {
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) {
+ || (b < _center_y - _label_gap && t < _center_y - _label_gap)
+ || (b > _center_y + _label_gap && t > _center_y + _label_gap)) {
draw_text(x, y, s);
}
}
void HUD::Tape::draw_horizontal(float value)
{
- float vmin = 0.0, vmax = 0.0;
+ float vmin = 0.0;//, vmax = 0.0;
float marker_xs;
- float marker_xe;
+// float marker_xe;
float marker_ys;
float marker_ye;
- float text_y = 0.0;
+// float text_y = 0.0;
float top = _y + _h;
float right = _x + _w;
if (!_pointer) {
vmin = value - _half_width_units; // width units == needle travel
- vmax = value + _half_width_units; // or picture unit span.
- text_y = _center_y;
+// vmax = value + _half_width_units; // or picture unit span.
+// text_y = _center_y;
} else if (_pointer_type == MOVING) {
vmin = _input.min();
- vmax = _input.max();
+// vmax = _input.max();
} else { // FIXED
vmin = value - _half_width_units; // width units == needle travel
- vmax = value + _half_width_units; // or picture unit span.
- text_y = _center_y;
+// vmax = value + _half_width_units; // or picture unit span.
+// text_y = _center_y;
}
// left tick bar
marker_ys = _y; // Starting point for
marker_ye = top; // tick y location calcs
- marker_xe = right;
+// marker_xe = right;
marker_xs = _x + ((value - vmin) * factor());
if (option_top()) {
for (int i = 0; ; i++) {
float v = vstart + i * _minor_divs;
- if (!_modulo)
+ if (!_modulo) {
if (v < _input.min())
continue;
else if (v > _input.max())
break;
+ }
float x = _x + (v - vmin) * factor();
- if (x < _x + 0)
+ if (x < _x + TICK_OFFSET)
continue;
- if (x > right - 0)
+ if (x > right - TICK_OFFSET)
break;
if (_div_ratio && i % _div_ratio) { // minor div
draw_line(x, marker_ys, x, marker_ye);
if (option_top())
- y = top, align = TOP|HCENTER;
+ y = top - _label_offset, align = TOP|HCENTER;
else
- y = _y, align = BOTTOM|HCENTER;
+ y = _y + _label_offset, align = BOTTOM|HCENTER;
}
if (!option_notext()) {
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) {
+ || (l < _center_x - _label_gap && r < _center_x - _label_gap)
+ || (l > _center_x + _label_gap && r > _center_x + _label_gap)) {
draw_text(x, y, s);
}
}
char *HUD::Tape::format_value(float v)
{
- if (fabsf(v) < 1e-8) // avoid -0.0
+ if (fabs(v) < 1e-8) // avoid -0.0
v = 0.0f;
if (_label_fmt == INT)