3 #ifdef USE_HUD_TextList
4 #define textString(x, y, text, digit) TextString(text, x , y ,digit)
6 #define textString(x, y, text, digit) puDrawString(guiFnt, text, x, y)
10 gauge_instr::gauge_instr(const SGPropertyNode *node) :
12 node->getIntValue("x"),
13 node->getIntValue("y"),
14 node->getIntValue("width"),
15 node->getIntValue("height"),
17 node->getIntValue("options"),
18 node->getFloatValue("maxValue") - node->getFloatValue("minValue"), // Always shows span?
19 node->getFloatValue("maxValue"),
20 node->getFloatValue("minValue"),
21 node->getFloatValue("disp_scaling"),
22 node->getIntValue("major_divs"),
23 node->getIntValue("minor_divs"),
24 node->getIntValue("modulator"), // "rollover"
25 0, /* hud.cxx: static int dp_shoing = 0; */ // FIXME
26 node->getBoolValue("working"))
28 SG_LOG(SG_INPUT, SG_INFO, "Done reading gauge instrument "
29 << node->getStringValue("name", "[unnamed]"));
31 string loadfn = node->getStringValue("loadfn"); // FIXME
32 float (*load_fn)(void);
35 } else if (loadfn=="heading") {
36 load_fn = get_heading;
37 } else if (loadfn=="aoa") {
39 } else if (loadfn=="climb") {
40 load_fn = get_climb_rate;
41 } else if (loadfn=="altitude") {
42 load_fn = get_altitude;
43 } else if (loadfn=="agl") {
45 } else if (loadfn=="speed") {
47 } else if (loadfn=="view_direction") {
48 load_fn = get_view_direction;
49 } else if (loadfn=="aileronval") {
50 load_fn = get_aileronval;
51 } else if (loadfn=="elevatorval") {
52 load_fn = get_elevatorval;
53 } else if (loadfn=="elevatortrimval") {
54 load_fn = get_elev_trimval;
55 } else if (loadfn=="rudderval") {
56 load_fn = get_rudderval;
57 } else if (loadfn=="throttleval") {
58 load_fn = get_throttleval;
62 set_data_source(load_fn);
66 // As implemented, draw only correctly draws a horizontal or vertical
67 // scale. It should contain a variation that permits clock type displays.
68 // Now is supports "tickless" displays such as control surface indicators.
69 // This routine should be worked over before using. Current value would be
70 // fetched and not used if not commented out. Clearly that is intollerable.
72 void gauge_instr::draw(void)
74 float marker_xs, marker_xe;
75 float marker_ys, marker_ye;
77 int width, height, bottom_4;
83 float vmin = min_val();
84 float vmax = max_val();
85 POINT mid_scr = get_centroid();
86 float cur_value = get_value();
87 RECT scrn_rect = get_location();
88 UINT options = get_options();
90 width = scrn_rect.left + scrn_rect.right;
91 height = scrn_rect.top + scrn_rect.bottom;
92 bottom_4 = scrn_rect.bottom / 4;
94 // Draw the basic markings for the scale...
95 if (huds_vert(options)) { // Vertical scale
97 drawOneLine(scrn_rect.left, scrn_rect.top, width, scrn_rect.top);
100 drawOneLine( scrn_rect.left, height, width, height);
102 marker_xs = scrn_rect.left;
105 if (huds_left(options)) { // Read left, so line down right side
106 drawOneLine(width, scrn_rect.top, width, height);
107 marker_xs = marker_xe - scrn_rect.right / 3.0; // Adjust tick
110 if (huds_right(options)) { // Read right, so down left sides
111 drawOneLine(scrn_rect.left, scrn_rect.top, scrn_rect.left, height);
112 marker_xe = scrn_rect.left + scrn_rect.right / 3.0; // Adjust tick
115 // At this point marker x_start and x_end values are transposed.
116 // To keep this from confusing things they are now interchanged.
117 if (huds_both(options)) {
118 marker_ye = marker_xs;
119 marker_xs = marker_xe;
120 marker_xe = marker_ye;
123 // Work through from bottom to top of scale. Calculating where to put
124 // minor and major ticks.
126 if (!huds_noticks(options)) { // If not no ticks...:)
127 // Calculate x marker offsets
128 int last = (int)vmax + 1; // FloatToInt(vmax)+1;
129 i = (int)vmin; //FloatToInt(vmin);
131 for (; i < last; i++) {
132 // Calculate the location of this tick
133 marker_ys = scrn_rect.top + (i - vmin) * factor()/* +.5f*/;
135 // We compute marker_ys even though we don't know if we will use
136 // either major or minor divisions. Simpler.
138 if (div_min()) { // Minor tick marks
139 if (!(i % (int)div_min())) {
140 if (huds_left(options) && huds_right(options)) {
141 drawOneLine(scrn_rect.left, marker_ys, marker_xs - 3, marker_ys);
142 drawOneLine(marker_xe + 3, marker_ys, width, marker_ys);
144 } else if (huds_left(options)) {
145 drawOneLine(marker_xs + 3, marker_ys, marker_xe, marker_ys);
147 drawOneLine(marker_xs, marker_ys, marker_xe - 3, marker_ys);
152 // Now we work on the major divisions. Since these are also labeled
153 // and no labels are drawn otherwise, we label inside this if
156 if (div_max()) { // Major tick mark
157 if (!(i % (int)div_max())) {
158 if (huds_left(options) && huds_right(options)) {
159 drawOneLine(scrn_rect.left, marker_ys, marker_xs, marker_ys);
160 drawOneLine(marker_xe, marker_ys, width, marker_ys);
162 drawOneLine(marker_xs, marker_ys, marker_xe, marker_ys);
165 if (!huds_notext(options)) {
167 sprintf(TextScale, "%d",
168 FloatToInt(disp_val * data_scaling()/*+.5*/));
170 lenstr = getStringWidth(TextScale);
172 if (huds_left(options) && huds_right(options)) {
173 text_x = mid_scr.x - lenstr/2 ;
175 } else if (huds_left(options)) {
176 text_x = FloatToInt(marker_xs - lenstr);
178 text_x = FloatToInt(marker_xe - lenstr);
180 // Now we know where to put the text.
181 text_y = FloatToInt(marker_ys);
182 textString(text_x, text_y, TextScale, 0);
189 // Now that the scale is drawn, we draw in the pointer(s). Since labels
190 // have been drawn, text_x and text_y may be recycled. This is used
191 // with the marker start stops to produce a pointer for each side reading
193 text_y = scrn_rect.top + FloatToInt((cur_value - vmin) * factor() /*+.5f*/);
194 // text_x = marker_xs - scrn_rect.left;
196 if (huds_right(options)) {
197 glBegin(GL_LINE_STRIP);
198 glVertex2f(scrn_rect.left, text_y + 5);
199 glVertex2f(FloatToInt(marker_xe), text_y);
200 glVertex2f(scrn_rect.left, text_y - 5);
203 if (huds_left(options)) {
204 glBegin(GL_LINE_STRIP);
205 glVertex2f(width, text_y + 5);
206 glVertex2f(FloatToInt(marker_xs), text_y);
207 glVertex2f(width, text_y - 5);
210 // End if VERTICAL SCALE TYPE
212 } else { // Horizontal scale by default
214 drawOneLine(scrn_rect.left, scrn_rect.top, scrn_rect.left, height);
217 drawOneLine(width, scrn_rect.top, width, height );
219 marker_ys = scrn_rect.top; // Starting point for
220 marker_ye = height; // tick y location calcs
221 marker_xs = scrn_rect.left + (cur_value - vmin) * factor() /*+ .5f*/;
223 if (huds_top(options)) {
225 drawOneLine(scrn_rect.left, scrn_rect.top, width, scrn_rect.top);
227 marker_ye = scrn_rect.top + scrn_rect.bottom / 2.0; // Tick point adjust
229 glBegin(GL_LINE_STRIP);
230 glVertex2f(marker_xs - bottom_4, scrn_rect.top);
231 glVertex2f(marker_xs, marker_ye);
232 glVertex2f(marker_xs + bottom_4, scrn_rect.top);
236 if (huds_bottom(options)) {
238 drawOneLine(scrn_rect.left, height, width, height);
240 marker_ys = height - scrn_rect.bottom / 2.0;
243 glBegin(GL_LINE_STRIP);
244 glVertex2f(marker_xs + bottom_4, height);
245 glVertex2f(marker_xs, marker_ys );
246 glVertex2f(marker_xs - bottom_4, height);
251 int last = (int)vmax + 1; //FloatToInt(vmax)+1;
252 i = (int)vmin; //FloatToInt(vmin);
253 for (; i <last ; i++) {
255 if (!modulo() && i < min_val())
259 marker_xs = scrn_rect.left + (i - vmin) * factor()/* +.5f*/;
260 // marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5f);
262 if (!(i % (int)div_min())) {
263 // draw in ticks only if they aren't too close to the edge.
264 if (((marker_xs + 5) > scrn_rect.left)
265 || ((marker_xs - 5) < (width))) {
267 if (huds_both(options)) {
268 drawOneLine(marker_xs, scrn_rect.top, marker_xs, marker_ys - 4);
269 drawOneLine(marker_xs, marker_ye + 4, marker_xs, height);
271 } else if (huds_top(options)) {
272 drawOneLine(marker_xs, marker_ys, marker_xs, marker_ye - 4);
274 drawOneLine(marker_xs, marker_ys + 4, marker_xs, marker_ye);
281 if (!(i % (int)div_max())) {
285 disp_val += modulo();
287 disp_val = i % (int)modulo();
291 sprintf(TextScale, "%d",
292 FloatToInt(disp_val * data_scaling()/* +.5*/));
293 lenstr = getStringWidth(TextScale);
295 // Draw major ticks and text only if far enough from the edge.
296 if (((marker_xs - 10) > scrn_rect.left)
297 && ((marker_xs + 10) < width)) {
298 if (huds_both(options)) {
299 drawOneLine(marker_xs, scrn_rect.top, marker_xs, marker_ys);
300 drawOneLine(marker_xs, marker_ye, marker_xs, height);
302 if (!huds_notext(options))
303 textString(marker_xs - lenstr, marker_ys + 4, TextScale, 0);
306 drawOneLine(marker_xs, marker_ys, marker_xs, marker_ye);
308 if (!huds_notext(options)) {
309 if (huds_top(options))
310 textString(marker_xs - lenstr, height - 10, TextScale, 0);
312 textString(marker_xs - lenstr, scrn_rect.top, TextScale, 0);