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