void DrawScreen() { if (DisplayMode == DISP_MATRIX) { int maxCellLength = 0; for (int y = 0; y < DisplayMatrix.MatrixHeight; y++) { for (int x = 0; x < DisplayMatrix.MatrixWidth; x++) { if (maxCellLength < DisplayMatrix.GetCell(y, x).ToString().Length) { maxCellLength = DisplayMatrix.GetCell(y, x).ToString().Length; } } } maxCellLength++; // because we need spacing if (WindowWidth - 6 < maxCellLength * DisplayMatrix.MatrixWidth) { maxCellLength = (WindowWidth - 8) / DisplayMatrix.MatrixWidth; } if (maxCellLength < 2 || DisplayMatrix.MatrixHeight >= (WindowHeight - 4)) { SetAlert("Error", "Matrix too big to display", 2); } } ResetScreen(); // draw title bars and window borders for (int x = 0; x < WindowWidth; x++) { ScreenBackground[x, 0] = AlertEnabled ? (int)ConsoleColor.DarkCyan : (int)ConsoleColor.Cyan; ScreenForeground[x, 0] = (int)ConsoleColor.Black; Screen[x, 0] = '-'; ScreenBackground[x, WindowHeight - 2] = AlertEnabled ? (int)ConsoleColor.DarkCyan : (int)ConsoleColor.Cyan; ScreenForeground[x, WindowHeight - 2] = (int)ConsoleColor.Black; Screen[x, WindowHeight - 2] = '-'; ScreenBackground[x, WindowHeight - 1] = (int)ConsoleColor.Green; ScreenForeground[x, WindowHeight - 1] = (int)ConsoleColor.Black; Screen[x, WindowHeight - 1] = '-'; } for (int y = 0; y < WindowHeight - 1; y++) { ScreenBackground[0, y] = AlertEnabled ? (int)ConsoleColor.DarkCyan : (int)ConsoleColor.Cyan; ScreenForeground[0, y] = (int)ConsoleColor.Black; Screen[0, y] = '|'; ScreenBackground[WindowWidth - 1, y] = AlertEnabled ? (int)ConsoleColor.DarkCyan : (int)ConsoleColor.Cyan; ScreenForeground[WindowWidth - 1, y] = (int)ConsoleColor.Black; Screen[WindowWidth - 1, y] = '|'; } WriteCentered(" " + MainTitleText + " ", 0); WriteUpperLeft(" " + PromptText + " ", 1, WindowHeight - 1); // draw content if (DisplayMode == DISP_TEXT) { WriteUpperLeft(MainText, 2, 2); } else if (DisplayMode == DISP_MENU) { int y = 2; int jump = (WindowHeight - 5) / MenuOptions.Count(); foreach (var opt in MenuOptions) { ScreenForeground[3, y] = (int)ConsoleColor.Black; ScreenForeground[4, y] = (int)ConsoleColor.Black; ScreenBackground[3, y] = AlertEnabled ? (int)ConsoleColor.DarkYellow : (int)ConsoleColor.Yellow; ScreenBackground[4, y] = AlertEnabled ? (int)ConsoleColor.DarkYellow : (int)ConsoleColor.Yellow; Screen[3, y] = opt.Key; Screen[4, y] = '.'; WriteUpperLeft(opt.Value, 7, y); y += jump; } } else if (DisplayMode == DISP_MATRIX) { int sign = 0, dec = 0, exp = 0; int maxCellLength = 0; for (int y = 0; y < DisplayMatrix.MatrixHeight; y++) { for (int x = 0; x < DisplayMatrix.MatrixWidth; x++) { if (maxCellLength < DisplayMatrix.GetCell(y, x).ToString().Length) { maxCellLength = DisplayMatrix.GetCell(y, x).ToString().Length; } } } maxCellLength += 1; if (WindowWidth - 6 < maxCellLength * DisplayMatrix.MatrixWidth) { maxCellLength = (WindowWidth - 8) / DisplayMatrix.MatrixWidth; } if (maxCellLength < 2 || DisplayMatrix.MatrixHeight < (WindowHeight - 4)) { // draw augment separator if (DisplayMatrix.border > 0) { for (int y = 0; y < DisplayMatrix.MatrixHeight; y++) { Screen[3 + maxCellLength * DisplayMatrix.border, y + 2] = '|'; } } // draw left bracket Screen[2, 2] = '/'; for (int y = 0; y < (DisplayMatrix.MatrixHeight - 2); y++) { Screen[2, y + 3] = '|'; } Screen[2, DisplayMatrix.MatrixHeight + 1] = '\\'; // draw contents double toDraw; for (int y = 0; y < DisplayMatrix.MatrixHeight; y++) { for (int x = 0; x < DisplayMatrix.MatrixWidth; x++) { toDraw = DisplayMatrix.GetCell(y, x); if (toDraw.ToString().Contains("-")) { sign = 2; } else { sign = 0; } if (toDraw.ToString().Contains(".")) { dec = 1; } else { dec = 0; } if (toDraw.ToString().Contains("E")) { exp = 1; } else { exp = 0; } WriteRightAlign(DisplayMatrix.GetCell(y, x).ToString("G" + (maxCellLength - (dec + sign + exp))), 4 + maxCellLength * x, y + 2, maxCellLength - 1); } } // draw right bracket Screen[4 + (DisplayMatrix.MatrixWidth) * maxCellLength, 2] = '\\'; for (int y = 0; y < (DisplayMatrix.MatrixHeight - 2); y++) { Screen[4 + DisplayMatrix.MatrixWidth * maxCellLength, y + 3] = '|'; } Screen[4 + DisplayMatrix.MatrixWidth * maxCellLength, DisplayMatrix.MatrixHeight + 1] = '/'; // draw highlights if (MatrixRowHighlight >= 0) { for (int x = 1; x < WindowWidth - 1; x++) { ScreenBackground[x, MatrixRowHighlight + 2] = AlertEnabled ? (int)ConsoleColor.DarkBlue : (int)ConsoleColor.Blue; } } if (MatrixColumnHighlight >= 0) { for (int y = 1; y < WindowHeight - 2; y++) { for (int x = maxCellLength * MatrixColumnHighlight + 4; x < maxCellLength * (MatrixColumnHighlight + 1) + 4; x++) { ScreenBackground[x, y] = AlertEnabled ? (int)ConsoleColor.DarkBlue : (int)ConsoleColor.Blue; } } } if (MatrixRowHighlight >= 0 && MatrixColumnHighlight >= 0) { for (int x = maxCellLength * MatrixColumnHighlight + 4; x < maxCellLength * (MatrixColumnHighlight + 1) + 4; x++) { ScreenBackground[x, MatrixRowHighlight + 2] = AlertEnabled ? (int)ConsoleColor.Gray : (int)ConsoleColor.White; ScreenForeground[x, MatrixRowHighlight + 2] = (int)ConsoleColor.Black; } } } } if (AlertEnabled) { DrawAlert(); } }