X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCockpit%2Fhud.hxx;h=0ce27ec3003883ce621793cc2cb23a435f16090b;hb=b07ad149aebeb1d060bc9a0d505fdc1ca1081654;hp=fe36c250fe1d41d218c2d12009e0a3b674a41ce0;hpb=8a482acf8f224fa8888a438becbc346cbbb5ca53;p=flightgear.git diff --git a/src/Cockpit/hud.hxx b/src/Cockpit/hud.hxx index fe36c250f..0ce27ec30 100644 --- a/src/Cockpit/hud.hxx +++ b/src/Cockpit/hud.hxx @@ -34,21 +34,21 @@ # include #endif -#ifdef HAVE_WINDOWS_H -# include +#ifdef __CYGWIN__ +#include #endif #include #include -//#ifdef HAVE_VALUES_H -//# include // for MAXINT -//#endif - #include // for_each() #include // STL vector #include // STL double ended queue -#include STL_FSTREAM +#include + +namespace osg { + class State; +} #include #include @@ -61,16 +61,13 @@ #include
#include
#include
-#include -#include +class FGRunway; -SG_USING_STD(deque); -SG_USING_STD(vector); -SG_USING_NAMESPACE(std); +using std::deque; +using std::vector; -//#define float_to_int(v) SGMiscf::roundToInt(v) -#define float_to_int(v) int(floorf(v + 0.5f)) +#define float_to_int(v) SGMiscf::roundToInt(v) // some of Norman's crazy optimizations. :-) @@ -107,32 +104,6 @@ enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ; #define HUDS_DECITICS 0x0040 #define HUDS_NOTEXT 0x0080 -// Ladder orientaion -// #define HUD_VERTICAL 1 -// #define HUD_HORIZONTAL 2 -// #define HUD_FREEFLOAT 3 - -// Ladder orientation modes -// #define HUD_LEFT 1 -// #define HUD_RIGHT 2 -// #define HUD_TOP 1 -// #define HUD_BOTTOM 2 -// #define HUD_V_LEFT 1 -// #define HUD_V_RIGHT 2 -// #define HUD_H_TOP 1 -// #define HUD_H_BOTTOM 2 - - -// Ladder sub-types -// #define HUD_LIM 1 -// #define HUD_NOLIM 2 -// #define HUD_CIRC 3 - -// #define HUD_INSTR_LADDER 1 -// #define HUD_INSTR_CLADDER 2 -// #define HUD_INSTR_HORIZON 3 -// #define HUD_INSTR_LABEL 4 - // in cockpit.cxx extern float get_throttleval ( void ); extern float get_aileronval ( void ); @@ -162,10 +133,8 @@ extern float get_climb_rate ( void ); extern float get_mach( void ); extern char *coord_format_lat(float); extern char *coord_format_lon(float); -//extern char *coord_format_latlon(float latitude, float longitude); // cockpit.cxx // $$$ begin - added, VS Renganathan, 13 Oct 2K -// #define FIGHTER_HUD extern float get_anzg (void); extern float get_Vx (void); extern float get_Vy (void); @@ -206,7 +175,6 @@ extern float get_aux18(void); // $$$ end - added, VS Renganathan, 13 Oct 2K extern char *get_formated_gmt_time( void ); -extern void fgHUDReshape(void); enum hudinstype{ HUDno_instr, HUDscale, @@ -265,26 +233,22 @@ extern float HUD_matrix[16]; class fgText { private: float x, y; - char msg[64]; + string msg; + bool digit; + // seems unused + public: - int digit; - fgText(float x = 0, float y = 0, char *c = NULL,int digits=0): x(x), y(y) - { - strcpy(msg,c); - digit=digits; - } + fgText(float x, float y, const string& c, bool digits=false): x(x), y(y), msg( c), digit( digits) {}; fgText( const fgText & image ) - : x(image.x), y(image.y),digit(image.digit) { strcpy(msg,image.msg); } - - fgText& operator = ( const fgText & image ) { // seems unused - strcpy(msg,image.msg); x = image.x; y = image.y;digit=image.digit; - return *this; - } - - ~fgText() { msg[0]='\0'; } // used but useless - - int getStringWidth ( char *str ) + : x(image.x), y(image.y), msg(image.msg), digit(image.digit) { } + + fgText& operator = ( const fgText & image ) { + x = image.x; y = image.y; msg= image.msg; digit = image.digit; + return *this; + } + + static int getStringWidth ( const char *str ) { if ( HUDtext && str ) { float r, l ; @@ -294,11 +258,11 @@ public: return 0 ; } - int StringWidth (void ) + int StringWidth () { - if ( HUDtext && strlen( msg )) { + if ( HUDtext && msg != "") { float r, l ; - HUD_Font->getBBox ( msg, HUD_TextSize, 0, &l, &r, NULL, NULL ) ; + HUD_Font->getBBox ( msg.c_str(), HUD_TextSize, 0, &l, &r, NULL, NULL ) ; return float_to_int( r - l ); } return 0 ; @@ -308,56 +272,50 @@ public: // according to MIL Standards for example Altitude above 10000 ft // is shown as 10ooo. - void Draw(fntRenderer *fnt,int digits) { - if (digits==1) { + void Draw(fntRenderer *fnt) { + if (digit) { int c=0,i=0; - char *t=msg; + int p=4; - if (t[0]=='-') { + if (msg[0]=='-') { //if negative value then increase the c and p values //for '-' sign. c++; p++; } - char *tmp=msg; - while (tmp[i]!='\0') { - if ((tmp[i]>='0') && (tmp[i]<='9')) + + for (string::size_type i = 0; i < msg.size(); i++) { + if ((msg[i]>='0') && (msg[i]<='9')) c++; - i++; } float orig_size = fnt->getPointSize(); if (c>p) { fnt->setPointSize(HUD_TextSize * 0.8); - int p1=c-3; - char *tmp1=msg+p1; - int p2=p1*8; + int p2=(c-3)*8; //advance to the last 3 digits fnt->start2f(x+p2,y); - fnt->puts(tmp1); + fnt->puts(msg.c_str() + c - 3); // display last 3 digits fnt->setPointSize(HUD_TextSize * 1.2); - char tmp2[64]; - strncpy(tmp2,msg,p1); - tmp2[p1]='\0'; - + fnt->start2f(x,y); - fnt->puts(tmp2); + fnt->puts(msg.substr(0,c-3).c_str()); } else { fnt->setPointSize(HUD_TextSize * 1.2); fnt->start2f( x, y ); - fnt->puts(tmp); + fnt->puts(msg.c_str()); } fnt->setPointSize(orig_size); } else { - //if digits not equal to 1 + //if digits not true fnt->start2f( x, y ); - fnt->puts( msg ) ; + fnt->puts( msg.c_str()) ; } } void Draw() { - guiFnt.drawString( msg, float_to_int(x), float_to_int(y) ); + guiFnt.drawString( msg.c_str(), float_to_int(x), float_to_int(y) ); } }; @@ -366,7 +324,7 @@ class fgLineList { public: fgLineList( void ) {} void add( const fgLineSeg2D& seg ) { List.push_back(seg); } - void erase( void ) { List.erase( List.begin(), List.end() ); } + void erase( void ) { List.clear();} void draw( void ) { glBegin(GL_LINES); for_each( List.begin(), List.end(), DrawLineSeg2D()); @@ -382,7 +340,7 @@ public: void setFont( fntRenderer *Renderer ) { Font = Renderer; } void add( const fgText& String ) { List.push_back(String); } - void erase( void ) { List.erase( List.begin(), List.end() ); } + void erase( void ) { List.clear(); } void draw( void ); }; @@ -409,7 +367,7 @@ extern fgLineList HUD_LineList; extern fgLineList HUD_StippleLineList; -class instr_item { // An Abstract Base Class (ABC) +class instr_item : public SGReferenced { // An Abstract Base Class (ABC) private: static UINT instances; // More than 64K instruments? Nah! static int brightness; @@ -484,7 +442,7 @@ public: { HUD_StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2)); } - void TextString( char *msg, float x, float y,int digit ) + void TextString( char *msg, float x, float y, bool digit ) { HUD_TextList.add(fgText(x, y, msg,digit)); } @@ -498,17 +456,7 @@ public: return 0 ; } - //code to draw ticks as small circles - void drawOneCircle(float x1, float y1, float r) - { - glBegin(GL_LINE_LOOP); // Use polygon to approximate a circle - 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(); - } + }; @@ -523,9 +471,7 @@ class HUDdraw { }; -extern deque< instr_item *> HUD_deque; extern int HUD_style; -//extern hud_deque_type HUD_deque; // instr_item This class has no other purpose than to maintain // a linked list of instrument and derived class @@ -535,12 +481,11 @@ extern int HUD_style; class instr_label : public instr_item { private: const char *pformat; - const char *pre_str; - const char *post_str; + fgLabelJust justify; int fontSize; int blink; - char format_buffer[80]; + string format_buffer; bool lat; bool lon; bool lbox; @@ -563,7 +508,7 @@ private: bool drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3& p1, const sgdVec3& p2); void drawArrow(); - bool get_active_runway(FGRunway& rwy); + FGRunway* get_active_runway(); void get_rwy_points(sgdVec3 *points); void setLineWidth(void); @@ -571,7 +516,7 @@ private: double mm[16],pm[16], arrowScale, arrowRad, lnScale; double scaleDist, default_pitch, default_heading; GLint view[4]; - FGRunway runway; + FGRunway* runway; FGViewer* cockpit_view; unsigned short stippleOut, stippleCen; bool drawIA, drawIAAlways; @@ -789,27 +734,12 @@ public: }; -//using namespace std; -//deque * Hdeque_ptr; - extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ ); extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ ); -extern void fgUpdateHUD( void ); -extern void fgUpdateHUD( GLfloat x_start, GLfloat y_start, +extern void fgUpdateHUD( osg::State* ); +extern void fgUpdateHUD( osg::State*, GLfloat x_start, GLfloat y_start, GLfloat x_end, GLfloat y_end ); -/* -bool AddHUDInstrument( instr_item *pBlackBox ); -void DrawHUD ( void ); -bool DamageInstrument( INSTR_HANDLE unit ); -bool RepairInstrument( INSTR_HANDLE unit ); - - -void fgUpdateHUD ( Hptr hud ); -void fgUpdateHUD2( Hptr hud ); // Future use? -void fgHUDSetTimeMode( Hptr hud, int time_of_day ); -*/ -