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