/// <summary>
 /// Instantiates a new console GUI, creating a consoleRenderer and an array to hold the GUI elements.
 /// </summary>
 public ConsoleGUI(ConsoleColor screenColour = ConsoleColor.Black)
 {
     consoleRenderer = new ConsoleRenderer(Console.WindowWidth, Console.WindowHeight);
     screen = new List<Element>(); //This list contains every element to be drawn to the screen. Elements are rendered in the order they're added to the list.
     numberOfElements = -1;
     activeElement = -1;
     this.screenColour = screenColour;
     Console.BackgroundColor = screenColour;
     Console.Clear ();
 }
Пример #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);
                        }
                    }
                }
            }
Пример #3
0
            public BorderStyles border;                                        //The style of border of the element. Borders are always internal.

            public abstract void DrawElement(ConsoleRenderer consoleRenderer); //Called to draw the element to the buffer.
            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);
                        }
                    }
                }
            }
 public override void DrawElement(ConsoleRenderer consoleRenderer)
 {
     if (border == BorderStyles.none) {
         DrawImage (0, consoleRenderer);
     } else {
         consoleRenderer.DrawBox (xPosition, yPosition, width, height, border, foreColour, ConsoleColor.Black);
         DrawImage (1, consoleRenderer);
     }
 }
            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--;
                                }
                            }
                        }
                    }
                }
            }
 public override void DrawElement(ConsoleRenderer consoleRenderer)
 {
     if (border == BorderStyles.none) {
         //no border, just draw the log.
         WriteBuffer(0, consoleRenderer);
     }
     else {
         //Draw a border before writing the text.
         consoleRenderer.DrawBox(xPosition, yPosition, width, height, border, foreColour, backColour);
         WriteBuffer(1, consoleRenderer);
     }
 }
 public abstract void DrawElement(ConsoleRenderer consoleRenderer);