1
0
Fork 0

- fix more cases of scale tick aliasing to get smooth scale movements

- remove trailing spaces, fix indentation, unify coding style, ...
This commit is contained in:
mfranz 2006-06-12 23:27:55 +00:00
parent 365546444c
commit b674037a3c
2 changed files with 948 additions and 944 deletions

File diff suppressed because it is too large Load diff

View file

@ -3,55 +3,55 @@
#ifdef USE_HUD_TextList #ifdef USE_HUD_TextList
#define textString( x , y, text, digit ) TextString( text, x , y,digit ) //suma #define textString( x , y, text, digit ) TextString( text, x , y,digit )
#else #else
#define textString( x , y, text, digit ) puDrawString ( guiFnt, text, x, y ); //suma #define textString( x , y, text, digit ) puDrawString ( guiFnt, text, x, y )
#endif #endif
//============== Top of gauge_instr class member definitions ============== //============== Top of gauge_instr class member definitions ==============
gauge_instr :: gauge_instr::gauge_instr(
gauge_instr( int x, int x,
int y, int y,
UINT width, UINT width,
UINT height, UINT height,
FLTFNPTR load_fn, FLTFNPTR load_fn,
UINT options, UINT options,
float disp_scale, float disp_scale,
float maxValue, float maxValue,
float minValue, float minValue,
UINT major_divs, UINT major_divs,
UINT minor_divs, UINT minor_divs,
int dp_showing, int dp_showing,
UINT modulus, UINT modulus,
bool working) : bool working) :
instr_scale( x, y, width, height, instr_scale( x, y, width, height,
load_fn, options, load_fn, options,
(maxValue - minValue), // Always shows span? (maxValue - minValue), // Always shows span?
maxValue, minValue, maxValue, minValue,
disp_scale, disp_scale,
major_divs, minor_divs, major_divs, minor_divs,
modulus, dp_showing, modulus, dp_showing,
working) working)
{ {
// UINT options = get_options(); // UINT options = get_options();
// huds_vert = options & HUDS_VERT; // huds_vert = options & HUDS_VERT;
// huds_left = options & HUDS_LEFT; // huds_left = options & HUDS_LEFT;
// huds_right = options & HUDS_RIGHT; // huds_right = options & HUDS_RIGHT;
// huds_both = (options & HUDS_BOTH) == HUDS_BOTH; // huds_both = (options & HUDS_BOTH) == HUDS_BOTH;
// huds_noticks = options & HUDS_NOTICKS; // huds_noticks = options & HUDS_NOTICKS;
// huds_notext = options & HUDS_NOTEXT; // huds_notext = options & HUDS_NOTEXT;
// huds_top = options & HUDS_TOP; // huds_top = options & HUDS_TOP;
// huds_bottom = options & HUDS_BOTTOM; // huds_bottom = options & HUDS_BOTTOM;
} }
gauge_instr ::
~gauge_instr() gauge_instr::~gauge_instr()
{ {
} }
gauge_instr ::
gauge_instr( const gauge_instr & image): gauge_instr::gauge_instr( const gauge_instr & image) :
instr_scale( (instr_scale &) image) instr_scale( (instr_scale &) image)
{ {
// UINT options = get_options(); // UINT options = get_options();
@ -65,25 +65,26 @@ gauge_instr( const gauge_instr & image):
// huds_bottom = options & HUDS_BOTTOM; // huds_bottom = options & HUDS_BOTTOM;
} }
gauge_instr & gauge_instr ::
operator = (const gauge_instr & rhs ) gauge_instr & gauge_instr::operator=(const gauge_instr & rhs)
{ {
if( !(this == &rhs)) { if (!(this == &rhs)) {
instr_scale::operator = (rhs); instr_scale::operator = (rhs);
} }
return *this; return *this;
} }
// As implemented, draw only correctly draws a horizontal or vertical // As implemented, draw only correctly draws a horizontal or vertical
// scale. It should contain a variation that permits clock type displays. // scale. It should contain a variation that permits clock type displays.
// Now is supports "tickless" displays such as control surface indicators. // Now is supports "tickless" displays such as control surface indicators.
// This routine should be worked over before using. Current value would be // This routine should be worked over before using. Current value would be
// fetched and not used if not commented out. Clearly that is intollerable. // fetched and not used if not commented out. Clearly that is intollerable.
void gauge_instr :: draw (void) void gauge_instr::draw (void)
{ {
int marker_xs, marker_xe; float marker_xs, marker_xe;
int marker_ys, marker_ye; float marker_ys, marker_ye;
int text_x, text_y; int text_x, text_y;
int width, height, bottom_4; int width, height, bottom_4;
int lenstr; int lenstr;
@ -100,280 +101,281 @@ void gauge_instr :: draw (void)
width = scrn_rect.left + scrn_rect.right; width = scrn_rect.left + scrn_rect.right;
height = scrn_rect.top + scrn_rect.bottom, height = scrn_rect.top + scrn_rect.bottom,
bottom_4 = scrn_rect.bottom / 4; bottom_4 = scrn_rect.bottom / 4;
// Draw the basic markings for the scale... // Draw the basic markings for the scale...
if( huds_vert(options) ) { // Vertical scale if ( huds_vert(options) ) { // Vertical scale
drawOneLine( scrn_rect.left, // Bottom tick bar drawOneLine( scrn_rect.left, // Bottom tick bar
scrn_rect.top, scrn_rect.top,
width, width,
scrn_rect.top); scrn_rect.top);
drawOneLine( scrn_rect.left, // Top tick bar drawOneLine( scrn_rect.left, // Top tick bar
height, height,
width, width,
height ); height );
marker_xs = scrn_rect.left; marker_xs = scrn_rect.left;
marker_xe = width; marker_xe = width;
if( huds_left(options) ) { // Read left, so line down right side if ( huds_left(options) ) { // Read left, so line down right side
drawOneLine( width, drawOneLine( width,
scrn_rect.top, scrn_rect.top,
width, width,
height); height);
marker_xs = marker_xe - scrn_rect.right / 3; // Adjust tick xs
}
if( huds_right(options) ) { // Read right, so down left sides
drawOneLine( scrn_rect.left,
scrn_rect.top,
scrn_rect.left,
height);
marker_xe = scrn_rect.left + scrn_rect.right / 3; // Adjust tick xe
}
// At this point marker x_start and x_end values are transposed. marker_xs = marker_xe - scrn_rect.right / 3.0; // Adjust tick xs
// To keep this from confusing things they are now interchanged. }
if( huds_both(options) ) {
marker_ye = marker_xs;
marker_xs = marker_xe;
marker_xe = marker_ye;
}
// Work through from bottom to top of scale. Calculating where to put if ( huds_right(options) ) { // Read right, so down left sides
// minor and major ticks. drawOneLine( scrn_rect.left,
scrn_rect.top,
scrn_rect.left,
height);
if( !huds_noticks(options)) { // If not no ticks...:) marker_xe = scrn_rect.left + scrn_rect.right / 3.0; // Adjust tick xe
// Calculate x marker offsets }
int last = (int)vmax + 1; //FloatToInt(vmax)+1;
i = (int)vmin; //FloatToInt(vmin);
for(; i <last ; i++ ) {
// for( i = (int)vmin; i <= (int)vmax; i++ ) {
// Calculate the location of this tick // At this point marker x_start and x_end values are transposed.
marker_ys = scrn_rect.top + FloatToInt((i - vmin) * factor()/* +.5f*/); // To keep this from confusing things they are now interchanged.
if ( huds_both(options) ) {
marker_ye = marker_xs;
marker_xs = marker_xe;
marker_xe = marker_ye;
}
// We compute marker_ys even though we don't know if we will use // Work through from bottom to top of scale. Calculating where to put
// either major or minor divisions. Simpler. // minor and major ticks.
if( div_min()) { // Minor tick marks if ( !huds_noticks(options)) { // If not no ticks...:)
if( !(i%(int)div_min()) ) { // Calculate x marker offsets
if( huds_left(options) && huds_right(options) ) { int last = (int)vmax + 1; //FloatToInt(vmax)+1;
drawOneLine( scrn_rect.left, marker_ys, i = (int)vmin; //FloatToInt(vmin);
marker_xs - 3, marker_ys ); for (; i < last; i++) {
drawOneLine( marker_xe + 3, marker_ys, // for ( i = (int)vmin; i <= (int)vmax; i++ ) {
width, marker_ys );
}
else {
if( huds_left(options) ) {
drawOneLine( marker_xs + 3, marker_ys, marker_xe, marker_ys );
}
else {
drawOneLine( marker_xs, marker_ys, marker_xe - 3, marker_ys );
}
}
}
}
// Now we work on the major divisions. Since these are also labeled // Calculate the location of this tick
// and no labels are drawn otherwise, we label inside this if marker_ys = scrn_rect.top + (i - vmin) * factor()/* +.5f*/;
// statement.
if( div_max()) { // Major tick mark // We compute marker_ys even though we don't know if we will use
if( !(i%(int)div_max()) ) { // either major or minor divisions. Simpler.
if( huds_left(options) && huds_right(options) ) {
drawOneLine( scrn_rect.left, marker_ys,
marker_xs, marker_ys );
drawOneLine( marker_xe, marker_ys,
width, marker_ys );
}
else {
drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
}
if( !huds_notext(options) ) { if ( div_min()) { // Minor tick marks
disp_val = i; if ( !(i%(int)div_min()) ) {
sprintf( TextScale, "%d", if ( huds_left(options) && huds_right(options) ) {
FloatToInt(disp_val * data_scaling()/*+.5*/ )); drawOneLine( scrn_rect.left, marker_ys,
marker_xs - 3, marker_ys );
drawOneLine( marker_xe + 3, marker_ys,
width, marker_ys );
}
else {
if ( huds_left(options) ) {
drawOneLine( marker_xs + 3, marker_ys, marker_xe, marker_ys );
}
else {
drawOneLine( marker_xs, marker_ys, marker_xe - 3, marker_ys );
}
}
}
}
lenstr = getStringWidth( TextScale ); // Now we work on the major divisions. Since these are also labeled
// and no labels are drawn otherwise, we label inside this if
if( huds_left(options) && huds_right(options) ) { // statement.
text_x = mid_scr.x - lenstr/2 ;
}
else {
if( huds_left(options) ) {
text_x = marker_xs - lenstr;
}
else {
text_x = marker_xe - lenstr;
}
}
// Now we know where to put the text.
text_y = marker_ys;
textString( text_x, text_y, TextScale, 0 ); //suma
}
}
} //
} //
} //
// Now that the scale is drawn, we draw in the pointer(s). Since labels
// have been drawn, text_x and text_y may be recycled. This is used
// with the marker start stops to produce a pointer for each side reading
text_y = scrn_rect.top + FloatToInt((cur_value - vmin) * factor() /*+.5f*/); if ( div_max()) { // Major tick mark
// text_x = marker_xs - scrn_rect.left; if ( !(i%(int)div_max()) ) {
if ( huds_left(options) && huds_right(options) ) {
drawOneLine( scrn_rect.left, marker_ys,
marker_xs, marker_ys );
drawOneLine( marker_xe, marker_ys,
width, marker_ys );
}
else {
drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
}
if( huds_right(options) ) { if ( !huds_notext(options) ) {
glBegin(GL_LINE_STRIP); disp_val = i;
glVertex2f( scrn_rect.left, text_y + 5); sprintf( TextScale, "%d",
glVertex2f( marker_xe, text_y); FloatToInt(disp_val * data_scaling()/*+.5*/ ));
glVertex2f( scrn_rect.left, text_y - 5);
glEnd();
}
if( huds_left(options) ) {
glBegin(GL_LINE_STRIP);
glVertex2f( width, text_y + 5);
glVertex2f( marker_xs, text_y);
glVertex2f( width, text_y - 5);
glEnd();
}
} // End if VERTICAL SCALE TYPE
else { // Horizontal scale by default
drawOneLine( scrn_rect.left, // left tick bar
scrn_rect.top,
scrn_rect.left,
height);
drawOneLine( width, // right tick bar lenstr = getStringWidth( TextScale );
scrn_rect.top,
width,
height );
marker_ys = scrn_rect.top; // Starting point for if ( huds_left(options) && huds_right(options) ) {
marker_ye = height; // tick y location calcs text_x = mid_scr.x - lenstr/2 ;
marker_xs = scrn_rect.left + FloatToInt((cur_value - vmin) * factor() /*+ .5f*/); }
else {
if ( huds_left(options) ) {
text_x = FloatToInt(marker_xs - lenstr);
}
else {
text_x = FloatToInt(marker_xe - lenstr);
}
}
// Now we know where to put the text.
text_y = FloatToInt(marker_ys);
textString( text_x, text_y, TextScale, 0 );
}
}
} //
} //
} //
// Now that the scale is drawn, we draw in the pointer(s). Since labels
// have been drawn, text_x and text_y may be recycled. This is used
// with the marker start stops to produce a pointer for each side reading
if( huds_top(options) ) { text_y = scrn_rect.top + FloatToInt((cur_value - vmin) * factor() /*+.5f*/);
drawOneLine( scrn_rect.left, // text_x = marker_xs - scrn_rect.left;
scrn_rect.top,
width,
scrn_rect.top); // Bottom box line
marker_ye = scrn_rect.top + scrn_rect.bottom / 2; // Tick point adjust
// Bottom arrow
glBegin(GL_LINE_STRIP);
glVertex2f( marker_xs - bottom_4, scrn_rect.top);
glVertex2f( marker_xs, marker_ye);
glVertex2f( marker_xs + bottom_4, scrn_rect.top);
glEnd();
}
if( huds_bottom(options) ) {
// Top box line
drawOneLine( scrn_rect.left, height, width, height);
// Tick point adjust
marker_ys = height - scrn_rect.bottom / 2;
// Top arrow if ( huds_right(options) ) {
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
glVertex2f( marker_xs + bottom_4, height); glVertex2f( scrn_rect.left, text_y + 5);
glVertex2f( marker_xs, marker_ys ); glVertex2f( FloatToInt(marker_xe), text_y);
glVertex2f( marker_xs - bottom_4, height); glVertex2f( scrn_rect.left, text_y - 5);
glEnd(); glEnd();
} }
if ( huds_left(options) ) {
glBegin(GL_LINE_STRIP);
glVertex2f( width, text_y + 5);
glVertex2f( FloatToInt(marker_xs), text_y);
glVertex2f( width, text_y - 5);
glEnd();
}
// End if VERTICAL SCALE TYPE
} else { // Horizontal scale by default
int last = (int)vmax + 1; //FloatToInt(vmax)+1; drawOneLine( scrn_rect.left, // left tick bar
i = (int)vmin; //FloatToInt(vmin); scrn_rect.top,
for( ; i <last ; i++ ) { scrn_rect.left,
condition = true; height);
if( !modulo()) {
if( i < min_val()) {
condition = false;
}
}
if( condition ) {
marker_xs = scrn_rect.left + FloatToInt((i - vmin) * factor()/* +.5f*/);
// marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5f);
if( div_min()){
if( !(i%(int)div_min()) ) {
// draw in ticks only if they aren't too close to the edge.
if((( marker_xs + 5) > scrn_rect.left ) ||
(( marker_xs - 5 )< (width))){
if( huds_both(options) ) { drawOneLine( width, // right tick bar
drawOneLine( marker_xs, scrn_rect.top, scrn_rect.top,
marker_xs, marker_ys - 4); width,
drawOneLine( marker_xs, marker_ye + 4, height );
marker_xs, height);
}
else {
if( huds_top(options) ) {
drawOneLine( marker_xs, marker_ys,
marker_xs, marker_ye - 4);
}
else {
drawOneLine( marker_xs, marker_ys + 4,
marker_xs, marker_ye);
}
}
}
}
}
if( div_max()) {
if( !(i%(int)div_max()) ) {
if(modulo()) {
if( disp_val < 0) {
while( disp_val < 0 ) {
disp_val += modulo();
}
}
disp_val = i % (int)modulo();
} else {
disp_val = i;
}
sprintf( TextScale, "%d",
FloatToInt(disp_val * data_scaling()/* +.5*/ ));
lenstr = getStringWidth( TextScale);
// Draw major ticks and text only if far enough from the edge.
if(( (marker_xs - 10)> scrn_rect.left ) &&
( (marker_xs + 10) < width )){
if( huds_both(options) ) {
drawOneLine( marker_xs, scrn_rect.top,
marker_xs, marker_ys);
drawOneLine( marker_xs, marker_ye,
marker_xs, height);
if( !huds_notext(options) ) { marker_ys = scrn_rect.top; // Starting point for
textString ( marker_xs - lenstr, marker_ys + 4, marker_ye = height; // tick y location calcs
TextScale ,0); //suma marker_xs = scrn_rect.left + (cur_value - vmin) * factor() /*+ .5f*/;
}
} if ( huds_top(options) ) {
else { drawOneLine( scrn_rect.left,
drawOneLine( marker_xs, marker_ys, scrn_rect.top,
marker_xs, marker_ye ); width,
scrn_rect.top); // Bottom box line
if( !huds_notext(options) ) {
if( huds_top(options) ) { marker_ye = scrn_rect.top + scrn_rect.bottom / 2.0; // Tick point adjust
textString ( marker_xs - lenstr, // Bottom arrow
height - 10, glBegin(GL_LINE_STRIP);
TextScale, 0 ); //suma glVertex2f( marker_xs - bottom_4, scrn_rect.top);
} glVertex2f( marker_xs, marker_ye);
else { glVertex2f( marker_xs + bottom_4, scrn_rect.top);
textString( marker_xs - lenstr, scrn_rect.top, glEnd();
TextScale, 0 ); //suma }
} if ( huds_bottom(options) ) {
} // Top box line
} drawOneLine( scrn_rect.left, height, width, height);
} // Tick point adjust
} marker_ys = height - scrn_rect.bottom / 2.0;
}
} // Top arrow
} glBegin(GL_LINE_STRIP);
glVertex2f( marker_xs + bottom_4, height);
glVertex2f( marker_xs, marker_ys );
glVertex2f( marker_xs - bottom_4, height);
glEnd();
}
int last = (int)vmax + 1; //FloatToInt(vmax)+1;
i = (int)vmin; //FloatToInt(vmin);
for ( ; i <last ; i++ ) {
condition = true;
if ( !modulo()) {
if ( i < min_val()) {
condition = false;
}
}
if ( condition ) {
marker_xs = scrn_rect.left + (i - vmin) * factor()/* +.5f*/;
// marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5f);
if ( div_min()){
if ( !(i%(int)div_min()) ) {
// draw in ticks only if they aren't too close to the edge.
if ((( marker_xs + 5) > scrn_rect.left ) ||
(( marker_xs - 5 )< (width))){
if ( huds_both(options) ) {
drawOneLine( marker_xs, scrn_rect.top,
marker_xs, marker_ys - 4);
drawOneLine( marker_xs, marker_ye + 4,
marker_xs, height);
}
else {
if ( huds_top(options) ) {
drawOneLine( marker_xs, marker_ys,
marker_xs, marker_ye - 4);
}
else {
drawOneLine( marker_xs, marker_ys + 4,
marker_xs, marker_ye);
}
}
}
}
}
if ( div_max()) {
if ( !(i%(int)div_max()) ) {
if (modulo()) {
if ( disp_val < 0) {
while( disp_val < 0 ) {
disp_val += modulo();
}
}
disp_val = i % (int)modulo();
} else {
disp_val = i;
}
sprintf( TextScale, "%d",
FloatToInt(disp_val * data_scaling()/* +.5*/ ));
lenstr = getStringWidth( TextScale);
// Draw major ticks and text only if far enough from the edge.
if (( (marker_xs - 10)> scrn_rect.left ) &&
( (marker_xs + 10) < width )){
if ( huds_both(options) ) {
drawOneLine( marker_xs, scrn_rect.top,
marker_xs, marker_ys);
drawOneLine( marker_xs, marker_ye,
marker_xs, height);
if ( !huds_notext(options) ) {
textString ( marker_xs - lenstr, marker_ys + 4,
TextScale ,0);
}
}
else {
drawOneLine( marker_xs, marker_ys,
marker_xs, marker_ye );
if ( !huds_notext(options) ) {
if ( huds_top(options) ) {
textString ( marker_xs - lenstr,
height - 10,
TextScale, 0 );
}
else {
textString( marker_xs - lenstr, scrn_rect.top,
TextScale, 0 );
}
}
}
}
}
}
}
}
} }
} }