~ubuntu-branches/ubuntu/quantal/flightgear/quantal

« back to all changes in this revision

Viewing changes to src/Cockpit/hud_labl.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Ove Kaaven
  • Date: 2002-03-27 21:50:15 UTC
  • Revision ID: james.westby@ubuntu.com-20020327215015-0rvi3o8iml0a8s93
Tags: upstream-0.7.9
ImportĀ upstreamĀ versionĀ 0.7.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "hud.hxx"
 
3
 
 
4
 
 
5
#ifdef USE_HUD_TextList
 
6
#define textString( x , y, text, font,digit )  TextString( text, x , y,digit ) //suma
 
7
#else
 
8
#define textString( x , y, text, font,digit )  puDrawString ( guiFnt, text, x, y ); //suma
 
9
#endif
 
10
 
 
11
//======================= Top of instr_label class =========================
 
12
instr_label ::
 
13
         instr_label( int           x,
 
14
                      int           y,
 
15
                      UINT          width,
 
16
                      UINT          height,
 
17
                      FLTFNPTR      data_source,
 
18
                      const char   *label_format,
 
19
                      const char   *pre_label_string,
 
20
                      const char   *post_label_string,
 
21
                      float        scale_data,
 
22
                      UINT          options,
 
23
                      fgLabelJust   justification,
 
24
                      int           font_size,
 
25
                      int           blinking,
 
26
                                      bool                      latitude,
 
27
                                      bool                      longitude,
 
28
                                          bool                  label_box,//hud
 
29
                      bool          working,
 
30
                                          int                   digit):  //suma
 
31
                           instr_item( x, y, width, height,
 
32
                                       data_source,scale_data,options, working, digit), //suma
 
33
                           pformat  ( label_format      ),
 
34
                           pre_str  ( pre_label_string  ),
 
35
                           post_str ( post_label_string ),
 
36
                           justify  ( justification     ),
 
37
                           fontSize ( font_size         ),
 
38
                           blink    ( blinking          ),
 
39
                                                   lat          ( latitude                      ),
 
40
                                                   lon          ( longitude                     ),
 
41
                                                   lbox         ( label_box                     ) //hud
 
42
 
 
43
{
 
44
  if( pre_str != NULL) {
 
45
    if( post_str != NULL ) {
 
46
      sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
 
47
      }
 
48
    else {
 
49
      sprintf( format_buffer, "%s%s",   pre_str, pformat );
 
50
      }
 
51
    }
 
52
  else {
 
53
    if( post_str != NULL ) {
 
54
      sprintf( format_buffer, "%s%s",   pformat, post_str );
 
55
      }
 
56
    } // else do nothing if both pre and post strings are nulls. Interesting.
 
57
 
 
58
}
 
59
 
 
60
// I put this in to make it easy to construct a class member using the current
 
61
// C code.
 
62
 
 
63
 
 
64
instr_label :: ~instr_label()
 
65
{
 
66
}
 
67
 
 
68
// Copy constructor
 
69
instr_label :: instr_label( const instr_label & image) :
 
70
                              instr_item((const instr_item &)image),
 
71
                              pformat    ( image.pformat    ),
 
72
                              pre_str  ( image.pre_str  ),
 
73
                              post_str ( image.post_str ),
 
74
                              blink    ( image.blink    ),
 
75
                                                          lat      ( image.lat          ),
 
76
                                                          lon      ( image.lon          ),      
 
77
                                                          lbox     (image.lbox          ) //hud
 
78
 
 
79
{
 
80
  if( pre_str != NULL) {
 
81
    if( post_str != NULL ) {
 
82
      sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
 
83
      }
 
84
    else {
 
85
      sprintf( format_buffer, "%s%s",   pre_str, pformat );
 
86
      }
 
87
    }
 
88
  else {
 
89
    if( post_str != NULL ) {
 
90
      sprintf( format_buffer, "%s%s",   pformat, post_str );
 
91
      }
 
92
    } // else do nothing if both pre and post strings are nulls. Interesting.
 
93
 
 
94
}
 
95
 
 
96
instr_label & instr_label ::operator = (const instr_label & rhs )
 
97
{
 
98
  if( !(this == &rhs)) {
 
99
    instr_item::operator = (rhs);
 
100
    pformat      = rhs.pformat;
 
101
    fontSize   = rhs.fontSize;
 
102
    blink      = rhs.blink;
 
103
    justify    = rhs.justify;
 
104
    pre_str    = rhs.pre_str;
 
105
    post_str   = rhs.post_str;
 
106
    lat            = rhs.lat;
 
107
    lon            = rhs.lon;
 
108
        lbox       = rhs.lbox; //hud
 
109
 
 
110
 
 
111
    strcpy(format_buffer,rhs.format_buffer);    
 
112
    }
 
113
  return *this;
 
114
}
 
115
 
 
116
//
 
117
// draw                    Draws a label anywhere in the HUD
 
118
//
 
119
//
 
120
void instr_label ::
 
121
draw( void )       // Required method in base class
 
122
{
 
123
//  char format_buffer[80];
 
124
  char label_buffer[80];
 
125
  int posincr;
 
126
  int lenstr;
 
127
  RECT  scrn_rect = get_location();
 
128
 
 
129
  if( data_available() ) {
 
130
        if(lat)
 
131
                sprintf( label_buffer, format_buffer, coord_format_lat(get_value()) );
 
132
        else
 
133
        if(lon)    
 
134
                sprintf( label_buffer, format_buffer, coord_format_lon(get_value()) );
 
135
        else
 
136
        {       
 
137
                if(lbox)//hud
 
138
                        {// Box for label
 
139
                                float x = scrn_rect.left;
 
140
                                float y = scrn_rect.top;
 
141
                                float w = scrn_rect.right;
 
142
                        float h = HUD_TextSize;
 
143
 
 
144
                                glPushMatrix();
 
145
                                glLoadIdentity();
 
146
                                glBegin(GL_LINES);
 
147
                                        glVertex2f( x - 2.0,  y - 2.0);
 
148
                                        glVertex2f( x + w + 2.0, y - 2.0);
 
149
                                        glVertex2f( x + w + 2.0, y + h + 2.0);
 
150
                                        glVertex2f( x - 2.0,  y + h + 2.0);
 
151
                                glEnd();
 
152
                        glEnable(GL_LINE_STIPPLE);
 
153
                                glLineStipple( 1, 0xAAAA );
 
154
                                glBegin(GL_LINES);
 
155
                                        glVertex2f( x + w + 2.0, y - 2.0);
 
156
                                        glVertex2f( x + w + 2.0, y + h + 2.0);
 
157
                                        glVertex2f( x - 2.0,  y + h + 2.0);
 
158
                                        glVertex2f( x - 2.0,  y - 2.0);
 
159
                                glEnd();
 
160
                        glDisable(GL_LINE_STIPPLE);
 
161
                                glPopMatrix();
 
162
                        }//hud
 
163
                sprintf( label_buffer, format_buffer, get_value()*data_scaling() );
 
164
        }
 
165
  }
 
166
  else {
 
167
//    sprintf( label_buffer, format_buffer );
 
168
  }
 
169
  
 
170
  lenstr = getStringWidth( label_buffer );
 
171
                                                
 
172
    
 
173
#ifdef DEBUGHUD
 
174
  fgPrintf( SG_COCKPIT, SG_DEBUG,  format_buffer );
 
175
  fgPrintf( SG_COCKPIT, SG_DEBUG,  "\n" );
 
176
  fgPrintf( SG_COCKPIT, SG_DEBUG, label_buffer );
 
177
  fgPrintf( SG_COCKPIT, SG_DEBUG, "\n" );
 
178
#endif
 
179
  lenstr = strlen( label_buffer );
 
180
 
 
181
  if( justify == RIGHT_JUST ) {
 
182
          posincr = scrn_rect.right - lenstr;
 
183
  }else if( justify == CENTER_JUST ) {
 
184
          posincr = get_span() - (lenstr/2); //  -lenstr*4;
 
185
  }  else {
 
186
      //  justify == LEFT_JUST
 
187
      posincr = 0;  // 0;
 
188
  }
 
189
  
 
190
  if( fontSize == SMALL ) {
 
191
    textString( scrn_rect.left + posincr, scrn_rect.top,
 
192
                label_buffer, GLUT_BITMAP_8_BY_13 ,get_digits()); //suma
 
193
    }
 
194
  else  {
 
195
    if( fontSize == LARGE ) {
 
196
      textString( scrn_rect.left + posincr, scrn_rect.top,
 
197
                  label_buffer, GLUT_BITMAP_9_BY_15 ,get_digits()); //suma
 
198
      }
 
199
    }
 
200
}
 
201