1
0
Fork 0
flightgear/src/Instrumentation/HUD/HUD_tape.cxx

891 lines
32 KiB
C++
Raw Normal View History

2006-07-04 15:32:55 +00:00
// HUD_tape.cxx -- HUD Tape Instrument
//
// Written by Michele America, started September 1997.
//
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
//
// 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 2 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "HUD.hxx"
HUD::Tape::Tape(HUD *hud, const SGPropertyNode *n, float x, float y) :
Scale(hud, n, x, y),
_draw_tick_bottom(n->getBoolValue("tick-bottom", false)),
_draw_tick_top(n->getBoolValue("tick-top", false)),
_draw_tick_right(n->getBoolValue("tick-right", false)),
_draw_tick_left(n->getBoolValue("tick-left", false)),
_draw_cap_bottom(n->getBoolValue("cap-bottom", false)),
_draw_cap_top(n->getBoolValue("cap-top", false)),
_draw_cap_right(n->getBoolValue("cap-right", false)),
_draw_cap_left(n->getBoolValue("cap-left", false)),
_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)),
_zoom(n->getIntValue("zoom"))
2006-07-04 15:32:55 +00:00
{
_half_width_units = range_to_show() / 2.0;
const char *s;
s = n->getStringValue("pointer-type");
_pointer_type = strcmp(s, "moving") ? FIXED : MOVING; // "fixed", "moving"
s = n->getStringValue("tick-type");
_tick_type = strcmp(s, "circle") ? LINE : CIRCLE; // "circle", "line"
s = n->getStringValue("tick-length"); // "variable", "constant"
_tick_length = strcmp(s, "constant") ? VARIABLE : CONSTANT;
2006-07-04 15:32:55 +00:00
}
void HUD::Tape::draw(void) // (HUD_scale * pscale)
{
if (!_input.isValid())
return;
float vmin = 0.0, vmax = 0.0;
float marker_xs;
float marker_xe;
float marker_ys;
float marker_ye;
2006-07-31 19:25:41 +00:00
float text_y = 0.0;
2006-07-04 15:32:55 +00:00
const int BUFSIZE = 80;
char buf[BUFSIZE];
int oddtype;
// int k; //odd or even values for ticks // FIXME odd scale
2006-07-04 15:32:55 +00:00
float cur_value = _input.getFloatValue();
2006-07-31 17:36:27 +00:00
if (int(floorf(_input.max() + 0.5)) & 1)
2006-07-04 15:32:55 +00:00
oddtype = 1; //draw ticks at odd values
else
oddtype = 0; //draw ticks at even values
float top = _y + _h;
float right = _x + _w;
2006-07-04 15:32:55 +00:00
2006-07-31 19:25:41 +00:00
if (!_pointer) {
vmin = cur_value - _half_width_units; // width units == needle travel
vmax = cur_value + _half_width_units; // or picture unit span.
text_y = _center_y;
2006-07-04 15:32:55 +00:00
2006-07-31 19:25:41 +00:00
} else if (_pointer_type == MOVING) {
vmin = _input.min();
vmax = _input.max();
2006-07-04 15:32:55 +00:00
2006-07-31 19:25:41 +00:00
} else { // FIXED
vmin = cur_value - _half_width_units; // width units == needle travel
vmax = cur_value + _half_width_units; // or picture unit span.
text_y = _center_y;
2006-07-04 15:32:55 +00:00
}
///////////////////////////////////////////////////////////////////////////////
// VERTICAL SCALE
///////////////////////////////////////////////////////////////////////////////
2006-07-04 15:32:55 +00:00
// Draw the basic markings for the scale...
if (option_vert()) { // Vertical scale
// Bottom tick bar
if (_draw_tick_bottom)
draw_line(_x, _y, right, _y);
2006-07-04 15:32:55 +00:00
// Top tick bar
if (_draw_tick_top)
draw_line(_x, top, right, top);
2006-07-04 15:32:55 +00:00
marker_xs = _x; // x start
marker_xe = right; // x extent
marker_ye = top;
2006-07-04 15:32:55 +00:00
// We do not use else in the following so that combining the
// two options produces a "caged" display with double
// carrots. The same is done for horizontal card indicators.
// begin vertical/left
//First draw capping lines and pointers
if (option_left()) { // Calculate x marker offset
if (_draw_cap_right)
draw_line(marker_xe, _y, marker_xe, marker_ye);
2006-07-04 15:32:55 +00:00
marker_xs = marker_xe - _w / 3.0;
2006-07-04 15:32:55 +00:00
// draw_line(marker_xs, _center_y, marker_xe, _center_y + _w / 6);
// draw_line(marker_xs, _center_y, marker_xe, _center_y - _w / 6);
2006-07-04 15:32:55 +00:00
// draw pointer
if (_pointer) {
if (_pointer_type == MOVING) {
if (!_zoom) {
2006-07-04 15:32:55 +00:00
//Code for Moving Type Pointer
float ycentre, ypoint, xpoint;
2006-07-31 17:36:27 +00:00
float range, right;
2006-07-04 15:32:55 +00:00
if (_input.min() >= 0.0)
ycentre = _y;
2006-07-04 15:32:55 +00:00
else if (_input.max() + _input.min() == 0.0)
ycentre = _center_y;
else if (oddtype)
2006-07-31 17:36:27 +00:00
ycentre = _y + (1.0 - _input.min()) * _h / (_input.max() - _input.min());
2006-07-04 15:32:55 +00:00
else
2006-07-31 17:36:27 +00:00
ycentre = _y + _input.min() * _h / (_input.max() - _input.min());
2006-07-04 15:32:55 +00:00
range = _h;
2006-07-31 17:36:27 +00:00
right = _x + _w;
2006-07-04 15:32:55 +00:00
if (oddtype)
ypoint = ycentre + ((cur_value - 1.0) * range / _val_span);
2006-07-04 15:32:55 +00:00
else
ypoint = ycentre + (cur_value * range / _val_span);
2006-07-04 15:32:55 +00:00
2006-07-31 17:36:27 +00:00
xpoint = right + _marker_offset;
2006-07-04 15:32:55 +00:00
draw_line(xpoint, ycentre, xpoint, ypoint);
draw_line(xpoint, ypoint, xpoint - _marker_offset, ypoint);
draw_line(xpoint - _marker_offset, ypoint, xpoint - 5.0, ypoint + 5.0);
draw_line(xpoint - _marker_offset, ypoint, xpoint - 5.0, ypoint - 5.0);
} // !_zoom
2006-07-04 15:32:55 +00:00
} else {
// default to fixed
2006-07-31 17:36:27 +00:00
draw_fixed_pointer(_marker_offset + marker_xe, text_y + _w / 6,
_marker_offset + marker_xs, text_y, _marker_offset + marker_xe,
text_y - _w / 6);
} // end pointer type
} // if pointer
} // end vertical/left
2006-07-04 15:32:55 +00:00
2006-07-04 15:32:55 +00:00
// begin vertical/right
// First draw capping lines and pointers
if (option_right()) {
if (_draw_cap_left)
draw_line(_x, _y, _x, marker_ye);
2006-07-04 15:32:55 +00:00
marker_xe = _x + _w / 3.0;
2006-07-04 15:32:55 +00:00
// Indicator carrot
// draw_line(_x, _center_y + _w / 6, marker_xe, _center_y);
// draw_line(_x, _center_y - _w / 6, marker_xe, _center_y);
2006-07-04 15:32:55 +00:00
// draw pointer
if (_pointer) {
if (_pointer_type == MOVING) {
if (!_zoom) {
// type-fixed & _zoom=1, behaviour to be defined
2006-07-04 15:32:55 +00:00
// Code for Moving Type Pointer
float ycentre, ypoint, xpoint;
float range;
if (_input.min() >= 0.0)
ycentre = _y;
2006-07-04 15:32:55 +00:00
else if (_input.max() + _input.min() == 0.0)
ycentre = _center_y;
else if (oddtype)
ycentre = _y + (1.0 - _input.min()) * _h / (_input.max() - _input.min());
2006-07-04 15:32:55 +00:00
else
ycentre = _y + _input.min() * _h / (_input.max() - _input.min());
2006-07-04 15:32:55 +00:00
range = _h;
2006-07-04 15:32:55 +00:00
if (oddtype)
ypoint = ycentre + ((cur_value - 1.0) * range / _val_span);
2006-07-04 15:32:55 +00:00
else
ypoint = ycentre + (cur_value * range / _val_span);
2006-07-04 15:32:55 +00:00
xpoint = _x - _marker_offset;
2006-07-04 15:32:55 +00:00
draw_line(xpoint, ycentre, xpoint, ypoint);
draw_line(xpoint, ypoint, xpoint + _marker_offset, ypoint);
draw_line(xpoint + _marker_offset, ypoint, xpoint + 5.0, ypoint + 5.0);
draw_line(xpoint + _marker_offset, ypoint, xpoint + 5.0, ypoint - 5.0);
2006-07-04 15:32:55 +00:00
}
} else {
// default to fixed
2006-07-31 17:36:27 +00:00
draw_fixed_pointer(-_marker_offset + _x, text_y + _w / 6,
-_marker_offset + marker_xe, text_y, -_marker_offset + _x,
text_y - _w / 6);
2006-07-04 15:32:55 +00:00
}
} // if pointer
} // end vertical/right
2006-07-04 15:32:55 +00:00
2006-07-04 15:32:55 +00:00
// At this point marker x_start and x_end values are transposed.
// To keep this from confusing things they are now swapped.
if (option_both())
marker_ye = marker_xs, marker_xs = marker_xe, marker_xe = marker_ye;
2006-07-04 15:32:55 +00:00
// Work through from bottom to top of scale. Calculating where to put
// minor and major ticks.
// draw scale or tape
if (_zoom) {
2006-07-04 15:32:55 +00:00
zoomed_scale((int)vmin, (int)vmax);
} else {
int div_ratio;
if (_minor_divs != 0.0f)
div_ratio = int(_major_divs / _minor_divs + 0.5f);
else
div_ratio = 0, _minor_divs = _major_divs; // FIXME move that into Scale/Constructor ?
float vstart = floorf(vmin / _major_divs) * _major_divs;
float min_diff = _w / 6.0; // length difference between major & minor tick
// FIXME consider oddtype
for (int i = 0; ; i++) {
float v = vstart + i * _minor_divs;
if (!_modulo)
if (v < _input.min())
continue;
else if (v > _input.max())
break;
float y = _y + (v - vmin) * factor();
if (y < _y + 0)
continue;
if (y > top - 0)
break;
if (div_ratio && i % div_ratio) { // minor div
if (option_both()) {
if (_tick_type == LINE) {
if (_tick_length == VARIABLE) {
draw_line(_x, y, marker_xs, y);
draw_line(marker_xe, y, right, y);
} else {
draw_line(_x, y, marker_xs, y);
draw_line(marker_xe, y, right, y);
}
} else { // _tick_type == CIRCLE
draw_bullet(_x, y, 3.0);
}
} else if (option_left()) {
if (_tick_type == LINE) {
if (_tick_length == VARIABLE) {
draw_line(marker_xs + min_diff, y, marker_xe, y);
} else {
draw_line(marker_xs, y, marker_xe, y);
}
} else { // _tick_type == CIRCLE
draw_bullet(marker_xs + 4, y, 3.0);
}
} else { // if (option_right())
if (_tick_type == LINE) {
if (_tick_length == VARIABLE) {
draw_line(marker_xs, y, marker_xe - min_diff, y);
} else {
draw_line(marker_xs, y, marker_xe, y);
}
} else { // _tick_type == CIRCLE
draw_bullet(marker_xe - 4, y, 3.0);
}
} // end huds both
} else { // major div
int display_value = int(v);
if (_modulo)
display_value %= _modulo;
snprintf(buf, BUFSIZE, "%d", display_value);
2006-07-04 15:32:55 +00:00
float x;
int align;
if (option_both()) {
if (_tick_type == LINE) {
2006-07-31 19:25:41 +00:00
draw_line(_x, y, marker_xs, y);
draw_line(marker_xs, y, right, y);
} else { // _tick_type == CIRCLE
draw_bullet(_x, y, 5.0);
}
x = marker_xs, align = CENTER;
} else {
if (_tick_type == LINE)
draw_line(marker_xs, y, marker_xe, y);
else // _tick_type == CIRCLE
draw_bullet(marker_xs + 4, y, 5.0);
if (option_left())
x = marker_xs, align = RIGHT|VCENTER;
else
x = marker_xe, align = LEFT|VCENTER;
}
if (!option_notext()) {
float l, r, b, t;
_hud->_text_list.align(buf, align, &x, &y, &l, &r, &b, &t);
if (b < _y || t > top)
continue;
if (_label_gap == 0.0)
draw_text(x, y, buf);
else if (b < _center_x - _label_gap && t < _center_x - _label_gap)
draw_text(x, y, buf);
else if (b > _center_x + _label_gap && t > _center_x + _label_gap)
draw_text(x, y, buf);
}
}
}
} // end of zoom
2006-07-04 15:32:55 +00:00
///////////////////////////////////////////////////////////////////////////////
// HORIZONTAL SCALE
///////////////////////////////////////////////////////////////////////////////
2006-07-04 15:32:55 +00:00
} else {
// left tick bar
if (_draw_tick_left)
draw_line(_x, _y, _x, top);
2006-07-04 15:32:55 +00:00
// right tick bar
if (_draw_tick_right)
draw_line(right, _y, right, top);
2006-07-04 15:32:55 +00:00
marker_ys = _y; // Starting point for
marker_ye = top; // tick y location calcs
marker_xe = right;
marker_xs = _x + ((cur_value - vmin) * factor());
2006-07-04 15:32:55 +00:00
if (option_top()) {
if (_draw_cap_bottom)
draw_line(_x, _y, right, _y);
2006-07-04 15:32:55 +00:00
// Tick point adjust
marker_ye = _y + _h / 2;
2006-07-04 15:32:55 +00:00
// Bottom arrow
// draw_line(_center_x, marker_ye, _center_x - _h / 4, _y);
// draw_line(_center_x, marker_ye, _center_x + _h / 4, _y);
2006-07-04 15:32:55 +00:00
// draw pointer
if (_pointer) {
if (_pointer_type == MOVING) {
if (!_zoom) {
2006-07-04 15:32:55 +00:00
//Code for Moving Type Pointer
float xcentre = _center_x;
float range = _w;
float xpoint = xcentre + (cur_value * range / _val_span);
float ypoint = _y - _marker_offset;
2006-07-04 15:32:55 +00:00
draw_line(xcentre, ypoint, xpoint, ypoint);
draw_line(xpoint, ypoint, xpoint, ypoint + _marker_offset);
draw_line(xpoint, ypoint + _marker_offset, xpoint + 5.0, ypoint + 5.0);
draw_line(xpoint, ypoint + _marker_offset, xpoint - 5.0, ypoint + 5.0);
2006-07-04 15:32:55 +00:00
}
} else {
//default to fixed
2006-07-31 17:36:27 +00:00
draw_fixed_pointer(marker_xs - _h / 4, _y, marker_xs,
marker_ye, marker_xs + _h / 4, _y);
2006-07-04 15:32:55 +00:00
}
}
} // End Horizontal scale/top
2006-07-04 15:32:55 +00:00
if (option_bottom()) {
if (_draw_cap_top)
draw_line(_x, top, right, top);
2006-07-04 15:32:55 +00:00
// Tick point adjust
marker_ys = top - _h / 2;
2006-07-04 15:32:55 +00:00
// Top arrow
// draw_line(_center_x + _h / 4, _y + _h, _center_x, marker_ys);
// draw_line(_center_x - _h / 4, _y + _h, _center_x , marker_ys);
2006-07-04 15:32:55 +00:00
// draw pointer
if (_pointer) {
if (_pointer_type == MOVING) {
if (!_zoom) {
2006-07-04 15:32:55 +00:00
//Code for Moving Type Pointer
float xcentre = _center_x;
float range = _w;
float hgt = _y + _h;
float xpoint = xcentre + (cur_value * range / _val_span);
float ypoint = hgt + _marker_offset;
2006-07-04 15:32:55 +00:00
draw_line(xcentre, ypoint, xpoint, ypoint);
draw_line(xpoint, ypoint, xpoint, ypoint - _marker_offset);
draw_line(xpoint, ypoint - _marker_offset, xpoint + 5.0, ypoint - 5.0);
draw_line(xpoint, ypoint - _marker_offset, xpoint - 5.0, ypoint - 5.0);
2006-07-04 15:32:55 +00:00
}
} else {
2006-07-31 17:36:27 +00:00
draw_fixed_pointer(marker_xs + _h / 4, top, marker_xs, marker_ys,
marker_xs - _h / 4, top);
2006-07-04 15:32:55 +00:00
}
}
} //end horizontal scale bottom
2006-07-04 15:32:55 +00:00
if (_zoom) {
2006-07-04 15:32:55 +00:00
zoomed_scale((int)vmin,(int)vmax);
} else {
int div_ratio; // FIXME abstract that out of hor/vert
if (_minor_divs != 0.0f)
div_ratio = int(_major_divs / _minor_divs + 0.5f);
else
div_ratio = 0, _minor_divs = _major_divs; // FIXME move that into Scale/Constructor ?
2006-07-04 15:32:55 +00:00
float vstart = floorf(vmin / _major_divs) * _major_divs;
float min_diff = _h / 6.0; // length difference between major & minor tick
// FIXME consider oddtype
for (int i = 0; ; i++) {
float v = vstart + i * _minor_divs;
if (!_modulo)
if (v < _input.min())
continue;
else if (v > _input.max())
break;
float x = _x + (v - vmin) * factor();
if (x < _x + 0)
continue;
if (x > right - 0)
break;
if (div_ratio && i % div_ratio) { // minor div
if (option_both()) {
if (_tick_length == VARIABLE) {
draw_line(x, _y, x, marker_ys - 4);
draw_line(x, marker_ye + 4, x, top);
} else {
draw_line(x, _y, x, marker_ys);
draw_line(x, marker_ye, x, top);
}
} else {
if (option_top()) {
// draw minor ticks
if (_tick_length == VARIABLE)
draw_line(x, marker_ys, x, marker_ye - min_diff);
else
draw_line(x, marker_ys, x, marker_ye);
} else if (_tick_length == VARIABLE) {
draw_line(x, marker_ys + 4, x, marker_ye);
} else {
draw_line(x, marker_ys, x, marker_ye);
}
}
} else { // major divs
int display_value = int(v);
if (_modulo)
display_value %= _modulo;
snprintf(buf, BUFSIZE, "%d", display_value);
float y;
int align;
if (option_both()) {
2006-07-31 19:25:41 +00:00
draw_line(x, _y, x, marker_ye);
draw_line(x, marker_ye, x, _y + _h);
y = marker_ys, align = CENTER;
} else {
draw_line(x, marker_ys, x, marker_ye);
if (option_top())
y = top, align = TOP|HCENTER;
else
y = _y, align = BOTTOM|HCENTER;
}
if (!option_notext()) {
float l, r, b, t;
_hud->_text_list.align(buf, align, &x, &y, &l, &r, &b, &t);
if (l < _x || r > right)
continue;
if (_label_gap == 0.0)
draw_text(x, y, buf);
else if (l < _center_x - _label_gap && r < _center_x - _label_gap)
draw_text(x, y, buf);
else if (l > _center_x + _label_gap && r > _center_x + _label_gap)
draw_text(x, y, buf);
}
}
} // end for
} // end zoom
} // end horizontal/vertical scale
}
2006-07-04 15:32:55 +00:00
2006-07-31 17:36:27 +00:00
void HUD::Tape::draw_fixed_pointer(float x1, float y1, float x2, float y2, float x3, float y3)
2006-07-04 15:32:55 +00:00
{
glBegin(GL_LINE_STRIP);
glVertex2f(x1, y1);
glVertex2f(x2, y2);
glVertex2f(x3, y3);
glEnd();
}
void HUD::Tape::zoomed_scale(int first, int last)
{
const int BUFSIZE = 80;
char buf[BUFSIZE];
int data[80];
float x, y, w, h, bottom;
float cur_value = _input.getFloatValue();
int a = 0;
while (first <= last) {
if ((first % (int)_major_divs) == 0) {
data[a] = first;
a++;
2006-07-04 15:32:55 +00:00
}
first++;
}
int centre = a / 2;
if (option_vert()) {
x = _x;
y = _y;
w = _x + _w;
h = _y + _h;
bottom = _h;
2006-07-04 15:32:55 +00:00
float xstart, yfirst, ycentre, ysecond;
float hgt = bottom * 20.0 / 100.0; // 60% of height should be zoomed
yfirst = _center_y - hgt;
ycentre = _center_y;
ysecond = _center_y + hgt;
2006-07-04 15:32:55 +00:00
float range = hgt * 2;
int i;
float factor = range / 10.0;
float hgt1 = bottom * 30.0 / 100.0;
int incrs = int((_val_span - _major_divs * 2.0) / _major_divs);
2006-07-04 15:32:55 +00:00
int incr = incrs / 2;
float factors = hgt1 / incr;
2006-07-31 17:36:27 +00:00
// moving type pointer
float ypoint, xpoint;
float ycent = _center_y;
float right = _x + _w;
2006-07-04 15:32:55 +00:00
if (cur_value <= data[centre + 1])
if (cur_value > data[centre]) {
ypoint = ycent + ((cur_value - data[centre]) * hgt / _major_divs);
}
if (cur_value >= data[centre - 1])
if (cur_value <= data[centre]) {
ypoint = ycent - ((data[centre] - cur_value) * hgt / _major_divs);
}
if (cur_value < data[centre - 1])
if (cur_value >= _input.min()) {
float diff = _input.min() - data[centre - 1];
float diff1 = cur_value - data[centre - 1];
float val = (diff1 * hgt1) / diff;
ypoint = ycent - hgt - val;
}
if (cur_value > data[centre + 1])
if (cur_value <= _input.max()) {
float diff = _input.max() - data[centre + 1];
float diff1 = cur_value - data[centre + 1];
float val = (diff1 * hgt1) / diff;
ypoint = ycent + hgt + val;
}
if (option_left()) {
xstart = w;
draw_line(xstart, ycentre, xstart - 5.0, ycentre); //centre tick
snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes not sense at all
2006-07-04 15:32:55 +00:00
if (!option_notext())
draw_text(x, ycentre, buf, 0);
for (i = 1; i < 5; i++) {
yfirst += factor;
ycentre += factor;
draw_bullet(xstart - 2.5, yfirst, 3.0);
draw_bullet(xstart - 2.5, ycentre, 3.0);
2006-07-04 15:32:55 +00:00
}
yfirst = _center_y - hgt;
2006-07-04 15:32:55 +00:00
for (i = 0; i <= incr; i++) {
draw_line(xstart, yfirst, xstart - 5.0, yfirst);
draw_line(xstart, ysecond, xstart - 5.0, ysecond);
snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
2006-07-04 15:32:55 +00:00
if (!option_notext())
draw_text(x, yfirst, buf, 0);
snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor())); // was data_scaling() ... makes no sense at all
2006-07-04 15:32:55 +00:00
if (!option_notext())
draw_text(x, ysecond, buf, 0);
yfirst -= factors;
ysecond += factors;
}
//to draw moving type pointer for left option
//begin
2006-07-31 17:36:27 +00:00
xpoint = right + 10.0;
2006-07-04 15:32:55 +00:00
if (_pointer_type == MOVING) {
2006-07-04 15:32:55 +00:00
draw_line(xpoint, ycent, xpoint, ypoint);
draw_line(xpoint, ypoint, xpoint - 10.0, ypoint);
draw_line(xpoint - 10.0, ypoint, xpoint - 5.0, ypoint + 5.0);
draw_line(xpoint - 10.0, ypoint, xpoint - 5.0, ypoint - 5.0);
}
//end
} else {
//option_right
xstart = (x + w) / 2;
draw_line(xstart, ycentre, xstart + 5.0, ycentre); //centre tick
snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes no sense at all
2006-07-04 15:32:55 +00:00
if (!option_notext())
draw_text(w, ycentre, buf, 0);
for (i = 1; i < 5; i++) {
yfirst += factor;
ycentre += factor;
draw_bullet(xstart + 2.5, yfirst, 3.0);
draw_bullet(xstart + 2.5, ycentre, 3.0);
2006-07-04 15:32:55 +00:00
}
yfirst = _center_y - hgt;
2006-07-04 15:32:55 +00:00
for (i = 0; i <= incr; i++) {
draw_line(xstart, yfirst, xstart + 5.0, yfirst);
draw_line(xstart, ysecond, xstart + 5.0, ysecond);
snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
2006-07-04 15:32:55 +00:00
if (!option_notext())
draw_text(w, yfirst, buf, 0);
snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor()));
2006-07-04 15:32:55 +00:00
if (!option_notext())
draw_text(w, ysecond, buf, 0);
yfirst -= factors;
ysecond += factors;
}
// to draw moving type pointer for right option
//begin
xpoint = _x;
2006-07-04 15:32:55 +00:00
if (_pointer_type == MOVING) {
2006-07-04 15:32:55 +00:00
draw_line(xpoint, ycent, xpoint, ypoint);
draw_line(xpoint, ypoint, xpoint + 10.0, ypoint);
draw_line(xpoint + 10.0, ypoint, xpoint + 5.0, ypoint + 5.0);
draw_line(xpoint + 10.0, ypoint, xpoint + 5.0, ypoint - 5.0);
}
//end
}//end option_right /left
//end of vertical scale
} else {
//horizontal scale
x = _x;
y = _y;
w = _x + _w;
h = _y + _h;
bottom = _w;
2006-07-04 15:32:55 +00:00
float ystart, xfirst, xcentre, xsecond;
float hgt = bottom * 20.0 / 100.0; // 60% of height should be zoomed
xfirst = _center_x - hgt;
xcentre = _center_x;
xsecond = _center_x + hgt;
2006-07-04 15:32:55 +00:00
float range = hgt * 2;
int i;
float factor = range / 10.0;
float hgt1 = bottom * 30.0 / 100.0;
int incrs = int((_val_span - _major_divs * 2.0) / _major_divs);
2006-07-04 15:32:55 +00:00
int incr = incrs / 2;
float factors = hgt1 / incr;
2006-07-31 19:25:41 +00:00
// Code for Moving Type Pointer
2006-07-31 19:32:02 +00:00
float xpoint, ypoint;
2006-07-31 19:25:41 +00:00
float xcent = _center_x;
2006-07-04 15:32:55 +00:00
2006-07-31 19:25:41 +00:00
if (cur_value <= data[centre + 1]) {
2006-07-04 15:32:55 +00:00
if (cur_value > data[centre]) {
xpoint = xcent + ((cur_value - data[centre]) * hgt / _major_divs);
}
2006-07-31 19:25:41 +00:00
}
2006-07-04 15:32:55 +00:00
2006-07-31 19:25:41 +00:00
if (cur_value >= data[centre - 1]) {
2006-07-04 15:32:55 +00:00
if (cur_value <= data[centre]) {
xpoint = xcent - ((data[centre] - cur_value) * hgt / _major_divs);
}
2006-07-31 19:25:41 +00:00
}
2006-07-04 15:32:55 +00:00
2006-07-31 19:25:41 +00:00
if (cur_value < data[centre - 1]) {
2006-07-04 15:32:55 +00:00
if (cur_value >= _input.min()) {
float diff = _input.min() - data[centre - 1];
float diff1 = cur_value - data[centre - 1];
float val = (diff1 * hgt1) / diff;
xpoint = xcent - hgt - val;
}
2006-07-31 19:25:41 +00:00
}
2006-07-04 15:32:55 +00:00
2006-07-31 19:25:41 +00:00
if (cur_value > data[centre + 1]) {
2006-07-04 15:32:55 +00:00
if (cur_value <= _input.max()) {
float diff = _input.max() - data[centre + 1];
float diff1 = cur_value - data[centre + 1];
float val = (diff1 * hgt1) / diff;
xpoint = xcent + hgt + val;
}
2006-07-31 19:25:41 +00:00
}
// end moving pointer
2006-07-04 15:32:55 +00:00
if (option_top()) {
ystart = h;
draw_line(xcentre, ystart, xcentre, ystart - 5.0); //centre tick
snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes no sense at all
2006-07-04 15:32:55 +00:00
if (!option_notext())
draw_text(xcentre - 10.0, y, buf, 0);
for (i = 1; i < 5; i++) {
xfirst += factor;
xcentre += factor;
draw_bullet(xfirst, ystart - 2.5, 3.0);
draw_bullet(xcentre, ystart - 2.5, 3.0);
2006-07-04 15:32:55 +00:00
}
xfirst = _center_x - hgt;
2006-07-04 15:32:55 +00:00
for (i = 0; i <= incr; i++) {
draw_line(xfirst, ystart, xfirst, ystart - 5.0);
draw_line(xsecond, ystart, xsecond, ystart - 5.0);
snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
2006-07-04 15:32:55 +00:00
if (!option_notext())
draw_text(xfirst - 10.0, y, buf, 0);
snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor())); // was data_scaling() ... makes no sense at all
2006-07-04 15:32:55 +00:00
if (!option_notext())
draw_text(xsecond - 10.0, y, buf, 0);
xfirst -= factors;
xsecond += factors;
}
2006-07-31 19:25:41 +00:00
// moving pointer for top option
ypoint = _y + _h + 10.0;
2006-07-04 15:32:55 +00:00
if (_pointer_type == MOVING) {
2006-07-04 15:32:55 +00:00
draw_line(xcent, ypoint, xpoint, ypoint);
draw_line(xpoint, ypoint, xpoint, ypoint - 10.0);
draw_line(xpoint, ypoint - 10.0, xpoint + 5.0, ypoint - 5.0);
draw_line(xpoint, ypoint - 10.0, xpoint - 5.0, ypoint - 5.0);
}
//end of top option
} else {
//else option_bottom
ystart = (y + h) / 2;
//draw_line(xstart, yfirst, xstart - 5.0, yfirst);
draw_line(xcentre, ystart, xcentre, ystart + 5.0); //centre tick
snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes no sense at all
2006-07-04 15:32:55 +00:00
if (!option_notext())
draw_text(xcentre - 10.0, h, buf, 0);
for (i = 1; i < 5; i++) {
xfirst += factor;
xcentre += factor;
draw_bullet(xfirst, ystart + 2.5, 3.0);
draw_bullet(xcentre, ystart + 2.5, 3.0);
2006-07-04 15:32:55 +00:00
}
xfirst = _center_x - hgt;
2006-07-04 15:32:55 +00:00
for (i = 0; i <= incr; i++) {
draw_line(xfirst, ystart, xfirst, ystart + 5.0);
draw_line(xsecond, ystart, xsecond, ystart + 5.0);
snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
2006-07-04 15:32:55 +00:00
if (!option_notext())
draw_text(xfirst - 10.0, h, buf, 0);
snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor())); // was data_scaling() ... makes no sense at all
2006-07-04 15:32:55 +00:00
if (!option_notext())
draw_text(xsecond - 10.0, h, buf, 0);
xfirst -= factors;
xsecond += factors;
}
2006-07-31 19:25:41 +00:00
// movimg pointer for bottom option
ypoint = _y - 10.0;
if (_pointer_type == MOVING) {
2006-07-04 15:32:55 +00:00
draw_line(xcent, ypoint, xpoint, ypoint);
draw_line(xpoint, ypoint, xpoint, ypoint + 10.0);
draw_line(xpoint, ypoint + 10.0, xpoint + 5.0, ypoint + 5.0);
draw_line(xpoint, ypoint + 10.0, xpoint - 5.0, ypoint + 5.0);
}
}//end hud_top or hud_bottom
} //end of horizontal/vertical scales
}//end draw