Exemplo n.º 1
0
            private void WriteBuffer(int borderOffset, ConsoleRenderer consoleRenderer)
            {
                int tempWidth  = width - (borderOffset * 2);
                int tempHeight = height - (borderOffset * 2);
                int tempX      = xPosition + borderOffset;
                int tempY      = yPosition + borderOffset;

                int linesRemaining = tempHeight;
                int charsPerLine   = tempWidth;

                for (int currentString = 0; currentString < bufferSize; currentString++)
                {
                    if (linesRemaining > 0)
                    {
                        //For each line, calculate how many lines it will take up in the logbox.
                        int numberOfLines = (int)Math.Ceiling((double)buffer[currentString].Length / (double)charsPerLine);

                        if (numberOfLines < 2)
                        {
                            //We only need to write one line; simple!
                            consoleRenderer.WriteString(tempX, tempY + (linesRemaining - 1), buffer[currentString], foreColour, backColour);
                            linesRemaining--;
                        }
                        else
                        {
                            //This is where it gets awkward. We need to account for text wrapping.
                            //To do this we split up the string into several substrings that will fit in the Log Box.
                            string[] substringArray = new string[numberOfLines];
                            for (int c = 0; c < numberOfLines - 1; c++)
                            {
                                substringArray[c] = buffer[currentString].Substring(c * charsPerLine, charsPerLine);
                            }
                            substringArray[numberOfLines - 1] = buffer[currentString].Substring((numberOfLines - 1) * charsPerLine);    //The last substring must go to the end of the string.

                            //Now, add each substring to the buffer and update the linesRemaining variable.
                            for (int c = numberOfLines - 1; c >= 0; c--)
                            {
                                if (linesRemaining > 0)
                                {
                                    consoleRenderer.WriteString(tempX, tempY + (linesRemaining - 1), substringArray[c], foreColour, backColour);
                                    linesRemaining--;
                                }
                            }
                        }
                    }
                }
            }
Exemplo n.º 2
0
            private void DrawImage(int borderOffset, ConsoleRenderer consoleRenderer)
            {
                int imageBufferSize = image.width * image.height;

                for (int posX = xPosition + borderOffset; posX < width - borderOffset; posX++)
                {
                    for (int posY = yPosition + borderOffset; posY < height - borderOffset; posY++)
                    {
                        try {
                            char         charToWrite       = image.imageData[(image.width * (posY + imageY)) + (posX + imageX)];
                            ConsoleColor colourToWrite     = (ConsoleColor)image.imageColour[(image.width * (posY + imageY)) + (posX + imageX)];
                            ConsoleColor backColourToWrite = (ConsoleColor)image.imageBackColour[(image.width * (posY + imageY)) + (posX + imageX)];
                            consoleRenderer.WriteString(posX, posY, charToWrite.ToString(), colourToWrite, backColourToWrite);
                        } catch {
                            consoleRenderer.WriteString(posX, posY, " ", ConsoleColor.Black, ConsoleColor.Black);
                        }
                    }
                }
            }
            private void DrawImage(int borderOffset, ConsoleRenderer consoleRenderer)
            {
                int imageBufferSize = image.width * image.height;

                for (int posX = xPosition + borderOffset; posX < width - borderOffset; posX++) {
                    for (int posY = yPosition + borderOffset; posY < height - borderOffset; posY++) {
                        try {
                            char charToWrite = image.imageData[(image.width * (posY + imageY)) + (posX + imageX)];
                            ConsoleColor colourToWrite = (ConsoleColor)image.imageColour[(image.width * (posY + imageY)) + (posX + imageX)];
                            ConsoleColor backColourToWrite = (ConsoleColor)image.imageBackColour[(image.width * (posY + imageY)) + (posX + imageX)];
                            consoleRenderer.WriteString(posX, posY, charToWrite.ToString(), colourToWrite, backColourToWrite);
                        } catch {
                            consoleRenderer.WriteString (posX, posY, " ", ConsoleColor.Black, ConsoleColor.Black);
                        }
                    }
                }
            }
            private void WriteBuffer(int borderOffset, ConsoleRenderer consoleRenderer)
            {
                int tempWidth = width - (borderOffset * 2);
                int tempHeight = height - (borderOffset * 2);
                int tempX = xPosition + borderOffset;
                int tempY = yPosition + borderOffset;

                int linesRemaining = tempHeight;
                int charsPerLine = tempWidth;
                for (int currentString = 0; currentString < bufferSize; currentString++) {
                    if (linesRemaining > 0) {
                        //For each line, calculate how many lines it will take up in the logbox.
                        int numberOfLines = (int)Math.Ceiling((double)buffer[currentString].Length / (double)charsPerLine);

                        if (numberOfLines < 2) {
                            //We only need to write one line; simple!
                            consoleRenderer.WriteString(tempX, tempY + (linesRemaining - 1), buffer[currentString], foreColour, backColour);
                            linesRemaining--;
                        }
                        else {
                            //This is where it gets awkward. We need to account for text wrapping.
                            //To do this we split up the string into several substrings that will fit in the Log Box.
                            string[] substringArray = new string[numberOfLines];
                            for (int c = 0; c < numberOfLines - 1; c++) {
                                substringArray[c] = buffer[currentString].Substring(c * charsPerLine, charsPerLine);
                            }
                            substringArray[numberOfLines - 1] = buffer[currentString].Substring((numberOfLines - 1) * charsPerLine);    //The last substring must go to the end of the string.

                            //Now, add each substring to the buffer and update the linesRemaining variable.
                            for (int c = numberOfLines - 1; c >= 0; c--) {
                                if (linesRemaining > 0) {
                                    consoleRenderer.WriteString(tempX, tempY + (linesRemaining - 1), substringArray[c], foreColour, backColour);
                                    linesRemaining--;
                                }
                            }
                        }
                    }
                }
            }