sources/coloredline.cpp

changeset 143
b9993733952a
parent 142
b4f89893c702
child 145
d0aedc9be448
equal deleted inserted replaced
142:b4f89893c702 143:b9993733952a
48 // ------------------------------------------------------------------------------------------------- 48 // -------------------------------------------------------------------------------------------------
49 // 49 //
50 void ColoredLine::finalize() 50 void ColoredLine::finalize()
51 { 51 {
52 if (m_activeColor != DEFAULT) 52 if (m_activeColor != DEFAULT)
53 set_color(m_activeColor, false); 53 setColor(m_activeColor, false);
54 54
55 if (m_boldActive) 55 if (m_boldActive)
56 m_data << RLINE_OFF_BOLD; 56 m_data << RLINE_OFF_BOLD;
57 57
58 m_final = true; 58 m_final = true;
59 } 59 }
60 60
61 // ------------------------------------------------------------------------------------------------- 61 // -------------------------------------------------------------------------------------------------
62 // 62 //
63 void ColoredLine::add_char(char ch) 63 void ColoredLine::addChar(char ch)
64 { 64 {
65 static const ColorCodeInfo colorCodes[] = 65 static const ColorCodeInfo colorCodes[] =
66 { 66 {
67 { "Brick", RED, true }, // a 67 { "Brick", RED, true }, // a
68 { "Tan", YELLOW, true }, // b 68 { "Tan", YELLOW, true }, // b
98 } 98 }
99 99
100 if (m_colorCodeStage == 1) 100 if (m_colorCodeStage == 1)
101 { 101 {
102 if (m_activeColor != DEFAULT) 102 if (m_activeColor != DEFAULT)
103 set_color(m_activeColor, false); 103 setColor(m_activeColor, false);
104 104
105 if (m_boldActive) 105 if (m_boldActive)
106 m_data << RLINE_OFF_BOLD; 106 m_data << RLINE_OFF_BOLD;
107 107
108 m_boldActive = false; 108 m_boldActive = false;
112 ch += 'a' - 'A'; 112 ch += 'a' - 'A';
113 113
114 if (ch >= 'a' and ch <= 'v' and ch != 'l') 114 if (ch >= 'a' and ch <= 'v' and ch != 'l')
115 { 115 {
116 const ColorCodeInfo& colorInfo = colorCodes[ch - 'a']; 116 const ColorCodeInfo& colorInfo = colorCodes[ch - 'a'];
117 activate_color(colorInfo.color, colorInfo.bold); 117 activateColor(colorInfo.color, colorInfo.bold);
118 } 118 }
119 119
120 if (ch == '[') 120 if (ch == '[')
121 m_colorCodeStage = 2; 121 m_colorCodeStage = 2;
122 else 122 else
131 131
132 for (const ColorCodeInfo &colorInfo : colorCodes) 132 for (const ColorCodeInfo &colorInfo : colorCodes)
133 { 133 {
134 if (String(colorInfo.name).to_lowercase() == color) 134 if (String(colorInfo.name).to_lowercase() == color)
135 { 135 {
136 activate_color(colorInfo.color, colorInfo.bold); 136 activateColor(colorInfo.color, colorInfo.bold);
137 m_colorCodeStage = 0; 137 m_colorCodeStage = 0;
138 break; 138 break;
139 } 139 }
140 } 140 }
141 141
156 } 156 }
157 } 157 }
158 158
159 // ------------------------------------------------------------------------------------------------- 159 // -------------------------------------------------------------------------------------------------
160 // 160 //
161 void ColoredLine::activate_color(Color color, bool bold) 161 void ColoredLine::activateColor(Color color, bool bold)
162 { 162 {
163 if (m_boldActive) 163 if (m_boldActive)
164 m_data << RLINE_OFF_BOLD; 164 m_data << RLINE_OFF_BOLD;
165 165
166 m_activeColor = color; 166 m_activeColor = color;
167 m_boldActive = bold; 167 m_boldActive = bold;
168 assert(m_activeColor < 8); 168 assert(m_activeColor < 8);
169 set_color(m_activeColor, true); 169 setColor(m_activeColor, true);
170 170
171 if (m_boldActive) 171 if (m_boldActive)
172 m_data << RLINE_ON_BOLD; 172 m_data << RLINE_ON_BOLD;
173 } 173 }
174 174
175 // ------------------------------------------------------------------------------------------------- 175 // -------------------------------------------------------------------------------------------------
176 // 176 //
177 void ColoredLine::add_string(const String& text) 177 void ColoredLine::addString(const String& text)
178 { 178 {
179 for (char a : text) 179 for (char a : text)
180 add_char(a); 180 addChar(a);
181 } 181 }
182 182
183 // ------------------------------------------------------------------------------------------------- 183 // -------------------------------------------------------------------------------------------------
184 // 184 //
185 void ColoredLine::set_color(Color a, bool on) 185 void ColoredLine::setColor(Color a, bool on)
186 { 186 {
187 assert(a < 8); 187 assert(a < 8);
188 m_data << (a +(on ? RLINE_ON_COLOR : RLINE_OFF_COLOR)); 188 m_data << (a +(on ? RLINE_ON_COLOR : RLINE_OFF_COLOR));
189 } 189 }
190 190

mercurial