sources/coloredline.cpp

changeset 87
53c2aecb9704
parent 73
07dda51a7a8e
child 88
08ccaf26cffd
equal deleted inserted replaced
86:3c02a728a681 87:53c2aecb9704
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "coloredline.h" 31 #include "coloredline.h"
32 32
33 static const struct 33 struct ColorCodeInfo
34 { 34 {
35 const char* name; 35 const char* name;
36 Color color; 36 Color color;
37 bool bold; 37 bool bold;
38 } g_colorCodes['v' - 'a' + 1] =
39 {
40 { "Brick", RED, true }, // a
41 { "Tan", YELLOW, true }, // b
42 { "Gray", WHITE, false }, // c
43 { "Green", GREEN, true }, // d
44 { "Brown", YELLOW, false }, // e
45 { "Gold", YELLOW, true }, // f
46 { "Red", RED, true }, // g
47 { "Blue", BLUE, false }, // h
48 { "Orange", YELLOW, false }, // i
49 { "White", WHITE, true }, // j
50 { "Yellow", YELLOW, true }, // k
51 { "Untranslated", DEFAULT, false }, // l
52 { "Black", BLACK, false }, // m
53 { "Blue", BLUE, true }, // n
54 { "Cream", YELLOW, true }, // o
55 { "Olive", GREEN, true }, // p
56 { "Dark Green", GREEN, false }, // q
57 { "Dark Red", RED, false }, // r
58 { "Dark Brown", YELLOW, false }, // s
59 { "Purple", MAGENTA, false }, // t
60 { "Dark Gray", BLACK, true }, // u
61 { "Cyan", CYAN, true }, // v
62 }; 38 };
63 39
64 // ------------------------------------------------------------------------------------------------- 40 // -------------------------------------------------------------------------------------------------
65 // 41 //
66 void ColoredLine::finalize() 42 void ColoredLine::finalize()
76 52
77 // ------------------------------------------------------------------------------------------------- 53 // -------------------------------------------------------------------------------------------------
78 // 54 //
79 void ColoredLine::add_char (char ch) 55 void ColoredLine::add_char (char ch)
80 { 56 {
57 static const ColorCodeInfo colorCodes[] =
58 {
59 { "Brick", RED, true }, // a
60 { "Tan", YELLOW, true }, // b
61 { "Gray", WHITE, false }, // c
62 { "Green", GREEN, true }, // d
63 { "Brown", YELLOW, false }, // e
64 { "Gold", YELLOW, true }, // f
65 { "Red", RED, true }, // g
66 { "Blue", BLUE, false }, // h
67 { "Orange", YELLOW, false }, // i
68 { "White", WHITE, true }, // j
69 { "Yellow", YELLOW, true }, // k
70 { "Untranslated", DEFAULT, false }, // l
71 { "Black", BLACK, false }, // m
72 { "Blue", BLUE, true }, // n
73 { "Cream", YELLOW, true }, // o
74 { "Olive", GREEN, true }, // p
75 { "Dark Green", GREEN, false }, // q
76 { "Dark Red", RED, false }, // r
77 { "Dark Brown", YELLOW, false }, // s
78 { "Purple", MAGENTA, false }, // t
79 { "Dark Gray", BLACK, true }, // u
80 { "Cyan", CYAN, true }, // v
81 };
82
81 if (m_final) 83 if (m_final)
82 return; // Don't touch finalized lines. 84 return; // Don't touch finalized lines.
83 85
84 if (ch == '\x1C' and m_colorCodeStage == 0) 86 if (ch == '\x1C' and m_colorCodeStage == 0)
85 { 87 {
99 if (ch >= 'A' and ch <= 'V') 101 if (ch >= 'A' and ch <= 'V')
100 ch += 'a' - 'A'; 102 ch += 'a' - 'A';
101 103
102 if (ch >= 'a' and ch <= 'v' and ch != 'l') 104 if (ch >= 'a' and ch <= 'v' and ch != 'l')
103 { 105 {
104 auto colorInfo = g_colorCodes[ch - 'a']; 106 auto colorInfo = colorCodes[ch - 'a'];
105 m_activeColor = colorInfo.color; 107 m_activeColor = colorInfo.color;
106 m_boldActive = colorInfo.bold; 108 m_boldActive = colorInfo.bold;
107 assert (m_activeColor < 8); 109 assert (m_activeColor < 8);
108 set_color (m_activeColor, true); 110 set_color (m_activeColor, true);
109 111

mercurial