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
187 float _pointer_width;
188 float _pointer_length;
190 SGSharedPtr<SGCondition> _blink_condition;
191 double _blink_interval;
192 double _blink_target; // time for next blink state change
198 // abstract base class for both moving scale and moving needle (fixed scale)
201 class HUD::Scale : public Item {
203 Scale(HUD *parent, const SGPropertyNode *, float x, float y);
204 virtual void draw ( void ) {} // No-op here. Defined in derived classes.
207 inline float factor() const { return _display_factor; }
208 inline float range_to_show() const { return _range_shown; }
211 float _major_divs; // major division marker units
212 float _minor_divs; // minor division marker units
213 unsigned int _modulo; // Roll over point
216 float _range_shown; // Width Units.
217 float _display_factor; // factor => screen units/range values.
221 class HUD::Gauge : public Scale {
223 Gauge(HUD *parent, const SGPropertyNode *, float x, float y);
229 // displays the indicated quantity on a scale that moves past the
230 // pointer. It may be horizontal or vertical.
232 class HUD::Tape : public Scale {
234 Tape(HUD *parent, const SGPropertyNode *, float x, float y);
238 void draw_vertical(float);
239 void draw_horizontal(float);
240 void draw_fixed_pointer(float, float, float, float, float, float);
241 char *format_value(float);
245 float _half_width_units;
246 bool _draw_tick_bottom;
248 bool _draw_tick_right;
249 bool _draw_tick_left;
250 bool _draw_cap_bottom;
252 bool _draw_cap_right;
254 float _marker_offset;
260 int _div_ratio; // _major_divs/_minor_divs
261 bool _odd_type; // whether to put numbers at 0/2/4 or 1/3/5
263 enum { BUFSIZE = 64 };
266 enum PointerType { FIXED, MOVING } _pointer_type;
267 enum TickType { LINE, CIRCLE } _tick_type;
268 enum TickLength { VARIABLE, CONSTANT } _tick_length;
273 class HUD::Dial : public Scale {
275 Dial(HUD *parent, const SGPropertyNode *, float x, float y);
285 class HUD::TurnBankIndicator : public Item {
287 TurnBankIndicator(HUD *parent, const SGPropertyNode *, float x, float y);
293 void draw_line(float, float, float, float);
294 void draw_tick(float angle, float r1, float r2, int side);
305 class HUD::Ladder : public Item {
307 Ladder(HUD *parent, const SGPropertyNode *, float x, float y);
312 void draw_zenith(float, float);
313 void draw_nadir(float, float);
315 void draw_text(float x, float y, const char *s, int align = 0) {
316 _locTextList.add(x, y, s, align, 0);
319 void draw_line(float x1, float y1, float x2, float y2, bool stipple = false) {
321 _locStippleLineList.add(LineSegment(x1, y1, x2, y2));
323 _locLineList.add(LineSegment(x1, y1, x2, y2));
326 enum Type { PITCH, CLIMB_DIVE } _type;
332 float _zero_bar_overlength;
333 bool _dive_bar_angle;
338 bool _dynamic_origin;
339 bool _frl; // fuselage reference line
341 bool _target_markers;
342 bool _velocity_vector;
346 bool _climb_dive_marker;
347 bool _glide_slope_marker;
350 bool _waypoint_marker;
356 // The Ladder has its own temporary display lists
357 TextList _locTextList;
358 LineList _locLineList;
359 LineList _locStippleLineList;
364 // responsible for rendering the active runway in the hud (if visible).
366 class HUD::Runway : public Item {
368 Runway(HUD *parent, const SGPropertyNode *, float x, float y);
372 void boundPoint(const sgdVec3& v, sgdVec3& m);
373 bool boundOutsidePoints(sgdVec3& v, sgdVec3& m);
374 bool drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3& p1, const sgdVec3& p2);
376 FGRunway* get_active_runway();
377 void get_rwy_points(sgdVec3 *points);
380 SGPropertyNode_ptr _agl;
381 sgdVec3 _points3d[6], _points2d[6];
384 double _arrow_scale; // scales of runway indication arrow
385 double _arrow_radius;
386 double _line_scale; // maximum line scale
387 double _scale_dist; // distance where to start scaling the lines
388 double _default_pitch;
389 double _default_heading;
392 unsigned short _stipple_out; // stipple pattern of the outline of the runway
393 unsigned short _stipple_center; // stipple pattern of the center line of the runway
394 bool _draw_arrow; // draw arrow when runway is not visible in HUD
395 bool _draw_arrow_always; // always draws arrow
396 float _left, _right, _top, _bottom;
400 class HUD::AimingReticle : public Item {
402 AimingReticle(HUD *parent, const SGPropertyNode *, float x, float y);
406 SGSharedPtr<SGCondition> _active_condition; // stadiametric (true) or standby (false)
407 SGSharedPtr<SGCondition> _tachy_condition; // tachymetric (true) or standby (false)
408 SGSharedPtr<SGCondition> _align_condition; // tachymetric (true) or standby (false)
410 Input _diameter; // inner/outer radius relation