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 _scr_span; // Working values for draw;
171 class HUD::Label : public Item {
173 Label(HUD *parent, const SGPropertyNode *, float x, float y);
182 int _halign; // HUDText alignment
184 float _pointer_width;
185 float _pointer_length;
187 SGSharedPtr<SGCondition> _blink_condition;
188 double _blink_interval;
189 double _blink_target; // time for next blink state change
195 // abstract base class for both moving scale and moving needle (fixed scale)
198 class HUD::Scale : public Item {
200 Scale(HUD *parent, const SGPropertyNode *, float x, float y);
201 virtual void draw ( void ) {} // No-op here. Defined in derived classes.
204 inline float factor() const { return _display_factor; }
205 inline float range_to_show() const { return _range_shown; }
208 float _major_divs; // major division marker units
209 float _minor_divs; // minor division marker units
210 unsigned int _modulo; // Roll over point
213 float _range_shown; // Width Units.
214 float _display_factor; // factor => screen units/range values.
218 class HUD::Gauge : public Scale {
220 Gauge(HUD *parent, const SGPropertyNode *, float x, float y);
226 // displays the indicated quantity on a scale that moves past the
227 // pointer. It may be horizontal or vertical.
229 class HUD::Tape : public Scale {
231 Tape(HUD *parent, const SGPropertyNode *, float x, float y);
235 void draw_vertical(float);
236 void draw_horizontal(float);
237 void draw_fixed_pointer(float, float, float, float, float, float);
238 char *format_value(float);
242 float _half_width_units;
243 bool _draw_tick_bottom;
245 bool _draw_tick_right;
246 bool _draw_tick_left;
247 bool _draw_cap_bottom;
249 bool _draw_cap_right;
251 float _marker_offset;
257 int _div_ratio; // _major_divs/_minor_divs
258 bool _odd_type; // whether to put numbers at 0/2/4 or 1/3/5
260 enum { BUFSIZE = 64 };
263 enum PointerType { FIXED, MOVING } _pointer_type;
264 enum TickType { LINE, CIRCLE } _tick_type;
265 enum TickLength { VARIABLE, CONSTANT } _tick_length;
270 class HUD::Dial : public Scale {
272 Dial(HUD *parent, const SGPropertyNode *, float x, float y);
282 class HUD::TurnBankIndicator : public Item {
284 TurnBankIndicator(HUD *parent, const SGPropertyNode *, float x, float y);
290 void draw_line(float, float, float, float);
291 void draw_tick(float angle, float r1, float r2, int side);
302 class HUD::Ladder : public Item {
304 Ladder(HUD *parent, const SGPropertyNode *, float x, float y);
309 void draw_zenith(float, float);
310 void draw_nadir(float, float);
312 void draw_text(float x, float y, const char *s, int align = 0) {
313 _locTextList.add(x, y, s, align, 0);
316 void draw_line(float x1, float y1, float x2, float y2, bool stipple = false) {
318 _locStippleLineList.add(LineSegment(x1, y1, x2, y2));
320 _locLineList.add(LineSegment(x1, y1, x2, y2));
323 enum Type { PITCH, CLIMB_DIVE } _type;
329 float _zero_bar_overlength;
330 bool _dive_bar_angle;
335 bool _dynamic_origin;
336 bool _frl; // fuselage reference line
338 bool _target_markers;
339 bool _velocity_vector;
343 bool _climb_dive_marker;
344 bool _glide_slope_marker;
347 bool _waypoint_marker;
353 // The Ladder has its own temporary display lists
354 TextList _locTextList;
355 LineList _locLineList;
356 LineList _locStippleLineList;
361 // responsible for rendering the active runway in the hud (if visible).
363 class HUD::Runway : public Item {
365 Runway(HUD *parent, const SGPropertyNode *, float x, float y);
369 void boundPoint(const sgdVec3& v, sgdVec3& m);
370 bool boundOutsidePoints(sgdVec3& v, sgdVec3& m);
371 bool drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3& p1, const sgdVec3& p2);
373 FGRunway* get_active_runway();
374 void get_rwy_points(sgdVec3 *points);
377 SGPropertyNode_ptr _agl;
378 sgdVec3 _points3d[6], _points2d[6];
381 double _arrow_scale; // scales of runway indication arrow
382 double _arrow_radius;
383 double _line_scale; // maximum line scale
384 double _scale_dist; // distance where to start scaling the lines
385 double _default_pitch;
386 double _default_heading;
389 unsigned short _stipple_out; // stipple pattern of the outline of the runway
390 unsigned short _stipple_center; // stipple pattern of the center line of the runway
391 bool _draw_arrow; // draw arrow when runway is not visible in HUD
392 bool _draw_arrow_always; // always draws arrow
393 float _left, _right, _top, _bottom;
397 class HUD::AimingReticle : public Item {
399 AimingReticle(HUD *parent, const SGPropertyNode *, float x, float y);
403 SGSharedPtr<SGCondition> _active_condition; // stadiametric (true) or standby (false)
404 SGSharedPtr<SGCondition> _tachy_condition; // tachymetric (true) or standby (false)
405 SGSharedPtr<SGCondition> _align_condition; // tachymetric (true) or standby (false)
407 Input _diameter; // inner/outer radius relation