]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_lon.cxx
Updates to vacuum system model from Alex Perry.
[flightgear.git] / src / Cockpit / hud_lon.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 <GUI/gui.h>
18 #include <Scenery/scenery.hxx>
19 #include <Time/fg_timer.hxx>
20
21 #include "hud.hxx"
22
23
24 #ifdef USE_HUD_TextList
25 #define textString( x , y, text, font )  TextString( text, x , y )
26 #else
27 #define textString( x , y, text, font )  puDrawString ( guiFnt, text, x, y );
28 #endif
29
30 //======================= Top of instr_label class =========================
31 lon_label ::
32          lon_label( int           x,
33                       int           y,
34                       UINT          width,
35                       UINT          height,
36                       FLTFNPTR      data_source,
37 //                      DBLFNPTR      data_source,                                      
38                       const char   *label_format,
39                       const char   *pre_label_string,
40                       const char   *post_label_string,
41                       float        scale_data,
42 //                      double        scale_data,                                       
43                       UINT          options,
44                       fgLabelJust   justification,
45                       int           font_size,
46                       int           blinking,
47                       bool          working ):
48                            instr_item( x, y, width, height,
49                                        data_source, scale_data,options, working ),
50                            pformat  ( label_format      ),
51                            pre_str  ( pre_label_string  ),
52                            post_str ( post_label_string ),
53                            justify  ( justification     ),
54                            fontSize ( font_size         ),
55                            blink    ( blinking          )
56 {
57   if( pre_str != NULL) {
58     if( post_str != NULL ) {
59       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
60       }
61     else {
62       sprintf( format_buffer, "%s%s",   pre_str, pformat );
63       }
64     }
65   else {
66     if( post_str != NULL ) {
67       sprintf( format_buffer, "%s%s",   pformat, post_str );
68       }
69     } // else do nothing if both pre and post strings are nulls. Interesting.
70
71 }
72
73 // I put this in to make it easy to construct a class member using the current
74 // C code.
75
76
77 lon_label :: ~lon_label()
78 {
79 }
80
81 // Copy constructor
82 lon_label :: lon_label( const lon_label & image) :
83                               instr_item((const instr_item &)image),
84                               pformat    ( image.pformat    ),
85                               pre_str  ( image.pre_str  ),
86                               post_str ( image.post_str ),
87                               blink    ( image.blink    )
88 {
89   if( pre_str != NULL) {
90     if( post_str != NULL ) {
91       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
92       }
93     else {
94       sprintf( format_buffer, "%s%s",   pre_str, pformat );
95       }
96     }
97   else {
98     if( post_str != NULL ) {
99       sprintf( format_buffer, "%s%s",   pformat, post_str );
100       }
101     } // else do nothing if both pre and post strings are nulls. Interesting.
102
103 }
104
105 lon_label & lon_label ::operator = (const lon_label & rhs )
106 {
107   if( !(this == &rhs)) {
108     instr_item::operator = (rhs);
109     pformat      = rhs.pformat;
110     fontSize   = rhs.fontSize;
111     blink      = rhs.blink;
112     justify    = rhs.justify;
113     pre_str    = rhs.pre_str;
114     post_str   = rhs.post_str;
115     strcpy(format_buffer,rhs.format_buffer);    
116     }
117   return *this;
118 }
119
120 //
121 // draw                    Draws a label anywhere in the HUD
122 //
123 //
124 void lon_label ::
125 draw( void )       // Required method in base class
126 {
127 //  char format_buffer[80];
128   char label_buffer[80];
129   int posincr;
130   int lenstr;
131   RECT  scrn_rect = get_location();
132   float lon = get_value();
133 //  double lon = get_value();  
134   if( data_available() ) {
135 //      char *lonstring = coord_format_lon(lon);
136     lenstr = sprintf( label_buffer, format_buffer, coord_format_lon(lon) );
137     }
138   else {
139     lenstr = sprintf( label_buffer, format_buffer );
140     }
141     
142 #ifdef DEBUGHUD
143   fgPrintf( FG_COCKPIT, FG_DEBUG,  format_buffer );
144   fgPrintf( FG_COCKPIT, FG_DEBUG,  "\n" );
145   fgPrintf( FG_COCKPIT, FG_DEBUG, label_buffer );
146   fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
147 #endif
148         
149         lenstr = getStringWidth(label_buffer);
150                                                 
151   if( justify == RIGHT_JUST ) {
152           posincr = scrn_rect.right - lenstr;
153   }else if( justify == CENTER_JUST ) {
154           posincr = get_span() - (lenstr/2); //  -lenstr*4;
155   }  else {
156       //  justify == LEFT_JUST
157       posincr = 0;  // 0;
158   }
159   
160   if( fontSize == SMALL ) {
161     textString( scrn_rect.left + posincr, scrn_rect.top,
162                 label_buffer, GLUT_BITMAP_8_BY_13);
163     }
164   else  {
165     if( fontSize == LARGE ) {
166       textString( scrn_rect.left + posincr, scrn_rect.top,
167                   label_buffer, GLUT_BITMAP_9_BY_15);
168       }
169     }
170 }
171