]> git.mxchange.org Git - flightgear.git/blob - Cockpit/hud_labl.cxx
Renamed polar3d.h to polar3d.hxx
[flightgear.git] / Cockpit / hud_labl.cxx
1 #ifdef HAVE_CONFIG_H\r
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.h>
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 \r
23 //======================= Top of instr_label class =========================\r
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                       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, 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 //
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   sprintf( label_buffer, format_buffer, get_value() );
110 #ifdef DEBUGHUD
111         fgPrintf( FG_COCKPIT, FG_DEBUG,  format_buffer );
112         fgPrintf( FG_COCKPIT, FG_DEBUG,  "\n" );
113         fgPrintf( FG_COCKPIT, FG_DEBUG, label_buffer );
114         fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
115 #endif
116   lenstr = strlen( label_buffer );
117
118   posincr = 0;   //  default to RIGHT_JUST ... center located calc: -lenstr*8;
119
120   if( justify == CENTER_JUST ) {
121     posincr =  - (lenstr << 2); //  -lenstr*4;
122     }
123   else {
124     if( justify == LEFT_JUST ) {
125       posincr = - (lenstr << 8);  // 0;
126       }
127     }
128
129   if( fontSize == SMALL ) {
130     textString( scrn_rect.left + posincr, scrn_rect.top,
131                 label_buffer, GLUT_BITMAP_8_BY_13);
132     }
133   else  {
134     if( fontSize == LARGE ) {
135       textString( scrn_rect.left + posincr, scrn_rect.top,
136                   label_buffer, GLUT_BITMAP_9_BY_15);
137       }
138     }
139 }
140