1 // HUD_private.hxx -- Intenral delcerations for the HUD
3 // Written by Michele America, started September 1997.
5 // Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
6 // Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
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.
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.
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.
22 #ifndef _HUD_PRIVATE_HXX
23 #define _HUD_PRIVATE_HXX
25 #include <simgear/compiler.h>
26 #include <simgear/props/condition.hxx>
34 #include <simgear/math/SGLimits.hxx>
35 #include <simgear/constants.h>
36 #include <simgear/props/props.hxx>
38 #include <plib/sg.h> // for lingering sgdVec3 usage below
48 ClipBox(const SGPropertyNode *, float xoffset = 0, float yoffset = 0);
55 SGConstPropertyNode_ptr _top_node;
56 SGConstPropertyNode_ptr _bot_node;
57 SGConstPropertyNode_ptr _left_node;
58 SGConstPropertyNode_ptr _right_node;
68 Input(const SGPropertyNode *n, float factor = 1.0, float offset = 0.0,
69 float min = -SGLimitsf::max(), float max = SGLimitsf::max());
71 bool getBoolValue() const {
73 return _property->getBoolValue();
76 const char *getStringValue() const {
78 return _property->getStringValue();
81 float getFloatValue() {
83 float f = _property->getFloatValue() * _factor + _offset;
84 if (_damped == SGLimitsf::max())
87 f = _damped = f * (1.0f - _coeff) + _damped * _coeff;
91 inline float isValid() const { return _valid; }
92 inline float min() const { return _min; }
93 inline float max() const { return _max; }
94 inline float factor() const { return _factor; }
95 float clamp(float v) const { return v < _min ? _min : v > _max ? _max : v; }
97 void set_min(float m, bool force = true) {
98 if (force || _min == -SGLimitsf::max())
101 void set_max(float m, bool force = true) {
102 if (force || _max == SGLimitsf::max())
108 SGConstPropertyNode_ptr _property;
121 Item(HUD *parent, const SGPropertyNode *, float x = 0.0f, float y = 0.0f);
123 virtual void draw() = 0;
124 virtual bool isEnabled();
137 Format check_format(const char *) const;
138 inline float get_span() const { return _scr_span; }
139 inline int get_digits() const { return _digits; }
141 inline bool option_vert() const { return (_options & VERTICAL) == VERTICAL; }
142 inline bool option_left() const { return (_options & LEFT) == LEFT; }
143 inline bool option_right() const { return (_options & RIGHT) == RIGHT; }
144 inline bool option_both() const { return (_options & BOTH) == BOTH; }
145 inline bool option_noticks() const { return (_options & NOTICKS) == NOTICKS; }
146 inline bool option_notext() const { return (_options & NOTEXT) == NOTEXT; }
147 inline bool option_top() const { return (_options & TOP) == TOP; }
148 inline bool option_bottom() const { return (_options & BOTTOM) == BOTTOM; }
150 void draw_line(float x1, float y1, float x2, float y2);
151 void draw_stipple_line(float x1, float y1, float x2, float y2);
152 void draw_text(float x, float y, const char *msg, int align = 0, int digit = 0);
153 void draw_circle(float x1, float y1, float r) const;
154 void draw_arc(float x1, float y1, float t0, float t1, float r) const;
155 void draw_bullet(float, float, float);
160 float _x, _y, _w, _h;
161 float _center_x, _center_y;
164 SGSharedPtr<SGCondition> _condition;
165 float _disp_factor; // Multiply by to get numbers shown on scale.
166 float _scr_span; // Working values for draw;
172 class HUD::Label : public Item {
174 Label(HUD *parent, const SGPropertyNode *, float x, float y);
183 int _halign; // HUDText alignment
185 float _pointer_width;
186 float _pointer_length;
188 SGSharedPtr<SGCondition> _blink_condition;
189 double _blink_interval;
190 double _blink_target; // time for next blink state change
196 // abstract base class for both moving scale and moving needle (fixed scale)
199 class HUD::Scale : public Item {
201 Scale(HUD *parent, const SGPropertyNode *, float x, float y);
202 virtual void draw ( void ) {} // No-op here. Defined in derived classes.
205 inline float factor() const { return _display_factor; }
206 inline float range_to_show() const { return _range_shown; }
209 float _major_divs; // major division marker units
210 float _minor_divs; // minor division marker units
211 unsigned int _modulo; // Roll over point
214 float _range_shown; // Width Units.
215 float _display_factor; // factor => screen units/range values.
219 class HUD::Gauge : public Scale {
221 Gauge(HUD *parent, const SGPropertyNode *, float x, float y);
227 // displays the indicated quantity on a scale that moves past the
228 // pointer. It may be horizontal or vertical.
230 class HUD::Tape : public Scale {
232 Tape(HUD *parent, const SGPropertyNode *, float x, float y);
236 void draw_vertical(float);
237 void draw_horizontal(float);
238 void draw_fixed_pointer(float, float, float, float, float, float);
239 char *format_value(float);
243 float _half_width_units;
244 bool _draw_tick_bottom;
246 bool _draw_tick_right;
247 bool _draw_tick_left;
248 bool _draw_cap_bottom;
250 bool _draw_cap_right;
252 float _marker_offset;
258 int _div_ratio; // _major_divs/_minor_divs
259 bool _odd_type; // whether to put numbers at 0/2/4 or 1/3/5
261 enum { BUFSIZE = 64 };
264 enum PointerType { FIXED, MOVING } _pointer_type;
265 enum TickType { LINE, CIRCLE } _tick_type;
266 enum TickLength { VARIABLE, CONSTANT } _tick_length;
271 class HUD::Dial : public Scale {
273 Dial(HUD *parent, const SGPropertyNode *, float x, float y);
283 class HUD::TurnBankIndicator : public Item {
285 TurnBankIndicator(HUD *parent, const SGPropertyNode *, float x, float y);
291 void draw_line(float, float, float, float);
292 void draw_tick(float angle, float r1, float r2, int side);
303 class HUD::Ladder : public Item {
305 Ladder(HUD *parent, const SGPropertyNode *, float x, float y);
310 void draw_zenith(float, float);
311 void draw_nadir(float, float);
313 void draw_text(float x, float y, const char *s, int align = 0) {
314 _locTextList.add(x, y, s, align, 0);
317 void draw_line(float x1, float y1, float x2, float y2, bool stipple = false) {
319 _locStippleLineList.add(LineSegment(x1, y1, x2, y2));
321 _locLineList.add(LineSegment(x1, y1, x2, y2));
324 enum Type { PITCH, CLIMB_DIVE } _type;
330 float _zero_bar_overlength;
331 bool _dive_bar_angle;
336 bool _dynamic_origin;
337 bool _frl; // fuselage reference line
339 bool _target_markers;
340 bool _velocity_vector;
344 bool _climb_dive_marker;
345 bool _glide_slope_marker;
348 bool _waypoint_marker;
354 // The Ladder has its own temporary display lists
355 TextList _locTextList;
356 LineList _locLineList;
357 LineList _locStippleLineList;
362 // responsible for rendering the active runway in the hud (if visible).
364 class HUD::Runway : public Item {
366 Runway(HUD *parent, const SGPropertyNode *, float x, float y);
370 void boundPoint(const sgdVec3& v, sgdVec3& m);
371 bool boundOutsidePoints(sgdVec3& v, sgdVec3& m);
372 bool drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3& p1, const sgdVec3& p2);
374 FGRunway* get_active_runway();
375 void get_rwy_points(sgdVec3 *points);
378 SGPropertyNode_ptr _agl;
379 sgdVec3 _points3d[6], _points2d[6];
382 double _arrow_scale; // scales of runway indication arrow
383 double _arrow_radius;
384 double _line_scale; // maximum line scale
385 double _scale_dist; // distance where to start scaling the lines
386 double _default_pitch;
387 double _default_heading;
390 unsigned short _stipple_out; // stipple pattern of the outline of the runway
391 unsigned short _stipple_center; // stipple pattern of the center line of the runway
392 bool _draw_arrow; // draw arrow when runway is not visible in HUD
393 bool _draw_arrow_always; // always draws arrow
394 float _left, _right, _top, _bottom;
398 class HUD::AimingReticle : public Item {
400 AimingReticle(HUD *parent, const SGPropertyNode *, float x, float y);
404 SGSharedPtr<SGCondition> _active_condition; // stadiametric (true) or standby (false)
405 SGSharedPtr<SGCondition> _tachy_condition; // tachymetric (true) or standby (false)
406 SGSharedPtr<SGCondition> _align_condition; // tachymetric (true) or standby (false)
408 Input _diameter; // inner/outer radius relation