12 #include <simgear/constants.h>
13 #include <simgear/math/fg_random.h>
14 #include <simgear/math/polar3d.hxx>
16 #include <Aircraft/aircraft.hxx>
17 #include <Scenery/scenery.hxx>
18 #include <Time/fg_timer.hxx>
25 //====================== Top of HudLadder Class =======================
26 HudLadder :: HudLadder( int x,
39 dual_instr_item( x, y, width, height,
44 width_units ( (int)(span_units) ),
45 div_units ( (int)(major_div < 0? -major_div: major_div) ),
46 minor_div ( (int)(minor_div) ),
47 label_pos ( lbl_pos ),
48 scr_hole ( screen_hole ),
49 vmax ( span_units/2 ),
55 factor = (float)get_span() / (float) width_units;
59 HudLadder :: ~HudLadder()
64 HudLadder( const HudLadder & image ) :
65 dual_instr_item( (dual_instr_item &) image),
66 width_units ( image.width_units ),
67 div_units ( image.div_units ),
68 label_pos ( image.label_pos ),
69 scr_hole ( image.scr_hole ),
72 factor ( image.factor )
75 HudLadder & HudLadder :: operator = ( const HudLadder & rhs )
77 if( !(this == &rhs)) {
78 (dual_instr_item &)(*this) = (dual_instr_item &)rhs;
79 width_units = rhs.width_units;
80 div_units = rhs.div_units;
81 label_pos = rhs.label_pos;
82 scr_hole = rhs.scr_hole;
91 // Draws a climb ladder in the center of the HUD
94 void HudLadder :: draw( void )
96 POINT centroid = get_centroid();
98 float roll_value = current_ch2();
101 glTranslatef( centroid.x, centroid.y, 0);
102 // Alex's panel patch
103 // glScalef( current_options.get_fov()/55.0, 1.0, 1.0 );
104 glRotatef(roll_value * RAD_TO_DEG, 0.0, 0.0, 1.0);
106 // Draw the target spot.
107 #define CENTER_DIAMOND_SIZE 6.0f
109 glBegin(GL_LINE_LOOP);
110 glVertex2f( CENTER_DIAMOND_SIZE, 0.0);
111 glVertex2f( 0.0, CENTER_DIAMOND_SIZE);
112 glVertex2f( -CENTER_DIAMOND_SIZE, 0.0);
113 glVertex2f( 0.0, -CENTER_DIAMOND_SIZE);
116 if( minimal || ! div_units ) {
125 float pitch_value = current_ch1() * RAD_TO_DEG;
126 vmin = pitch_value - (float)width_units * 0.5f;
127 vmax = pitch_value + (float)width_units * 0.5f;
129 RECT box = get_location();
131 float half_span = box.right * 0.5f ;
140 float text_offset = 4.0f ;
141 float zero_offset = 10.0f ;
143 fntFont *font = HUDtext->getFont();
144 float pointsize = HUDtext->getPointSize();
145 float italic = HUDtext->getSlant();
147 TextList.setFont( HUDtext );
150 StippleLineList.erase();
152 int last = FloatToInt(vmax)+1;
153 int i = FloatToInt(vmin);
157 for( ; i<last ; i++ ) {
159 y = (((float)(i - pitch_value) * factor) + .5f);
160 if( !(i % div_units )) { // At integral multiple of div
162 sprintf( TextLadder, "%d", i );
163 font->getBBox ( TextLadder, pointsize, italic,
164 &left, &right, &bot, &top ) ;
166 label_length = right - left;
167 label_length += text_offset;
168 label_height = (top - bot) * 0.5f;
173 // Make zero point wider on left
175 x_ini -= zero_offset;
176 // Zero or above draw solid lines
177 Line(x_ini, y, x_end, y);
179 // Below zero draw dashed lines.
180 StippleLine(x_ini, y, x_end, y);
183 // Calculate the position of the left text and write it.
184 Text( x_ini-label_length, y-label_height, TextLadder );
185 Text( x_end+text_offset, y-label_height, TextLadder );
188 } else { // scr_hole != 0
189 // Draw ladder with space in the middle of the lines
192 float hole = (float)((scr_hole)*0.5f);
194 x_end = -half_span + hole;
195 x_ini2 = half_span - hole;
197 for( ; i<last ; i++ ) {
199 y = (((float)(i - pitch_value) * factor) + .5);
200 if( !(i % div_units )) { // At integral multiple of div
202 sprintf( TextLadder, "%d", i );
203 font->getBBox ( TextLadder, pointsize, italic,
204 &left, &right, &bot, &top ) ;
205 label_length = right - left;
206 label_length += text_offset;
207 label_height = (top - bot) * 0.5f;
209 // Start by calculating the points and drawing the
215 // Make zero point wider on left
217 x_ini -= zero_offset;
218 x_end2 += zero_offset;
220 // Zero or above draw solid lines
221 Line(x_ini, y, x_end, y);
222 Line(x_ini2, y, x_end2, y);
224 // Below zero draw dashed lines.
225 StippleLine(x_ini, y, x_end, y);
226 StippleLine(x_ini2, y, x_end2, y);
228 // Calculate the location of the left side label using
229 Text( x_ini-label_length, y-label_height, TextLadder );
230 // Calculate the location and draw the right side label
231 Text( x_end2+text_offset, y-label_height, TextLadder );
239 glEnable(GL_LINE_STIPPLE);
241 glLineStipple( 1, current_options.get_panel_status() ? 0x0F0F : 0x00FF );
243 glLineStipple( 1, 0x00FF );
246 StippleLineList.draw( );
247 glDisable(GL_LINE_STIPPLE);
249 // } // if(div_units)