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