Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hud.cpp File Reference
#include <ctype.h>
#include "gfxlib.h"
#include "cmd/unit_generic.h"
#include "hud.h"
#include "lin_time.h"
#include "file_main.h"
#include "gfx/aux_texture.h"
#include "vs_globals.h"
#include "config_xml.h"
#include "xml_support.h"
#include "cmd/base.h"
#include "gldrv/gl_globals.h"

Go to the source code of this file.

Functions

static bool isInside ()
 
const std::string & getStringFont (bool &changed, bool force_inside=false, bool whatinside=false)
 
const std::string & getStringFontForHeight (bool &changed)
 
void * getFont (bool forceinside=false, bool whichinside=false)
 
float getFontHeight ()
 
static unsigned intCreateLists ()
 
static unsigned char HexToChar (char a)
 
static unsigned char TwoCharToByte (char a, char b)
 
static float TwoCharToFloat (char a, char b)
 
void DrawSquare (float left, float right, float top, float bot)
 
float charWidth (char c, float myFontMetrics)
 
bool doNewLine (string::const_iterator begin, string::const_iterator end, float cur_pos, float end_pos, float metrics, bool last_row)
 

Function Documentation

float charWidth ( char  c,
float  myFontMetrics 
)

Definition at line 193 of file hud.cpp.

References getFont(), VegaConfig::getVariable(), XMLSupport::parse_bool(), and vs_config.

Referenced by PaintText::addFragment(), doNewLine(), and PaintText::parseFragmentsWithWordBreak().

194 {
195  static bool use_bit = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "high_quality_font", "false" ) );
196  void *fnt = use_bit ? getFont() : GLUT_STROKE_ROMAN;
197  float charwid = use_bit ? glutBitmapWidth( fnt, c ) : glutStrokeWidth( fnt, c );
198  float dubyawid = use_bit ? glutBitmapWidth( fnt, 'W' ) : glutStrokeWidth( fnt, 'W' );
199  return charwid*myFontMetrics/dubyawid;
200 }
static unsigned int* CreateLists ( )
static

Definition at line 136 of file hud.cpp.

References getFont(), VegaConfig::getVariable(), GFXCreateList(), GFXEndList(), i, XMLSupport::parse_bool(), and vs_config.

137 {
138  static unsigned int lists[256] = {0};
139  void *fnt0 = getFont( true, false );
140  void *fnt1 = getFont( true, true );
141  static bool use_bit = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "high_quality_font", "false" ) );
142  static bool use_display_lists = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "text_display_lists", "true" ) );
143  if (use_display_lists) {
144  for (unsigned int i = 32; i < 256; i++)
145  if ( (i < 128) || (i >= 128+32) ) {
146  lists[i] = GFXCreateList();
147  if (use_bit)
148  glutBitmapCharacter( i < 128 ? fnt0 : fnt1, i%128 );
149  else
150  glutStrokeCharacter( GLUT_STROKE_ROMAN, i%128 );
151  if ( !GFXEndList() )
152  lists[i] = 0;
153  }
154  }
155  return lists;
156 }
bool doNewLine ( string::const_iterator  begin,
string::const_iterator  end,
float  cur_pos,
float  end_pos,
float  metrics,
bool  last_row 
)

Definition at line 202 of file hud.cpp.

References charWidth().

208 {
209  if (*begin == '\n')
210  return true;
211  if (*begin == ' ' && !last_row) {
212  cur_pos += charWidth( *begin, metrics );
213  *begin++;
214  for (; begin != end && cur_pos <= end_pos && !isspace( *begin ); begin++)
215  cur_pos += charWidth( *begin, metrics );
216  return cur_pos > end_pos;
217  }
218  return cur_pos+( (begin+1 != end) ? charWidth( *begin, metrics ) : 0 ) >= end_pos;
219 }
void DrawSquare ( float  left,
float  right,
float  top,
float  bot 
)

Definition at line 179 of file hud.cpp.

References GFXBegin(), GFXEnd(), GFXQUAD, and GFXVertex3f().

180 {
181  GFXBegin( GFXQUAD );
182  GFXVertex3f( left, top, 0 );
183  GFXVertex3f( left, bot, 0 );
184  GFXVertex3f( right, bot, 0 );
185  GFXVertex3f( right, top, 0 );
186  GFXVertex3f( right, top, 0 );
187  GFXVertex3f( right, bot, 0 );
188  GFXVertex3f( left, bot, 0 );
189  GFXVertex3f( left, top, 0 );
190  GFXEnd();
191 }
void* getFont ( bool  forceinside = false,
bool  whichinside = false 
)

Definition at line 68 of file hud.cpp.

References changed, and getStringFont().

Referenced by charWidth(), and CreateLists().

69 {
70  bool changed = false;
71  std::string whichfont = getStringFont( changed, forceinside, whichinside );
72  static void *retval = NULL;
73  if (changed) retval = NULL;
74  if (retval == NULL) {
75  if (whichfont == "helvetica10")
76  retval = GLUT_BITMAP_HELVETICA_10;
77  else if (whichfont == "helvetica18")
78  retval = GLUT_BITMAP_HELVETICA_18;
79  else if (whichfont == "times24")
80  retval = GLUT_BITMAP_TIMES_ROMAN_24;
81  else if (whichfont == "times10")
82  retval = GLUT_BITMAP_TIMES_ROMAN_10;
83  else if (whichfont == "fixed13")
84  retval = GLUT_BITMAP_8_BY_13;
85  else if (whichfont == "fixed15")
86  retval = GLUT_BITMAP_9_BY_15;
87  else
88  retval = GLUT_BITMAP_HELVETICA_12;
89  }
90  return retval;
91 }
float getFontHeight ( )

Definition at line 93 of file hud.cpp.

References changed, g_game, getStringFontForHeight(), and game_data_t::y_resolution.

Referenced by BaseUtil::GetTextHeight().

94 {
95  bool changed = false;
96  std::string whichfont = getStringFontForHeight( changed );
97  static float point = 0;
98  if (changed)
99  point = 0;
100  if (point == 0) {
101  if (whichfont == "helvetica10")
102  point = 22;
103  else if (whichfont == "helvetica18")
104  point = 40;
105  else if (whichfont == "times24")
106  point = 50;
107  else if (whichfont == "times10")
108  point = 22;
109  else if (whichfont == "fixed13")
110  point = 30;
111  else if (whichfont == "fixed15")
112  point = 34;
113  else
114  point = 26;
115  }
116  return point/g_game.y_resolution;
117 }
const std::string& getStringFont ( bool changed,
bool  force_inside = false,
bool  whatinside = false 
)

Definition at line 42 of file hud.cpp.

References VegaConfig::getVariable(), isInside(), and vs_config.

Referenced by getFont().

43 {
44  static std::string whichfont = vs_config->getVariable( "graphics", "font", "helvetica12" );
45  static std::string whichdockedfont = vs_config->getVariable( "graphics", "basefont", "helvetica12" );
46  bool inside = isInside();
47  if (force_inside)
48  inside = whatinside;
49  static bool lastinside = inside;
50  if (lastinside != inside) {
51  changed = true;
52  lastinside = inside;
53  } else {changed = false; } return inside ? whichdockedfont : whichfont;
54 }
const std::string& getStringFontForHeight ( bool changed)

Definition at line 56 of file hud.cpp.

References VegaConfig::getVariable(), isInside(), and vs_config.

Referenced by getFontHeight().

57 {
58  static std::string whichfont = vs_config->getVariable( "graphics", "font", "helvetica12" );
59  static std::string whichdockedfont = vs_config->getVariable( "graphics", "basefont", "helvetica12" );
60  bool inside = isInside();
61  static bool lastinside = inside;
62  if (lastinside != inside) {
63  changed = true;
64  lastinside = inside;
65  } else {changed = false; } return inside ? whichdockedfont : whichfont;
66 }
static unsigned char HexToChar ( char  a)
static

Definition at line 158 of file hud.cpp.

Referenced by TwoCharToByte().

159 {
160  if (a >= '0' && a <= '9')
161  return a-'0';
162  else if (a >= 'a' && a <= 'f')
163  return 10+a-'a';
164  else if (a >= 'A' && a <= 'F')
165  return 10+a-'A';
166  return 0;
167 }
static bool isInside ( )
static

Definition at line 36 of file hud.cpp.

References BaseInterface::CurrentBase.

Referenced by getStringFont(), and getStringFontForHeight().

37 {
38  if (BaseInterface::CurrentBase) return true;
39  return false;
40 }
static unsigned char TwoCharToByte ( char  a,
char  b 
)
static

Definition at line 169 of file hud.cpp.

References HexToChar().

Referenced by TwoCharToFloat().

170 {
171  return 16*HexToChar( a )+HexToChar( b );
172 }
static float TwoCharToFloat ( char  a,
char  b 
)
static

Definition at line 174 of file hud.cpp.

References TwoCharToByte().

175 {
176  return TwoCharToByte( a, b )/255.;
177 }