Debian Codegraph @

src/Instrumentation/HUD/HUD_gauge.cxx

raw symbols SCIP
1 // HUD_gauge.cxx -- HUD Gauge Instrument
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
6 // Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 #include "HUD.hxx"
23 #include "HUD_private.hxx"
24
25 HUD::Gauge::Gauge(HUD *hud, const SGPropertyNode *n, float x, float y) :
26 Scale(hud, n, x, y)
27 {
28 }
29
30
31 // As implemented, draw only correctly draws a horizontal or vertical
32 // scale. It should contain a variation that permits clock type displays.
33 // Now is supports "tickless" displays such as control surface indicators.
34 // This routine should be worked over before using. Current value would be
35 // fetched and not used if not commented out. Clearly that is intollerable.
36
37 void HUD::Gauge::draw(void)
38 {
39 if (!_input.isValid())
40 return;
41
42 float marker_xs, marker_xe;
43 float marker_ys, marker_ye;
44 float text_y;
45 int i;
46 const int BUFSIZE = 80;
47 char buf[BUFSIZE];
48 bool condition;
49 int disp_val = 0;
50 float vmin = _input.min();
51 float vmax = _input.max();
52 float cur_value = _input.getFloatValue();
53
54 float right = _x + _w;
55 float top = _y + _h;
56 float bottom_4 = _h / 4.0; // FIXME
57 float right_4 = _w / 4.0;
58
59 // Draw the basic markings for the scale...
60 if (option_vert()) { // Vertical scale
61 // Bottom tick bar
62 draw_line(_x, _y, right, _y);
63
64 // Top tick bar
65 draw_line(_x, top, right, top);
66
67 marker_xs = _x;
68 marker_xe = right;
69
70 if (option_left()) { // Read left, so line down right side
71 draw_line(right, _y, right, top);
72 marker_xs = marker_xe - _w / 2.0; // Adjust tick
73 }
74
75 if (option_right()) { // Read right, so down left sides
76 draw_line(_x, _y, _x, top);
77 marker_xe = _x + _w / 2.0; // Adjust tick
78 }
79
80 // At this point marker x_start and x_end values are transposed.
81 // To keep this from confusing things they are now interchanged.
82 if (option_both()) {
83 marker_ye = marker_xs;
84 marker_xs = marker_xe;
85 marker_xe = marker_ye;
86 }
87
88 // Work through from bottom to top of scale. Calculating where to put
89 // minor and major ticks.
90
91 if (!option_noticks()) { // If not no ticks...:)
92 // Calculate x marker offsets
93 int last = (int)vmax + 1;
94 i = (int)vmin;
95
96 for (; i < last; i++) {
97 // Calculate the location of this tick
98 marker_ys = _y + (i - vmin) * factor()/* +.5f*/;
99
100 // We compute marker_ys even though we don't know if we will use
101 // either major or minor divisions. Simpler.
102
103 if (_minor_divs) { // Minor tick marks
104 if (!(i % (int)_minor_divs)) {
105 if (option_left() && option_right()) {
106 draw_line(_x, marker_ys, marker_xs - 4, marker_ys);
107 draw_line(marker_xe + 4, marker_ys, right, marker_ys);
108
109 } else if (option_left()) {
110 draw_line(marker_xs + 4, marker_ys, marker_xe, marker_ys);
111 } else {
112 draw_line(marker_xs, marker_ys, marker_xe - 4, marker_ys);
113 }
114 }
115 }
116
117 // Now we work on the major divisions. Since these are also labeled
118 // and no labels are drawn otherwise, we label inside this if
119 // statement.
120
121 if (_major_divs) { // Major tick mark
122 if (!(i % (int)_major_divs)) {
123 if (option_left() && option_right()) {
124 draw_line(_x, marker_ys, marker_xs, marker_ys);
125 draw_line(marker_xe, marker_ys, right, marker_ys);
126 } else {
127 draw_line(marker_xs, marker_ys, marker_xe, marker_ys);
128 }
129
130 if (!option_notext()) {
131 disp_val = i;
132 snprintf(buf, BUFSIZE, "%d",
133 int(disp_val * _input.factor()/*+.5*/)); /// was data_scaling(), which makes no sense
134
135 if (option_left() && option_right())
136 draw_text(_center_x, marker_ys, buf, CENTER);
137 else if (option_left())
138 draw_text(marker_xs, marker_ys, buf, RIGHT|VCENTER);
139 else
140 draw_text(marker_xe, marker_ys, buf, LEFT|VCENTER);
141 }
142 }
143 }
144 }
145 }
146
147 // Now that the scale is drawn, we draw in the pointer(s).
148 text_y = _y + ((cur_value - vmin) * factor() /*+.5f*/);
149
150 if (option_right()) {
151 _hud->_line_list.add(LineSegment(_x, text_y + right_4, marker_xe, text_y));
152 _hud->_line_list.add(LineSegment(marker_xe, text_y, _x, text_y - right_4));
153 }
154 if (option_left()) {
155 _hud->_line_list.add(LineSegment(right, text_y + right_4, marker_xs, text_y));
156 _hud->_line_list.add(LineSegment(marker_xs, text_y, right, text_y - right_4));
157 }
158 // End if VERTICAL SCALE TYPE
159
160 } else { // Horizontal scale by default
161 // left tick bar
162 draw_line(_x, _y, _x, top);
163
164 // right tick bar
165 draw_line(right, _y, right, top );
166
167 marker_ys = _y; // Starting point for
168 marker_ye = top; // tick y location calcs
169 marker_xs = _x + (cur_value - vmin) * factor() /*+ .5f*/;
170
171 if (option_top()) {
172 // Bottom box line
173 draw_line(_x, _y, right, _y);
174
175 marker_ye = _y + _h / 2.0; // Tick point adjust
176 // Bottom arrow
177 _hud->_line_list.add(LineSegment(marker_xs - bottom_4, _y, marker_xs, marker_ye));
178 _hud->_line_list.add(LineSegment(marker_xs, marker_ye, marker_xs + bottom_4, _y));
179 }
180
181 if (option_bottom()) {
182 // Top box line
183 draw_line(_x, top, right, top);
184 // Tick point adjust
185 marker_ys = top - _h / 2.0;
186
187 // Top arrow
188 _hud->_line_list.add(LineSegment(marker_xs + bottom_4, top, marker_xs, marker_ys));
189 _hud->_line_list.add(LineSegment(marker_xs, marker_ys, marker_xs - bottom_4, top));
190 }
191
192
193 int last = (int)vmax + 1;
194 i = (int)vmin;
195 for (; i <last ; i++) {
196 condition = true;
197 if (!_modulo && i < _input.min())
198 condition = false;
199
200 if (condition) {
201 marker_xs = _x + (i - vmin) * factor()/* +.5f*/;
202 // marker_xs = _x + (int)((i - vmin) * factor() + .5f);
203 if (_minor_divs) {
204 if (!(i % (int)_minor_divs)) {
205 // draw in ticks only if they aren't too close to the edge.
206 if (((marker_xs + 5) > _x)
207 || ((marker_xs - 5) < right)) {
208
209 if (option_both()) {
210 draw_line(marker_xs, _y, marker_xs, marker_ys - 4);
211 draw_line(marker_xs, marker_ye + 4, marker_xs, top);
212
213 } else if (option_top()) {
214 draw_line(marker_xs, marker_ys, marker_xs, marker_ye - 4);
215 } else {
216 draw_line(marker_xs, marker_ys + 4, marker_xs, marker_ye);
217 }
218 }
219 }
220 }
221
222 if (_major_divs) {
223 if (!(i % (int)_major_divs)) {
224 if (_modulo) {
225 if (disp_val < 0) {
226 while (disp_val < 0)
227 disp_val += _modulo;
228 }
229 disp_val = i % (int)_modulo;
230 } else {
231 disp_val = i;
232 }
233 snprintf(buf, BUFSIZE, "%d",
234 int(disp_val * _input.factor()/* +.5*/)); // was data_scaling(), which makes no sense
235
236 // Draw major ticks and text only if far enough from the edge.
237 if (((marker_xs - 10) > _x)
238 && ((marker_xs + 10) < right)) {
239 if (option_both()) {
240 draw_line(marker_xs, _y, marker_xs, marker_ys);
241 draw_line(marker_xs, marker_ye, marker_xs, top);
242
243 if (!option_notext())
244 draw_text(marker_xs, marker_ys, buf, CENTER);
245
246 } else {
247 draw_line(marker_xs, marker_ys, marker_xs, marker_ye);
248
249 if (!option_notext()) {
250 if (option_top())
251 draw_text(marker_xs, top, buf, TOP|HCENTER);
252 else
253 draw_text(marker_xs, _y, buf, BOTTOM|HCENTER);
254 }
255 }
256 }
257 }
258 }
259 }
260 }
261 }
262 }
263
264