]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_ladr.cxx
e3143cee6fdd4fd814fc4f5b515adbb24653d664
[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     glRotatef(roll_value * RAD_TO_DEG, 0.0, 0.0, 1.0);
112
113     // Draw the target spot.
114 #define CENTER_DIAMOND_SIZE 6.0
115     glBegin(GL_LINE_LOOP);
116         glVertex2f( -CENTER_DIAMOND_SIZE, 0.0);
117         glVertex2f(0.0, CENTER_DIAMOND_SIZE);
118         glVertex2f( CENTER_DIAMOND_SIZE, 0.0);
119         glVertex2f(0.0, -CENTER_DIAMOND_SIZE);
120     glEnd();
121 #undef CENTER_DIAMOND_SIZE
122
123     if(minimal) {
124         glPopMatrix();      
125         return;
126     }
127
128     if( div_units ) {
129         char     TextLadder[8] ;
130         float    label_length ;
131         float    label_height ;
132         float    left ;
133         float    right ;
134         float    bot ;
135         float    top ;
136         float    text_offset = 4.0f ;
137         float    zero_offset = 10.0f ;
138   
139         fntFont *font      = HUDtext->getFont();
140         float    pointsize = HUDtext->getPointSize();
141         float    italic    = HUDtext->getSlant();
142         
143         TextList.setFont( HUDtext );
144         TextList.erase();
145         LineList.erase();
146         StippleLineList.erase();
147   
148         int last = FloatToInt(vmax)+1;
149         int i    = FloatToInt(vmin);
150         
151         if( !scr_hole ) {
152             for( ; i<last ; i++ ) {
153                 
154                 y =  (((float)(i - pitch_value) * factor) + .5f);
155                 if( !(i % div_units ))    {        //  At integral multiple of div
156                 
157                     sprintf( TextLadder, "%d", i );
158                     font->getBBox ( TextLadder, pointsize, italic,
159                                     &left, &right, &bot, &top ) ;
160                     label_length  = right - left;
161                     label_length += text_offset;
162                     label_height  = (top - bot)/2.0f;
163                 
164                     x_ini = -half_span;
165                     x_end =  half_span;
166                     
167                     if( i >= 0 ) {
168                         // Make zero point wider on left
169                         if( i == 0 )
170                             x_ini -= zero_offset;
171                         // Zero or above draw solid lines
172                         Line(x_ini, y, x_end, y);
173                     } else {
174                         // Below zero draw dashed lines.
175                         StippleLine(x_ini, y, x_end, y);
176                     }
177                     
178                     // Calculate the position of the left text and write it.
179                     Text( x_ini-label_length, y-label_height, TextLadder );
180                     Text( x_end+text_offset,  y-label_height, TextLadder );
181                 }
182             }
183         }
184         else // if(scr_hole )
185         {    // Draw ladder with space in the middle of the lines
186             float hole = (float)((scr_hole)/2.0f);
187             for( ; i<last ; i++ )      {
188                 
189                 y = (((float)(i - pitch_value) * factor) + .5);
190                 if( !(i % div_units ))    {        //  At integral multiple of div
191                 
192                     sprintf( TextLadder, "%d", i );
193                     font->getBBox ( TextLadder, pointsize, italic,
194                                     &left, &right, &bot, &top ) ;
195                     label_length  = right - left;
196                     label_length += text_offset;
197                     label_height  = (top - bot)/2.0f;
198 //                  printf("l %f r %f b %f t %f\n",left, right, bot, top );
199                 
200                     // Start by calculating the points and drawing the
201                     // left side lines.
202                     x_ini = -half_span;
203                     x_end = -half_span + hole;
204                     
205                     if( i >= 0 ) { 
206                         // Make zero point wider on left
207                         if( i == 0 )
208                             x_ini -= zero_offset;
209                         // Zero or above draw solid lines
210                         Line(x_ini, y, x_end, y);
211                     } else {
212                         // Below zero draw dashed lines.
213                         StippleLine(x_ini, y, x_end, y);
214                     }
215                     
216                     // Now calculate the location of the left side label using
217                     Text( x_ini-label_length, y-label_height, TextLadder );
218                     
219                     // Now calculate and draw the right side line location
220                     x_ini = half_span - hole;
221                     x_end = half_span;
222                     
223                     if( i >= 0 ) {
224                         if( i == 0 ) 
225                             x_end += zero_offset;
226                         // Zero or above draw solid lines
227                         Line(x_ini, y, x_end, y);
228                     } else {
229                         // Below zero draw dashed lines.
230                         StippleLine(x_ini, y, x_end, y);
231                     }
232                     
233                     // Calculate the location and draw the right side label
234                     Text( x_end+text_offset,  y-label_height, TextLadder );
235                 }
236             }
237         }
238         TextList.draw();
239
240         glLineWidth(0.2);
241         
242         LineList.draw();
243         
244         glEnable(GL_LINE_STIPPLE);
245         glLineStipple( 1, 0x00FF );
246         StippleLineList.draw( );
247         glDisable(GL_LINE_STIPPLE);
248     }
249     glPopMatrix();
250 }
251