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