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