]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_lat.cxx
indentation, trailing spaces, alignment, ... (to make further work easier)
[flightgear.git] / src / Cockpit / hud_lat.cxx
1
2 #include "hud.hxx"
3
4
5 #ifdef USE_HUD_TextList
6 #define textString( x , y, text, digit )  TextString( text, x , y,digit )
7 #else
8 #define textString( x , y, text, digit )  puDrawString ( guiFnt, text, x, y )
9 #endif
10
11 //======================= Top of instr_label class =========================
12 lat_label::lat_label(int           x,
13                      int           y,
14                      UINT          width,
15                      UINT          height,
16                      FLTFNPTR      data_source,
17                      const char   *label_format,
18                      const char   *pre_label_string,
19                      const char   *post_label_string,
20                      float         scale_data,
21                      UINT          options,
22                      fgLabelJust   justification,
23                      int           font_size,
24                      int           blinking,
25                      bool          working ,
26                      int           digit) :
27     instr_item( x, y, width, height,
28                 data_source, scale_data,options, working,digit),
29     pformat  ( label_format      ),
30     pre_str  ( pre_label_string  ),
31     post_str ( post_label_string ),
32     justify  ( justification     ),
33     fontSize ( font_size         ),
34     blink    ( blinking          )
35 {
36     if (pre_str != NULL) {
37         if (post_str != NULL)
38             sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
39         else
40             sprintf( format_buffer, "%s%s",   pre_str, pformat );
41
42     } else if (post_str != NULL) {
43             sprintf( format_buffer, "%s%s",   pformat, post_str );
44     } // else do nothing if both pre and post strings are nulls. Interesting.
45
46 }
47
48 // I put this in to make it easy to construct a class member using the current
49 // C code.
50
51
52 lat_label::~lat_label()
53 {
54 }
55
56
57 // Copy constructor
58 lat_label::lat_label( const lat_label & image) :
59                       instr_item((const instr_item &)image),
60                       pformat    ( image.pformat  ),
61                       pre_str    ( image.pre_str  ),
62                       post_str   ( image.post_str ),
63                       blink      ( image.blink    )
64 {
65     if (pre_str != NULL) {
66         if (post_str != NULL)
67             sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
68         else
69             sprintf( format_buffer, "%s%s",   pre_str, pformat );
70
71     } else if (post_str != NULL) {
72         sprintf( format_buffer, "%s%s",   pformat, post_str );
73     } // else do nothing if both pre and post strings are nulls. Interesting.
74
75 }
76
77
78 lat_label& lat_label::operator=(const lat_label & rhs)
79 {
80     if (!(this == &rhs)) {
81         instr_item::operator = (rhs);
82         pformat    = rhs.pformat;
83         fontSize   = rhs.fontSize;
84         blink      = rhs.blink;
85         justify    = rhs.justify;
86         pre_str    = rhs.pre_str;
87         post_str   = rhs.post_str;
88         strcpy(format_buffer,rhs.format_buffer);
89     }
90     return *this;
91 }
92
93
94 //
95 // draw                    Draws a label anywhere in the HUD
96 //
97 //
98 void lat_label::draw( void )       // Required method in base class
99 {
100     char label_buffer[80];
101     int posincr;
102     int lenstr;
103     RECT  scrn_rect = get_location();
104     // float lat = get_value();
105
106     if (data_available()) {
107 //      // sprintf( label_buffer, format_buffer, coord_format_lat(lat) );
108         sprintf( label_buffer, format_buffer,
109                 coord_format_lat( get_value()) );
110
111     } else {
112         sprintf( label_buffer, format_buffer );
113     }
114
115 #ifdef DEBUGHUD
116     fgPrintf( SG_COCKPIT, SG_DEBUG, format_buffer );
117     fgPrintf( SG_COCKPIT, SG_DEBUG, "\n" );
118     fgPrintf( SG_COCKPIT, SG_DEBUG, label_buffer );
119     fgPrintf( SG_COCKPIT, SG_DEBUG, "\n" );
120 #endif
121
122     lenstr = getStringWidth(label_buffer);
123
124     if (justify == RIGHT_JUST)
125         posincr = scrn_rect.right - lenstr;
126     else if (justify == CENTER_JUST)
127         posincr = get_span() - (lenstr/2);
128     else // justify == LEFT_JUST
129         posincr = 0;
130
131     if (fontSize == HUD_FONT_SMALL) {
132         textString( scrn_rect.left + posincr, scrn_rect.top,
133                 label_buffer, get_digits());
134
135     } else if (fontSize == HUD_FONT_LARGE) {
136         textString( scrn_rect.left + posincr, scrn_rect.top,
137                 label_buffer, get_digits());
138     }
139 }
140
141