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