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