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