sources/interface.cpp

changeset 137
485cb6d6b98c
parent 132
8a4690db252e
child 138
c909c38ca886
equal deleted inserted replaced
132:8a4690db252e 137:485cb6d6b98c
177 bool hasDefaultColors = (::use_default_colors() == OK); 177 bool hasDefaultColors = (::use_default_colors() == OK);
178 int defaultFg = hasDefaultColors ? -1 : COLOR_WHITE; 178 int defaultFg = hasDefaultColors ? -1 : COLOR_WHITE;
179 int defaultBg = hasDefaultColors ? -1 : COLOR_BLACK; 179 int defaultBg = hasDefaultColors ? -1 : COLOR_BLACK;
180 180
181 // Initialize color pairs 181 // Initialize color pairs
182 for (int i = 0; i < NUM_COLORS; ++i) 182 for (int i : range<int>(NUM_COLORS))
183 for (int j = 0; j < NUM_COLORS; ++j) 183 for (int j : range<int>(NUM_COLORS))
184 { 184 {
185 int pairnum = 1 + (i * NUM_COLORS + j); 185 int pairnum = 1 + (i * NUM_COLORS + j);
186 int fg = (i == DEFAULT) ? defaultFg : i; 186 int fg = (i == DEFAULT) ? defaultFg : i;
187 int bg = (j == DEFAULT) ? defaultBg : j; 187 int bg = (j == DEFAULT) ? defaultBg : j;
188 188
259 // 259 //
260 int Interface::render_colorline (int y, int x0, int width, const ColoredLine& line, bool allowWrap) 260 int Interface::render_colorline (int y, int x0, int width, const ColoredLine& line, bool allowWrap)
261 { 261 {
262 int x = x0; 262 int x = x0;
263 263
264 for (int i = 0; i < line.data().size(); ++i) 264 for (int byte : line.data())
265 { 265 {
266 int byte = line.data()[i];
267
268 if (x == x0 + width) 266 if (x == x0 + width)
269 { 267 {
270 if (not allowWrap) 268 if (not allowWrap)
271 return y; 269 return y;
272 270
360 return; 358 return;
361 359
362 assert (start <= end and start - end <= height); 360 assert (start <= end and start - end <= height);
363 361
364 // Clear the display 362 // Clear the display
365 for (int i = y; i < y + height; ++i) 363 for (int i : range(height))
366 mvhline (i, 0, ' ', width); 364 mvhline (y + i, 0, ' ', width);
367 365
368 // Print the lines 366 // Print the lines
369 y += printOffset; 367 y += printOffset;
370 368
371 for (int i = start; i < end; ++i) 369 for (int i : range(start, end))
372 y = render_colorline (y, 0, width, m_outputLines[i], true); 370 y = render_colorline (y, 0, width, m_outputLines[i], true);
373 371
374 m_needOutputRender = false; 372 m_needOutputRender = false;
375 m_needRefresh = true; 373 m_needRefresh = true;
376 } 374 }
382 int width = nicklist_width(); 380 int width = nicklist_width();
383 int height = LINES- 3; 381 int height = LINES- 3;
384 int y = 1; 382 int y = 1;
385 int x = COLS - width; 383 int x = COLS - width;
386 384
387 if (width == 0) 385 if (width > 0)
388 return; 386 return;
389 387
390 for (int i = 0; i < height; ++i) 388 for (int i : range(height))
391 { 389 {
392 mvhline (y, x, ' ', width); 390 mvhline (y, x, ' ', width);
393 391
394 if (i < m_playerNames.size()) 392 if (i < m_playerNames.size())
395 render_colorline (y, x, width, m_playerNames[i], false); 393 render_colorline (y, x, width, m_playerNames[i], false);
425 int y = LINES - 2; 423 int y = LINES - 2;
426 424
427 // If we're inputting a password, replace it with asterisks 425 // If we're inputting a password, replace it with asterisks
428 if (m_inputState == INPUTSTATE_PASSWORD) 426 if (m_inputState == INPUTSTATE_PASSWORD)
429 { 427 {
430 for (int i = 0; i < displayString.length(); ++i) 428 for (char &ch : displayString)
431 displayString[i] = '*'; 429 ch = '*';
432 } 430 }
433 431
434 // Ensure the cursor is within bounds 432 // Ensure the cursor is within bounds
435 m_cursorPosition = clamp (m_cursorPosition, 0, displayString.length()); 433 m_cursorPosition = clamp (m_cursorPosition, 0, displayString.length());
436 434
959 { 957 {
960 // Zandronum sometimes sends color codes as "\\c" and sometimes as "\x1C". 958 // Zandronum sometimes sends color codes as "\\c" and sometimes as "\x1C".
961 // Let's correct that on our end and hope this won't cause conflicts. 959 // Let's correct that on our end and hope this won't cause conflicts.
962 message.replace ("\\c", "\x1C"); 960 message.replace ("\\c", "\x1C");
963 961
964 for (int i = 0; i < message.length(); ++i) 962 for (char ch : message)
965 { 963 {
966 char ch = message[i];
967
968 if (ch == '\n') 964 if (ch == '\n')
969 { 965 {
970 m_outputLines.last().finalize(); 966 m_outputLines.last().finalize();
971 m_outputLines << ColoredLine(); 967 m_outputLines << ColoredLine();
972 continue; 968 continue;
977 time_t now; 973 time_t now;
978 time (&now); 974 time (&now);
979 char timestamp[32]; 975 char timestamp[32];
980 strftime (timestamp, sizeof timestamp, "[%H:%M:%S] ", localtime (&now)); 976 strftime (timestamp, sizeof timestamp, "[%H:%M:%S] ", localtime (&now));
981 977
982 for (char* cp = timestamp; *cp != '\0'; ++cp) 978 for (char ch : String(timestamp))
983 m_outputLines.last().add_char (*cp); 979 m_outputLines.last().add_char (ch);
984 } 980 }
985 981
986 // Remove some lines if there's too many of them. 20,000 should be enough, I hope. 982 // Remove some lines if there's too many of them. 20,000 should be enough, I hope.
987 while (m_outputLines.size() > 20000) 983 while (m_outputLines.size() > 20000)
988 m_outputLines.remove_at(0); 984 m_outputLines.remove_at(0);

mercurial