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