]> git.mxchange.org Git - flightgear.git/blob - Cockpit/hud_inst.cxx
C++-ifying.
[flightgear.git] / Cockpit / hud_inst.cxx
1 // Abstract Base Class instr_item
2 //
3 #ifdef HAVE_CONFIG_H
4 #  include <config.h>
5 #endif
6
7 #ifdef HAVE_WINDOWS_H
8 #  include <windows.h>
9 #endif
10
11 #include <stdlib.h>
12 #include <string.h>
13 #include <Aircraft/aircraft.hxx>
14 #include <Debug/fg_debug.h>
15 #include <Include/fg_constants.h>
16 #include <Math/fg_random.h>
17 #include <Math/mat3.h>
18 #include <Math/polar3d.hxx>
19 #include <Scenery/scenery.hxx>
20 #include <Time/fg_timer.hxx>
21 #include <Weather/weather.h>
22
23
24 #include "hud.hxx"
25
26 UINT instr_item :: instances = 0;  // Initial value of zero
27 int  instr_item :: brightness = BRT_MEDIUM;
28 glRGBTRIPLE instr_item :: color = {0.1, 0.7, 0.0};
29
30 // constructor    ( No default provided )
31 instr_item  ::
32    instr_item( int              x,
33                int              y,
34                UINT             width,
35                UINT             height,
36                DBLFNPTR         data_source,
37                double           data_scaling,
38                UINT             options,
39                bool             working) :
40                       handle         ( ++instances  ),
41                       load_value_fn  ( data_source  ),
42                       disp_factor    ( data_scaling ),
43                       opts           ( options      ),
44                       is_enabled     ( working      ),
45                       broken         ( FALSE        )
46 {
47   scrn_pos.left   = x;
48   scrn_pos.top    = y;
49   scrn_pos.right  = width;
50   scrn_pos.bottom = height;
51
52          // Set up convenience values for centroid of the box and
53          // the span values according to orientation
54
55   if( opts & HUDS_VERT) { // Vertical style
56          // Insure that the midpoint marker will fall exactly at the
57          // middle of the bar.
58     if( !(scrn_pos.bottom % 2)) {
59       scrn_pos.bottom++;
60       }
61     scr_span = scrn_pos.bottom;
62     }
63   else {
64          // Insure that the midpoint marker will fall exactly at the
65          // middle of the bar.
66     if( !(scrn_pos.right % 2)) {
67       scrn_pos.right++;
68       }
69     scr_span = scrn_pos.right;
70     }
71          // Here we work out the centroid for the corrected box.
72   mid_span.x = scrn_pos.left   + (scrn_pos.right  >> 1);
73   mid_span.y = scrn_pos.top + (scrn_pos.bottom >> 1);
74 }
75
76
77 // copy constructor
78 instr_item  ::
79      instr_item ( const instr_item & image ):
80                          handle       ( ++instances        ),
81                          scrn_pos     ( image.scrn_pos     ),
82                          load_value_fn( image.load_value_fn),
83                          disp_factor  ( image.disp_factor  ),
84                          opts         ( image.opts         ),
85                          is_enabled   ( image.is_enabled   ),
86                          broken       ( image.broken       ),
87                          scr_span     ( image.scr_span     ),
88                          mid_span     ( image.mid_span     )
89 {
90 }
91
92 // assignment operator
93
94 instr_item & instr_item :: operator = ( const instr_item & rhs )
95 {
96   if( !(this == &rhs )) { // Not an identity assignment
97     scrn_pos      = rhs.scrn_pos;
98     load_value_fn = rhs.load_value_fn;
99     disp_factor   = rhs.disp_factor;
100     opts          = rhs.opts;
101     is_enabled    = rhs.is_enabled;
102     broken        = rhs.broken;
103     }
104   return *this;
105 }
106
107 // destructor
108
109 instr_item :: ~instr_item ()
110 {
111   if( instances ) {
112     instances--;
113     }
114 }
115
116 void instr_item ::
117     update( void )
118 {
119 }
120
121 // break_display       This is emplaced to provide hooks for making
122 //                     instruments unreliable. The default behavior is
123 // to simply not display, but more sophisticated behavior is available
124 // by over riding the function which is virtual in this class.
125
126 void instr_item ::
127     break_display ( bool bad )
128 {
129   broken = !!bad;
130   is_enabled = FALSE;
131 }
132
133 void instr_item ::
134     SetBrightness  ( int level  )
135 {
136   brightness = level;   // This is all we will do for now. Later the
137                         // brightness levels will be sensitive both to
138                         // the control knob and the outside light levels
139                         // to emulated night vision effects.
140 }
141
142 UINT instr_item :: get_Handle( void )
143 {
144   return handle;
145 }
146