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