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