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
painttext.cpp File Reference
#include "vegastrike.h"
#include "painttext.h"
#include "vs_globals.h"
#include "config_xml.h"
#include "gldrv/gl_globals.h"

Go to the source code of this file.

Functions

bool useStroke ()
 
static float drawChars (const string &str, int start, int end, const Font &font, const GFXColor &color, float inRasterPos)
 
static void parseFormatFloat (const std::string &str, const string::size_type startPos, const string::size_type endPos, bool *formatSuccess, float *resultValue, string::size_type *resultPos, const char optionalTerminator= '\0')
 
static void parseFormatColor (const string &str, const string::size_type startPos, const string::size_type endPos, bool *formatSuccess, GFXColor &color, string::size_type *resultPos)
 
static bool isWordBreak (char c)
 
std::string colorsToCommandString (float r, float g, float b, float a)
 

Variables

static const char OLD_FORMAT_NEWLINE = '\\'
 
static const char DT_FORMAT_CHAR = '#'
 
static const char DT_FORMAT_NEWLINE_CHAR = 'n'
 
static const char DT_FORMAT_LINE_SPACING_CHAR = 'l'
 
static const char DT_FORMAT_STROKE_CHAR = 'b'
 
static const char DT_FORMAT_COLOR_CHAR = 'c'
 
static const char DT_FORMAT_POP_CHAR = '-'
 
static const char DT_FORMAT_RESET_CHAR = '!'
 
static const char DT_FORMAT_COLOR_SEP = ':'
 
static const float BOGUS_LINE_SPACING = -100.0
 
static const string::size_type ELLIPSIS_FRAGMENT = 64
 
static const string ELLIPSIS_STRING = "..."
 
static const float LINE_HEIGHT_EPSILON = .99
 
static const int LINES_RESERVE = 50
 

Function Documentation

std::string colorsToCommandString ( float  r,
float  g,
float  b,
float  a 
)

Definition at line 747 of file painttext.cpp.

Referenced by factionColorTextString(), and BaseComputer::showPlayerInfo().

748 {
749  char buf[256];
750  if (a >= 1.0)
751  //Three-color string.
752  sprintf( buf, "#c%.3g:%.3g:%.3g#", r, g, b );
753  else
754  //Four-color string.
755  sprintf( buf, "#c%.3g:%.3g:%.3g:%.3g#", r, g, b, a );
756  return buf;
757 }
static float drawChars ( const string &  str,
int  start,
int  end,
const Font font,
const GFXColor color,
float  inRasterPos 
)
static

Definition at line 200 of file painttext.cpp.

References GFXColor::a, GFXColor::b, Font::drawChar(), GFXColor::g, g_game, VegaConfig::getVariable(), XMLSupport::parse_bool(), GFXColor::r, Font::strokeWidth(), useStroke(), vs_config, and game_data_t::x_resolution.

Referenced by PaintText::drawLines().

201 {
202  //Make sure the graphics state is right.
203  glColor4f( color.r, color.g, color.b, color.a );
204  if ( useStroke() ) {
205  glLineWidth( font.strokeWidth() );
206  } else {
207  static bool setRasterPos = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "set_raster_text_color", "true" ) );
208  if (setRasterPos)
209  glRasterPos2f( inRasterPos/(g_game.x_resolution/2), 0 );
210  }
211  //Draw all the characters.
212  for (int charPos = start; charPos <= end; charPos++)
213  inRasterPos += font.drawChar( str[charPos] );
214  return inRasterPos;
215 }
static bool isWordBreak ( char  c)
static

Definition at line 462 of file painttext.cpp.

Referenced by PaintText::parseFragmentsWithCharBreak(), and PaintText::parseFragmentsWithWordBreak().

463 {
464  return c == ' ';
465 }
static void parseFormatColor ( const string &  str,
const string::size_type  startPos,
const string::size_type  endPos,
bool formatSuccess,
GFXColor color,
string::size_type *  resultPos 
)
static

Definition at line 316 of file painttext.cpp.

References GFXColor::a, GFXColor::b, DT_FORMAT_CHAR, DT_FORMAT_COLOR_SEP, GFXColor::g, parseFormatFloat(), and GFXColor::r.

Referenced by PaintText::parseFormat().

323 {
324  *formatSuccess = false;
325  string::size_type curPos = startPos;
326  parseFormatFloat( str, curPos, endPos, formatSuccess, &color.r, &curPos, DT_FORMAT_COLOR_SEP );
327  if (!formatSuccess || str[curPos-1] == DT_FORMAT_CHAR) return;
328  parseFormatFloat( str, curPos, endPos, formatSuccess, &color.g, &curPos, DT_FORMAT_COLOR_SEP );
329  if (!formatSuccess || str[curPos-1] == DT_FORMAT_CHAR) return;
330  parseFormatFloat( str, curPos, endPos, formatSuccess, &color.b, &curPos, DT_FORMAT_COLOR_SEP );
331  if (!formatSuccess) return;
332  if (str[curPos-1] != DT_FORMAT_CHAR)
333  //Not done -- still have alpha to do.
334  parseFormatFloat( str, curPos, endPos, formatSuccess, &color.a, &curPos );
335  else
336  //Default alpha value is opaque.
337  color.a = 1.0;
338  *resultPos = curPos;
339 }
static void parseFormatFloat ( const std::string &  str,
const string::size_type  startPos,
const string::size_type  endPos,
bool formatSuccess,
float resultValue,
string::size_type *  resultPos,
const char  optionalTerminator = '\0' 
)
static

Definition at line 277 of file painttext.cpp.

References c, and DT_FORMAT_CHAR.

Referenced by PaintText::parseFormat(), and parseFormatColor().

285 {
286  *formatSuccess = false;
287  std::string num;
288  string::size_type curPos;
289  for (curPos = startPos; curPos < endPos; curPos++) {
290  const char c = str[curPos];
291  if (c == DT_FORMAT_CHAR || c == optionalTerminator) {
292  //Found the trailing end of the format string. Done.
293  *formatSuccess = true;
294  break;
295  }
296  //We only take digits and period, so we only parse simple floating numbers.
297  //We'll take comma for simple localization purposes.
298  if (isdigit( c ) || c == '.' || c == ',')
299  num += c;
300  else
301  //Found a bad character. Stop.
302  break;
303  }
304  *resultPos = curPos+1; //Skip over these chars no matter what.
305  if (formatSuccess && num.size() > 0) {
306  //Convert string to float.
307  //Can't figure out std::locale, so we'll use easy, dumb conversion.
308  *resultValue = atof( num.c_str() );
309  }
310 }
bool useStroke ( )

Definition at line 41 of file font.cpp.

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

Referenced by Font::calcMetrics(), Font::charWidth(), Font::drawChar(), drawChars(), and PaintText::drawLines().

42 {
43  static bool tmp =
44  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "high_quality_font_computer",
45  vs_config->getVariable( "graphics", "high_quality_font", "false" ) ) );
46  return !tmp;
47 }

Variable Documentation

const float BOGUS_LINE_SPACING = -100.0
static

Definition at line 75 of file painttext.cpp.

Referenced by PaintText::calcLayout(), and PaintText::parseFormat().

const char DT_FORMAT_CHAR = '#'
static
const char DT_FORMAT_COLOR_CHAR = 'c'
static

Definition at line 69 of file painttext.cpp.

Referenced by PaintText::parseFormat().

const char DT_FORMAT_COLOR_SEP = ':'
static

Definition at line 73 of file painttext.cpp.

Referenced by parseFormatColor().

const char DT_FORMAT_LINE_SPACING_CHAR = 'l'
static

Definition at line 67 of file painttext.cpp.

Referenced by PaintText::parseFormat().

const char DT_FORMAT_NEWLINE_CHAR = 'n'
static

Definition at line 66 of file painttext.cpp.

Referenced by PaintText::parseFormat().

const char DT_FORMAT_POP_CHAR = '-'
static

Definition at line 70 of file painttext.cpp.

Referenced by PaintText::parseFormat().

const char DT_FORMAT_RESET_CHAR = '!'
static

Definition at line 71 of file painttext.cpp.

Referenced by PaintText::parseFormat().

const char DT_FORMAT_STROKE_CHAR = 'b'
static

Definition at line 68 of file painttext.cpp.

Referenced by PaintText::parseFormat().

const string::size_type ELLIPSIS_FRAGMENT = 64
static

Definition at line 79 of file painttext.cpp.

Referenced by PaintText::drawLines(), and PaintText::parseFragmentsWithCharBreak().

const string ELLIPSIS_STRING = "..."
static

Definition at line 80 of file painttext.cpp.

Referenced by PaintText::drawLines(), and PaintText::parseFragmentsWithCharBreak().

const float LINE_HEIGHT_EPSILON = .99
static

Definition at line 86 of file painttext.cpp.

Referenced by PaintText::drawLines(), and PaintText::visibleLineCountStartingWith().

const int LINES_RESERVE = 50
static

Definition at line 89 of file painttext.cpp.

Referenced by PaintText::calcLayout().

const char OLD_FORMAT_NEWLINE = '\\'
static

Definition at line 61 of file painttext.cpp.

Referenced by PaintText::setText().