Esempio n. 1
0
        /// <summary>
        ///     Initializes a ScreenContainer instance that creates a new Cube for the given screen.
        /// </summary>
        /// <param name="screen">VScreen that needs a Cube</param>
        public ScreenContainer(VScreen screen)
        {
            Screen = screen;
            Cube   = new Cube(Min(Screen.WindowHeight, Screen.WindowWidth));

            // print the initial cube
            Cube.ProjectToVScreen(Screen);
            Screen.Output();
        }
Esempio n. 2
0
        /// <summary>
        ///     Do some initializing work (mainly environment prep).
        /// </summary>
        /// <param name="screens">List containing the VScreen instances</param>
        /// <param name="height"></param>
        /// <param name="width"></param>
        /// <param name="skipResize"></param>
        private static void Init(out List <VScreen> screens, bool skipResize)
        {
            Console.Title = "MultiCube";


            // Considering the possibility of launching from command line, we don't want to have any residual output from it left on the screen.
            Console.Clear();

            if (!skipResize)
            {
                lock (ConsoleLock)
                {
                    ConsoleKeyInfo key;
                    Console.WriteLine("Resize the window to a size you like and press any key.");
                    do
                    {
                        key = Console.ReadKey(true);
                    } while (key.Key == LeftWindows || key.Key == RightWindows);
                }
            }

            screens = new List <VScreen>();

            if (Settings.ShowIntro)
            {
                Intro();
            }
            lock (ConsoleLock)
            {
                // Virtual screen sizes. They were found by trial and error.
                int vheight = (int)(Console.WindowHeight / 2.5);
                int vwidth  = (int)(Console.WindowWidth / 5.5);
                // v?Border = size with space we are leaving for the borders
                int vhBorder = vheight + 1;
                int vwBorder = vwidth + 1;

                // All screens need to have a space in-between for the border.
                for (int yOffset = 0; yOffset < Console.WindowHeight - vhBorder; yOffset += vhBorder)
                {
                    int xOffset = 0;
                    for (; xOffset < Console.WindowWidth - vwBorder; xOffset += vwBorder)
                    {
                        if (screens.Count != ScreenCount)
                        {
                            var screen = new VScreen(vwidth, vheight, xOffset, yOffset);
                            screens.Add(screen);
                            screen.PrintBorders();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     Prints borders around the screen.
        /// </summary>
        /// <param name="screen">VScreen to have its borders printed</param>
        /// <param name="verticalBorderChar">Border for the right-hand border.</param>
        /// <param name="horizontalBorderChar">Border for the bottom border</param>
        /// <param name="color">Optional ConsoleColor to print the borders in</param>
        public static void PrintBorders(this VScreen screen, char horizontalBorderChar = '-',
                                        char verticalBorderChar = '|', ConsoleColor color = ConsoleColor.White)
        {
            lock (ConsoleLock)
            {
                ConsoleColor prevColor = Console.ForegroundColor;
                Console.ForegroundColor = color;
                // Print vertical right-hand screen border
                Console.CursorLeft = screen.XOffset + screen.WindowWidth;
                for (int y = 0; y < screen.WindowHeight; ++y)
                {
                    try
                    {
                        Console.CursorTop = screen.YOffset + y;
                        Console.Write(verticalBorderChar);
                        // Move the cursor left after writing
                        --Console.CursorLeft;
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        /* ignore, user error with offset or VScreen size */
                    }
                }

                // Print horizontal bottom screen border
                Console.CursorTop  = screen.YOffset + screen.WindowHeight;
                Console.CursorLeft = screen.XOffset;
                var sb = new StringBuilder();
                for (int x = 0; x <= screen.WindowWidth; ++x)
                {
                    sb.Append(horizontalBorderChar);
                }
                Console.Write(sb);

                Console.ForegroundColor = prevColor;
            }
        }