]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_ladr.cxx
2a62b4d500e672e30423cde9a0372a18b1f236f9
[flightgear.git] / src / Cockpit / hud_ladr.cxx
1
2 #include "hud.hxx"
3 #include "panel.hxx"
4
5 #define DO_PANEL_HACK
6
7 //====================== Top of HudLadder Class =======================
8 HudLadder ::   HudLadder(  int       x,
9                int       y,
10                UINT      width,
11                UINT      height,
12                UINT      mini,
13                FLTFNPTR  ptch_source,
14                FLTFNPTR  roll_source,
15                float    span_units,
16                float    major_div,
17                float    minor_div,
18                UINT      screen_hole,
19                UINT      lbl_pos,
20                bool      working) :
21    dual_instr_item( x, y, width, height,
22                     ptch_source,
23                     roll_source,
24                     working,
25                     HUDS_RIGHT),
26                     width_units    ( (int)(span_units)   ),
27                     div_units      ( (int)(major_div < 0? -major_div: major_div) ),
28                     minor_div      ( (int)(minor_div)    ),
29                     label_pos      ( lbl_pos      ),
30                     scr_hole       ( screen_hole  ),
31                     vmax           ( span_units/2 ),
32                     vmin           ( -vmax        )
33    {
34        if( !width_units ) {
35            width_units = 45;
36        }
37        factor = (float)get_span() / (float) width_units;
38        minimal = mini;
39    }
40    
41 HudLadder ::  ~HudLadder()
42     {
43     }
44            
45     HudLadder ::
46             HudLadder( const HudLadder & image ) :
47             dual_instr_item( (dual_instr_item &) image),
48             width_units    ( image.width_units   ),
49             div_units      ( image.div_units     ),
50             label_pos      ( image.label_pos     ),
51             scr_hole       ( image.scr_hole      ),
52             vmax           ( image.vmax ),
53             vmin           ( image.vmin ),
54             factor         ( image.factor        )
55     {
56     }
57 HudLadder & HudLadder ::  operator = ( const HudLadder & rhs )
58     {
59         if( !(this == &rhs)) {
60             (dual_instr_item &)(*this) = (dual_instr_item &)rhs;
61             width_units  = rhs.width_units;
62             div_units    = rhs.div_units;
63             label_pos    = rhs.label_pos;
64             scr_hole     = rhs.scr_hole;
65             vmax         = rhs.vmax;
66             vmin         = rhs.vmin;
67             factor       = rhs.factor;
68         }
69         return *this;
70     }
71                            
72 //
73 //  Draws a climb ladder in the center of the HUD
74 //
75
76 void HudLadder :: draw( void )
77 {
78     POINT  centroid    = get_centroid();
79         
80     float   roll_value = current_ch2();
81     
82     glPushMatrix();
83     glTranslatef( centroid.x, centroid.y, 0);
84         // Alex's panel patch
85 //      glScalef( current_options.get_fov()/55.0, 1.0, 1.0 );
86     glRotatef(roll_value * RAD_TO_DEG, 0.0, 0.0, 1.0);
87
88     // Draw the target spot.
89 #define CENTER_DIAMOND_SIZE 6.0f
90         
91     glBegin(GL_LINE_LOOP);
92         glVertex2f( CENTER_DIAMOND_SIZE, 0.0);
93         glVertex2f( 0.0, CENTER_DIAMOND_SIZE);
94         glVertex2f( -CENTER_DIAMOND_SIZE, 0.0);
95         glVertex2f( 0.0, -CENTER_DIAMOND_SIZE);
96     glEnd();
97
98     if( minimal || ! div_units ) {
99         glPopMatrix();      
100         return;
101     }
102
103         float  x_ini;
104         float  x_end;
105         float  y;
106
107         float pitch_value = current_ch1() * RAD_TO_DEG;
108         vmin              = pitch_value - (float)width_units * 0.5f;
109         vmax              = pitch_value + (float)width_units * 0.5f;
110
111         RECT   box         = get_location();
112
113         float   half_span  = box.right * 0.5f ;
114
115         char     TextLadder[8] ;
116         float    label_length ;
117         float    label_height ;
118         float    left ;
119         float    right ;
120         float    bot ;
121         float    top ;
122         float    text_offset = 4.0f ;
123         float    zero_offset = 10.0f ;
124         
125         fntFont *font      = HUDtext->getFont();
126         float    pointsize = HUDtext->getPointSize();
127         float    italic    = HUDtext->getSlant();
128         
129         TextList.setFont( HUDtext );
130         TextList.erase();
131         LineList.erase();
132         StippleLineList.erase();
133         
134         int last = FloatToInt(vmax)+1;
135         int i    = FloatToInt(vmin);
136         
137         if( !scr_hole ) {
138                 x_end =  half_span;
139                 for( ; i<last ; i++ ) {
140                 
141                         y =  (((float)(i - pitch_value) * factor) + .5f);
142                         if( !(i % div_units ))    {        //  At integral multiple of div
143                 
144                                 sprintf( TextLadder, "%d", i );
145                                 font->getBBox ( TextLadder, pointsize, italic,
146                                                                 &left, &right, &bot, &top ) ;
147                                 
148                                 label_length  = right - left;
149                                 label_length += text_offset;
150                                 label_height  = (top - bot) * 0.5f;
151                 
152                                 x_ini = -half_span;
153
154                                 if( i >= 0 ) {
155                                         // Make zero point wider on left
156                                         if( i == 0 )
157                                                 x_ini -= zero_offset;
158                                         // Zero or above draw solid lines
159                                         Line(x_ini, y, x_end, y);
160                                 } else {
161                                         // Below zero draw dashed lines.
162                                         StippleLine(x_ini, y, x_end, y);
163                                 }
164                     
165                                 // Calculate the position of the left text and write it.
166                                 Text( x_ini-label_length, y-label_height, TextLadder );
167                                 Text( x_end+text_offset,  y-label_height, TextLadder );
168                         }
169                 }
170         } else  { // scr_hole != 0
171                 // Draw ladder with space in the middle of the lines
172                 float  x_ini2;
173                 float  x_end2;
174                 float hole = (float)((scr_hole)*0.5f);
175                 
176                 x_end  = -half_span + hole;
177                 x_ini2 =  half_span - hole;
178                 
179                 for( ; i<last ; i++ )      {
180                 
181                         y = (((float)(i - pitch_value) * factor) + .5);
182                         if( !(i % div_units ))    {        //  At integral multiple of div
183                 
184                                 sprintf( TextLadder, "%d", i );
185                                 font->getBBox ( TextLadder, pointsize, italic,
186                                                                 &left, &right, &bot, &top ) ;
187                                 label_length  = right - left;
188                                 label_length += text_offset;
189                                 label_height  = (top - bot) * 0.5f;
190                 
191                                 // Start by calculating the points and drawing the
192                                 // left side lines.
193                                 x_ini  = -half_span;
194                                 x_end2 =  half_span;
195                     
196                                 if( i >= 0 ) { 
197                                         // Make zero point wider on left
198                                         if( i == 0 ) {
199                                                 x_ini -= zero_offset;
200                                                 x_end2 += zero_offset;
201                                         }
202                                         // Zero or above draw solid lines
203                                         Line(x_ini, y, x_end, y);
204                                         Line(x_ini2, y, x_end2, y);
205                                 } else {
206                                         // Below zero draw dashed lines.
207                                         StippleLine(x_ini,  y, x_end,  y);
208                                         StippleLine(x_ini2, y, x_end2, y);
209                                 }
210                                 // Calculate the location of the left side label using
211                                 Text( x_ini-label_length, y-label_height, TextLadder );
212                                 // Calculate the location and draw the right side label
213                                 Text( x_end2+text_offset, y-label_height, TextLadder );
214                         }
215                 }
216         }
217         TextList.draw();
218         
219         LineList.draw();
220
221         glEnable(GL_LINE_STIPPLE);
222 #ifdef DO_PANEL_HACK
223         glLineStipple( 1, fgPanelVisible() ? 0x0F0F : 0x00FF );
224 #else
225         glLineStipple( 1, 0x00FF );
226 #endif
227         
228         StippleLineList.draw( );
229         glDisable(GL_LINE_STIPPLE);
230
231 //   } // if(div_units)
232     glPopMatrix();
233 }
234