--- a/sources/coloredline.cpp Sat Jan 09 02:35:00 2016 +0200 +++ b/sources/coloredline.cpp Sat Jan 09 17:41:21 2016 +0200 @@ -29,38 +29,22 @@ */ #include "coloredline.h" +BEGIN_ZFC_NAMESPACE -static const struct +struct ColorCodeInfo { const char* name; Color color; bool bold; -} g_colorCodes['v' - 'a' + 1] = -{ - { "Brick", RED, true }, // a - { "Tan", YELLOW, true }, // b - { "Gray", WHITE, false }, // c - { "Green", GREEN, true }, // d - { "Brown", YELLOW, false }, // e - { "Gold", YELLOW, true }, // f - { "Red", RED, true }, // g - { "Blue", BLUE, false }, // h - { "Orange", YELLOW, false }, // i - { "White", WHITE, true }, // j - { "Yellow", YELLOW, true }, // k - { "Untranslated", DEFAULT, false }, // l - { "Black", BLACK, false }, // m - { "Blue", BLUE, true }, // n - { "Cream", YELLOW, true }, // o - { "Olive", GREEN, true }, // p - { "Dark Green", GREEN, false }, // q - { "Dark Red", RED, false }, // r - { "Dark Brown", YELLOW, false }, // s - { "Purple", MAGENTA, false }, // t - { "Dark Gray", BLACK, true }, // u - { "Cyan", CYAN, true }, // v }; +ColoredLine::ColoredLine() : + m_length (0), + m_final (false), + m_activeColor (DEFAULT), + m_boldActive (false), + m_colorCodeStage (0) {} + // ------------------------------------------------------------------------------------------------- // void ColoredLine::finalize() @@ -78,6 +62,32 @@ // void ColoredLine::add_char (char ch) { + static const ColorCodeInfo colorCodes[] = + { + { "Brick", RED, true }, // a + { "Tan", YELLOW, true }, // b + { "Gray", WHITE, false }, // c + { "Green", GREEN, true }, // d + { "Brown", YELLOW, false }, // e + { "Gold", YELLOW, true }, // f + { "Red", RED, true }, // g + { "Blue", BLUE, false }, // h + { "Orange", YELLOW, false }, // i + { "White", WHITE, true }, // j + { "Yellow", YELLOW, true }, // k + { "Untranslated", DEFAULT, false }, // l + { "Black", BLACK, false }, // m + { "Blue", BLUE, true }, // n + { "Cream", YELLOW, true }, // o + { "Olive", GREEN, true }, // p + { "Dark Green", GREEN, false }, // q + { "Dark Red", RED, false }, // r + { "Dark Brown", YELLOW, false }, // s + { "Purple", MAGENTA, false }, // t + { "Dark Gray", BLACK, true }, // u + { "Cyan", CYAN, true }, // v + }; + if (m_final) return; // Don't touch finalized lines. @@ -101,7 +111,7 @@ if (ch >= 'a' and ch <= 'v' and ch != 'l') { - auto colorInfo = g_colorCodes[ch - 'a']; + auto colorInfo = colorCodes[ch - 'a']; m_activeColor = colorInfo.color; m_boldActive = colorInfo.bold; assert (m_activeColor < 8); @@ -135,19 +145,8 @@ // void ColoredLine::set_color (Color a, bool on) { - switch (a) - { - case BLACK: m_data << (on ? RLINE_ON_BLACK : RLINE_OFF_BLACK); break; - case RED: m_data << (on ? RLINE_ON_RED : RLINE_OFF_RED); break; - case GREEN: m_data << (on ? RLINE_ON_GREEN : RLINE_OFF_GREEN); break; - case YELLOW: m_data << (on ? RLINE_ON_YELLOW : RLINE_OFF_YELLOW); break; - case BLUE: m_data << (on ? RLINE_ON_BLUE : RLINE_OFF_BLUE); break; - case MAGENTA: m_data << (on ? RLINE_ON_MAGENTA : RLINE_OFF_MAGENTA); break; - case CYAN: m_data << (on ? RLINE_ON_CYAN : RLINE_OFF_CYAN); break; - case WHITE: m_data << (on ? RLINE_ON_WHITE : RLINE_OFF_WHITE); break; - case NUM_COLORS: - case DEFAULT: assert (false); break; - } + assert (a < 8); + m_data << (a + (on ? RLINE_ON_COLOR : RLINE_OFF_COLOR)); } // ------------------------------------------------------------------------------------------------- @@ -162,3 +161,5 @@ return max (rows, 1); } + +END_ZFC_NAMESPACE