Skip to content
Permalink
Browse files

Remove Color::Token::DEFAULT_COLOR

  • Loading branch information...
mbasaglia committed Aug 29, 2015
1 parent d157b57 commit 03110213d59a07c983ff12eeb319a1ad05521ca7
@@ -262,7 +262,7 @@ TokenIterator::value_type TokenIterator::NextToken(const char* input)
}
else if ( input[1] == Constants::NULL_COLOR )
{
return value_type( input, input+2, value_type::DEFAULT_COLOR );
return value_type( input, input+2, parent->DefaultColor() );
}
else if ( std::toupper( input[1] ) >= '0' && std::toupper( input[1] ) < 'P' )
{
@@ -381,7 +381,6 @@ class Token
CHARACTER, // A character
ESCAPE, // Color escape
COLOR, // Color code
DEFAULT_COLOR, // Color code to reset to the default
};

/*
@@ -465,6 +464,8 @@ class Token

};

class Parser;

/**
* Class to parse C-style strings into tokens,
* implements the InputIterator concept
@@ -480,7 +481,8 @@ class TokenIterator

TokenIterator() = default;

explicit TokenIterator( const char* input )
explicit TokenIterator( const char* input, const Parser* parent )
: parent( parent )
{
token = NextToken( input );
}
@@ -532,6 +534,7 @@ class TokenIterator
value_type NextToken(const char* input);

value_type token;
const Parser* parent = nullptr;
};

/**
@@ -551,14 +554,19 @@ class Parser

iterator begin() const
{
return iterator(input);
return iterator(input, this);
}

iterator end() const
{
return iterator();
}

Color DefaultColor() const
{
return default_color;
}

private:
const char* input;
Color default_color;
@@ -492,7 +492,7 @@ bool CL_InternalConsolePrint( const char *text )

for ( const auto& token : Color::Parser( text ) )
{
if ( token.Type() == Color::Token::COLOR || token.Type() == Color::Token::DEFAULT_COLOR )
if ( token.Type() == Color::Token::COLOR )
{
consoleState.lines.back().append( token.Begin(), token.Size() );
continue;
@@ -878,18 +878,14 @@ void Con_DrawConsoleContent()

re.SetColor( console_color_alpha );

for ( const auto& token : Color::Parser( consoleState.lines[row].c_str() ) )
for ( const auto& token : Color::Parser( consoleState.lines[row].c_str(), console_color_alpha ) )
{
if ( token.Type() == Color::Token::COLOR )
{
Color::Color color = token.Color();
color.SetAlpha( console_color_alpha.Alpha() );
re.SetColor( color );
}
else if ( token.Type() == Color::Token::DEFAULT_COLOR )
{
re.SetColor( console_color_alpha );
}
else if ( token.Type() == Color::Token::CHARACTER )
{
int ch = Q_UTF8_CodePoint( token.Begin() );
@@ -291,22 +291,14 @@ void SCR_DrawSmallStringExt( int x, int y, const char *string,
xx = x;
re.SetColor( setColor );

for ( const auto& token : Color::Parser( string ) )
for ( const auto& token : Color::Parser( string, setColor ) )
{
if ( token.Type() == Color::Token::COLOR || token.Type() == Color::Token::DEFAULT_COLOR )
if ( token.Type() == Color::Token::COLOR )
{
if ( !forceColor )
{
Color::Color color;
if ( token.Type() == Color::Token::DEFAULT_COLOR )
{
color = setColor;
}
else
{
color = token.Color();
color.SetAlpha( setColor.Alpha() );
}
Color::Color color = token.Color();
color.SetAlpha( setColor.Alpha() );
re.SetColor( color );
}

@@ -116,7 +116,7 @@ static void CON_ColorPrint( WINDOW *win, const char *msg, bool stripcodes )
Con_ClearColor( win );

std::string buffer;
for ( const auto& token : Color::Parser( msg ) )
for ( const auto& token : Color::Parser( msg, Color::Color() ) )
{

if ( token.Type() == Color::Token::COLOR )
@@ -127,23 +127,15 @@ static void CON_ColorPrint( WINDOW *win, const char *msg, bool stripcodes )
buffer.clear();
}

CON_SetColor( win, token.Color() );

if ( !stripcodes )
if ( token.Color().Alpha() == 0 )
{
buffer.append( token.Begin(), token.Size() );
Con_ClearColor( win );
}
}
else if ( token.Type() == Color::Token::DEFAULT_COLOR )
{
if ( !buffer.empty() )
else
{
waddstr( win, buffer.c_str() );
buffer.clear();
CON_SetColor( win, token.Color() );
}

Con_ClearColor( win );

if ( !stripcodes )
{
buffer.append( token.Begin(), token.Size() );
@@ -75,7 +75,7 @@ Transform Q3 colour codes to ANSI escape sequences
static void CON_AnsiColorPrint( const char *msg )
{
std::string buffer;
for ( const auto& token : Color::Parser( msg ) )
for ( const auto& token : Color::Parser( msg, Color::Color() ) )
{
if ( token.Type() == Color::Token::COLOR )
{
@@ -85,26 +85,24 @@ static void CON_AnsiColorPrint( const char *msg )
buffer.clear();
}

auto c4b = Color::To4bit( token.Color() );
bool bright = c4b & 8;
int number = c4b & ~8;
if ( token.Color().Alpha() == 0 )
{
fputs( "\x1b[0m", stderr );
}
else
{
auto c4b = Color::To4bit( token.Color() );
bool bright = c4b & 8;
int number = c4b & ~8;

std::string ansi = "\x1b[3"+std::to_string(number)+";"+(bright ? "1" : "22")+"m";
fputs( ansi.c_str(), stderr );
std::string ansi = "\x1b[3"+std::to_string(number)+";"+(bright ? "1" : "22")+"m";
fputs( ansi.c_str(), stderr );
}
}
else if ( token.Type() == Color::Token::ESCAPE )
{
buffer += Color::Constants::ESCAPE;
}
else if ( token.Type() == Color::Token::DEFAULT_COLOR )
{
if ( !buffer.empty() )
{
fputs( buffer.c_str(), stderr );
buffer.clear();
}
fputs( "\x1b[0m", stderr );
}
else if ( token.Type() == Color::Token::CHARACTER )
{
if ( *token.Begin() == '\n' )
@@ -496,7 +496,7 @@ Rocket::Core::String Rocket_QuakeToRML( const char *in, int parseFlags = 0 )
return "";
}

for ( const auto& token : Color::Parser( in ) )
for ( const auto& token : Color::Parser( in, Color::Color() ) )
{
if ( token.Type() == Color::Token::CHARACTER )
{
@@ -544,7 +544,7 @@ Rocket::Core::String Rocket_QuakeToRML( const char *in, int parseFlags = 0 )
out.Append( token.Begin(), token.Size() );
}
}
else if ( token.Type() == Color::Token::COLOR || token.Type() == Color::Token::DEFAULT_COLOR )
else if ( token.Type() == Color::Token::COLOR )
{
if ( span && spanHasContent )
{
@@ -553,7 +553,7 @@ Rocket::Core::String Rocket_QuakeToRML( const char *in, int parseFlags = 0 )
spanHasContent = false;
}

if ( token.Type() == Color::Token::COLOR )
if ( token.Color().Alpha() != 0 )
{
char rgb[32];
Color::Color32Bit color32 = token.Color();
@@ -353,19 +353,12 @@ class RocketChatField : public Rocket::Core::Element, Rocket::Core::EventListene
return;
}

for ( const auto& token : Color::Parser( in.CString() ) )
for ( const auto& token : Color::Parser( in.CString(), Color::White ) )
{
if ( token.Type() == Color::Token::COLOR ||
token.Type() == Color::Token::DEFAULT_COLOR )
if ( token.Type() == Color::Token::COLOR )
{
Rocket::Core::XMLAttributes xml;

Color::Color color = Color::White;
if ( token.Type() == Color::Token::COLOR )
{
color = token.Color();
}

// Child element initialized
if ( span )
{
@@ -389,7 +382,7 @@ class RocketChatField : public Rocket::Core::Element, Rocket::Core::EventListene


child = Rocket::Core::Factory::InstanceElement( parent, "#text", "span", xml );
Color::Color32Bit color32 = color;
Color::Color32Bit color32 = token.Color();
child->SetProperty( "color", va( "#%02X%02X%02X", (int) color32.Red(), (int) color32.Green(), (int) color32.Blue() ) );
out.Append( token.Begin(), token.Size() );
span = true;

0 comments on commit 0311021

Please sign in to comment.
You can’t perform that action at this time.