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