X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2FHUD%2FHUD.hxx;h=678b197762d731c4175752a0c8194b9774aca8aa;hb=df2d876f7273887b29dbce5d7cc7b46c49000d3b;hp=740c73569b436a49b050029b84be824f5ae5395b;hpb=c6cbef666a611e66401bbd4a988c695242749cb3;p=flightgear.git diff --git a/src/Instrumentation/HUD/HUD.hxx b/src/Instrumentation/HUD/HUD.hxx index 740c73569..678b19776 100644 --- a/src/Instrumentation/HUD/HUD.hxx +++ b/src/Instrumentation/HUD/HUD.hxx @@ -204,10 +204,6 @@ public: float x, y; } Point; - typedef struct { - float top, bottom, left, right; - } Rect; - // called from Main/renderer.cxx to draw 2D and 3D HUD void draw(); @@ -315,7 +311,7 @@ public: _offset = n->getFloatValue("offset", offset); _min = n->getFloatValue("min", min); _max = n->getFloatValue("max", max); - _coeff = n->getFloatValue("damp", 0.0); + _coeff = 1.0 - 1.0 / powf(10, fabsf(n->getFloatValue("damp", 0.0))); SGPropertyNode *p = ((SGPropertyNode *)n)->getNode("property", false); if (p) { const char *path = p->getStringValue(); @@ -338,13 +334,14 @@ public: _damped = f; if (_coeff > 0.0f) f = _damped = f * (1.0f - _coeff) + _damped * _coeff; - return f < _min ? _min : f > _max ? _max : f; + return clamp(f); } inline float isValid() const { return _valid; } inline float min() const { return _min; } inline float max() const { return _max; } inline float factor() const { return _factor; } + float clamp(float v) const { return v < _min ? _min : v > _max ? _max : v; } void set_min(float m, bool force = true) { if (force || _min == -SGLimitsf::max()) @@ -368,7 +365,7 @@ private: -class HUD::Item { // An Abstract Base Class (ABC) +class HUD::Item { public: Item(HUD *parent, const SGPropertyNode *, float x = 0.0f, float y = 0.0f); virtual ~Item () {} @@ -376,63 +373,33 @@ public: virtual bool isEnabled(); protected: - - inline Rect get_location() const { return _scrn_pos; } inline float get_span() const { return _scr_span; } inline Point get_centroid() const { return _mid_span; } inline int get_digits() const { return _digits; } - inline float get_x() const { return _scrn_pos.left; } - inline float get_y() const { return _scrn_pos.top; } - inline float get_width() const { return _scrn_pos.right; } - inline float get_height() const { return _scrn_pos.bottom; } - - inline bool option_vert() const { return _options & VERT; } - inline bool option_left() const { return _options & LEFT; } - inline bool option_right() const { return _options & RIGHT; } + inline bool option_vert() const { return (_options & VERT) == VERT; } + inline bool option_left() const { return (_options & LEFT) == LEFT; } + inline bool option_right() const { return (_options & RIGHT) == RIGHT; } inline bool option_both() const { return (_options & BOTH) == BOTH; } - inline bool option_noticks() const { return _options & NOTICKS; } - inline bool option_notext() const { return _options & NOTEXT; } - inline bool option_top() const { return _options & TOP; } - inline bool option_bottom() const { return _options & BOTTOM; } - - void draw_line( float x1, float y1, float x2, float y2) { - _hud->_line_list.add(LineSegment(x1, y1, x2, y2)); - } - - void draw_stipple_line( float x1, float y1, float x2, float y2) { - _hud->_stipple_line_list.add(LineSegment(x1, y1, x2, y2)); - } - - void draw_text( float x, float y, char *msg, int digit) { - _hud->_text_list.add(HUDText(x, y, msg, digit)); - } - - float text_width(char *str) const { - assert(_hud->_font_renderer); - float r, l; - _hud->_font->getBBox(str, _hud->_font_size, 0, &l, &r, 0, 0); - return r - l; - } - - void draw_circle(float x1, float y1, float r) const { - glBegin(GL_LINE_LOOP); - for (int count = 0; count < 25; count++) { - float cosine = r * cos(count * 2 * SG_PI / 10.0); - float sine = r * sin(count * 2 * SG_PI / 10.0); - glVertex2f(cosine + x1, sine + y1); - } - glEnd(); - } + inline bool option_noticks() const { return (_options & NOTICKS) == NOTICKS; } + inline bool option_notext() const { return (_options & NOTEXT) == NOTEXT; } + inline bool option_top() const { return (_options & TOP) == TOP; } + inline bool option_bottom() const { return (_options & BOTTOM) == BOTTOM; } + + void draw_line( float x1, float y1, float x2, float y2); + void draw_stipple_line( float x1, float y1, float x2, float y2); + void draw_text( float x, float y, char *msg, int digit); + float text_width(char *str) const; + void draw_circle(float x1, float y1, float r) const; + void draw_bullet(float, float, float); HUD *_hud; string _name; int _options; + float _x, _y, _w, _h; private: SGCondition *_condition; - Rect _scrn_pos; // Framing - affects scale dimensions - // and orientation. Vert vs Horz, etc. float _disp_factor; // Multiply by to get numbers shown on scale. float _scr_span; // Working values for draw; Point _mid_span; @@ -491,17 +458,17 @@ public: protected: inline unsigned int modulo() const { return _modulo; } - inline float factor() const { return scale_factor; } - inline float range_to_show() const { return _range_shown; } + inline float factor() const { return _display_factor; } + inline float range_to_show() const { return _range_shown; } Input _input; - unsigned int _major_divs; // major division marker units - unsigned int _minor_divs; // minor division marker units + float _major_divs; // major division marker units + float _minor_divs; // minor division marker units private: float _range_shown; // Width Units. - float scale_factor; // factor => screen units/range values. - unsigned int _modulo; // Roll over point + float _display_factor; // factor => screen units/range values. + unsigned int _modulo; // Roll over point }; @@ -522,27 +489,26 @@ public: virtual void draw(); protected: - void circle(float, float, float); void fixed(float, float, float, float, float, float); void zoomed_scale(int, int); private: - float val_span; - float half_width_units; - bool draw_tick_bottom; - bool draw_tick_top; - bool draw_tick_right; - bool draw_tick_left; - bool draw_cap_bottom; - bool draw_cap_top; - bool draw_cap_right; - bool draw_cap_left; - float marker_offset; - bool pointer; - string pointer_type; - string tick_type; - string tick_length; - int zoom; + float _val_span; + float _half_width_units; + bool _draw_tick_bottom; + bool _draw_tick_top; + bool _draw_tick_right; + bool _draw_tick_left; + bool _draw_cap_bottom; + bool _draw_cap_top; + bool _draw_cap_right; + bool _draw_cap_left; + float _marker_offset; + bool _pointer; + int _zoom; + enum PointerType { FIXED, MOVING } _pointer_type; + enum TickType { LINE, CIRCLE } _tick_type; + enum TickLength { VARIABLE, CONSTANT } _tick_length; }; @@ -599,15 +565,14 @@ private: Input _pitch; Input _roll; enum Type { PITCH, CLIMB_DIVE } _type; - unsigned int width_units; + float _width_units; int div_units; - unsigned int minor_div; unsigned int label_pos; unsigned int _scr_hole; float _vmax; float _vmin; float _compression; - bool _frl; + bool _frl; // fuselage reference line bool _target_spot; bool _velocity_vector; bool _drift_marker; @@ -640,8 +605,7 @@ public: private: void boundPoint(const sgdVec3& v, sgdVec3& m); bool boundOutsidePoints(sgdVec3& v, sgdVec3& m); - bool drawLine(const sgdVec3& a1, const sgdVec3& a2, - const sgdVec3& p1, const sgdVec3& p2); + bool drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3& p1, const sgdVec3& p2); void drawArrow(); bool get_active_runway(FGRunway& rwy); void get_rwy_points(sgdVec3 *points); @@ -664,7 +628,7 @@ private: unsigned short _stipple_center; // stipple pattern of the center line of the runway bool _draw_arrow; // draw arrow when runway is not visible in HUD bool _draw_arrow_always; // always draws arrow - Rect _location; + float _left, _right, _top, _bottom; Point _center; };