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