]> git.mxchange.org Git - flightgear.git/blob - Cockpit/hud_labl.cxx
C++ ifying ...
[flightgear.git] / Cockpit / hud_labl.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 <Debug/fg_debug.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 //======================= Top of instr_label class =========================
23 instr_label ::
24          instr_label( int           x,
25                       int           y,
26                       UINT          width,
27                       UINT          height,
28                       DBLFNPTR      data_source,
29                       const char   *label_format,
30                       const char   *pre_label_string,
31                       const char   *post_label_string,
32                       double        scale_data,
33                       UINT          options,
34                       fgLabelJust   justification,
35                       int           font_size,
36                       int           blinking,
37                       bool          working ):
38                            instr_item( x, y, width, height,
39                                        data_source, scale_data,options, working ),
40                            pformat  ( label_format      ),
41                            pre_str  ( pre_label_string  ),
42                            post_str ( post_label_string ),
43                            justify  ( justification     ),
44                            fontSize ( font_size         ),
45                            blink    ( blinking          )
46 {
47 }
48
49 // I put this in to make it easy to construct a class member using the current
50 // C code.
51
52
53 instr_label :: ~instr_label()
54 {
55 }
56
57 // Copy constructor
58 instr_label :: instr_label( const instr_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 }
66
67 instr_label & instr_label ::operator = (const instr_label & rhs )
68 {
69   if( !(this == &rhs)) {
70     instr_item::operator = (rhs);
71     pformat      = rhs.pformat;
72     fontSize   = rhs.fontSize;
73     blink      = rhs.blink;
74     justify    = rhs.justify;
75     pre_str    = rhs.pre_str;
76     post_str   = rhs.post_str;
77     }
78         return *this;
79 }
80
81 //
82 // draw                    Draws a label anywhere in the HUD
83 //
84 //
85 void instr_label ::
86 draw( void )       // Required method in base class
87 {
88   char format_buffer[80];
89   char label_buffer[80];
90   int posincr;
91   int lenstr;
92   RECT  scrn_rect = get_location();
93
94   if( pre_str != NULL) {
95     if( post_str != NULL ) {
96       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
97       }
98     else {
99       sprintf( format_buffer, "%s%s",   pre_str, pformat );
100       }
101     }
102   else {
103     if( post_str != NULL ) {
104       sprintf( format_buffer, "%s%s",   pformat, post_str );
105       }
106     } // else do nothing if both pre and post strings are nulls. Interesting.
107
108   if( data_available() ) {
109     sprintf( label_buffer, format_buffer, get_value() );
110     }
111   else {
112     sprintf( label_buffer, format_buffer );
113     }
114     
115 #ifdef DEBUGHUD
116         fgPrintf( FG_COCKPIT, FG_DEBUG,  format_buffer );
117         fgPrintf( FG_COCKPIT, FG_DEBUG,  "\n" );
118         fgPrintf( FG_COCKPIT, FG_DEBUG, label_buffer );
119         fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
120 #endif
121   lenstr = strlen( label_buffer );
122
123   posincr = 0;   //  default to RIGHT_JUST ... center located calc: -lenstr*8;
124
125   if( justify == CENTER_JUST ) {
126     posincr =  - (lenstr << 2); //  -lenstr*4;
127     }
128   else {
129     if( justify == LEFT_JUST ) {
130       posincr = - (lenstr << 8);  // 0;
131       }
132     }
133
134   if( fontSize == SMALL ) {
135     textString( scrn_rect.left + posincr, scrn_rect.top,
136                 label_buffer, GLUT_BITMAP_8_BY_13);
137     }
138   else  {
139     if( fontSize == LARGE ) {
140       textString( scrn_rect.left + posincr, scrn_rect.top,
141                   label_buffer, GLUT_BITMAP_9_BY_15);
142       }
143     }
144 }
145