/// <summary> Creates a new ConsoleEngine. </summary>
        /// <param name="width">Target window width.</param>
        /// <param name="height">Target window height.</param>
        /// <param name="fontW">Target font width.</param>
        /// <param name="fontH">Target font height.</param>
        public ConsoleEngine(int width, int height, int fontW, int fontH)
        {
            if (width < 1 || height < 1)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (fontW < 1 || fontH < 1)
            {
                throw new ArgumentOutOfRangeException();
            }

            Console.Title         = "Untitled console application";
            Console.CursorVisible = false;

            // sätter fönstret och bufferns storlek
            // buffern måste sättas efter fönsret, eftersom den aldrig får vara mindre än skärmen
            Console.SetWindowSize(width, height);
            Console.SetBufferSize(width, height);

            ConsoleBuffer = new ConsoleBuffer(width, height);

            WindowSize = new Point(width, height);
            FontSize   = new Point(fontW, fontH);

            CharBuffer  = new char[width, height];
            ColorBuffer = new int[width, height];

            SetBackground(0);
            SetPalette(Palettes.Default);

            // Stänger av alla standard ConsoleInput metoder (Quick-edit etc)
            NativeMethods.SetConsoleMode(stdInputHandle, 0x0080);

            // Sätter fontstorlek och tvingar Raster (Terminal) / Consolas
            // Detta måste göras efter SetBufferSize, annars ger den en IOException
            ConsoleFont.SetFont(stdOutputHandle, (short)fontW, (short)fontH);
        }
Exemple #2
0
        /// <summary> Creates a new ConsoleEngine. </summary>
        /// <param name="width">Target window width.</param>
        /// <param name="height">Target window height.</param>
        /// <param name="fontW">Target font width.</param>
        /// <param name="fontH">Target font height.</param>


        public ConsoleEngine(int width, int height, int fontW, int fontH, short?sfontSize = null, string sfontName = null)
        {
            if (width < 1 || height < 1)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (fontW < 1 || fontH < 1)
            {
                throw new ArgumentOutOfRangeException();
            }

            Console.Title         = "Untitled console application";
            Console.CursorVisible = false;

            // sätter fönstret och bufferns storlek
            // buffern måste sättas efter fönsret, eftersom den aldrig får vara mindre än skärmen
            //var test0 = new System.Drawing.Font("Consolas", 16);
            //AWV:
            if (!String.IsNullOrEmpty(sfontName) || sfontSize != null)
            {
                ////    if (String.IsNullOrEmpty(sfontName))
                ////    {
                ////        sfontName = _defaultFONTNAME;
                ////    }
                ////    if(sfontSize == null)
                ////    {
                ////        sfontSize = _defaultFONTSIZE;
                ////    }
                //GetFontInfo gfi = new GetFontInfo();
                //IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE);
                //if (hnd != INVALID_HANDLE_VALUE)
                //{
                //    CONSOLE_FONT_INFO_EX ConsoleFontInfo = new CONSOLE_FONT_INFO_EX();
                //    ConsoleFontInfo.cbSize = (uint)Marshal.SizeOf(ConsoleFontInfo);
                //    bool tt = false;
                //    // First determine whether there's already a TrueType font.
                //    if (GetCurrentConsoleFontEx(hnd, false, ref ConsoleFontInfo))
                //    {

                //        tt = (ConsoleFontInfo.FontFamily & TMPF_TRUETYPE) == TMPF_TRUETYPE;
                //        //if (tt)
                //        //{
                //        //    Console.WriteLine("The console already is using a TrueType font.");
                //        //    return;
                //        //}
                //        // Set console font to Lucida Console.
                //        CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX();
                //        newInfo.cbSize = (uint)Marshal.SizeOf(newInfo);
                //        newInfo.FontFamily = TMPF_TRUETYPE;


                //        if (String.IsNullOrEmpty(sfontName))
                //        {
                //            sfontName = gfi.GetFontName();
                //        }
                //            IntPtr ptr = new IntPtr(newInfo.FaceName);
                //            Marshal.Copy(sfontName.ToCharArray(), 0, ptr, sfontName.Length);


                //        if (sfontSize == null)
                //        {
                //            newInfo.dwFontSize = new Coord.COORD(ConsoleFontInfo.dwFontSize.X, ConsoleFontInfo.dwFontSize.Y);
                //        }
                //        else
                //        {
                //            var newFont = gfi.calcFontSize(sfontSize.Value);
                //            newInfo.dwFontSize = new Coord.COORD(newFont.X, newFont.Y);
                //        }
                //        newInfo.FontWeight = ConsoleFontInfo.FontWeight;
                //        SetCurrentConsoleFontEx(hnd, false, newInfo);
                //    }
                //}
                //Above code got obsolate with PInvokeConsoleHelper Class and GetFontInfo Class
                GetFontInfo gfi = new GetFontInfo();
                if (String.IsNullOrEmpty(sfontName))
                {
                    sfontName = gfi.GetFontName();
                }
                if (sfontSize == null)
                {
                    sfontSize = gfi.GetFontSize();
                }

                PInvokeConsoleHelper.SetCurrentFont(sfontName, sfontSize.Value);
            }

            //try
            //{
            var test1 = Console.LargestWindowHeight;
            var test2 = Console.LargestWindowWidth;

            Console.SetWindowSize(width, height);

            //}
            //catch (ArgumentOutOfRangeException ex)
            //{
            //Console to big
            //}
            Console.SetBufferSize(width, height);


            ConsoleBuffer = new ConsoleBuffer(width, height);

            WindowSize = new Point(width, height);
            FontSize   = new Point(fontW, fontH);

            CharBuffer  = new char[width, height];
            ColorBuffer = new int[width, height];

            SetBackground(0);
            SetPalette(Palettes.Default);

            // Stänger av alla standard ConsoleInput metoder (Quick-edit etc)
            NativeMethods.SetConsoleMode(stdInputHandle, 0x0080);

            // Sätter fontstorlek och tvingar Raster (Terminal) / Consolas
            // Detta måste göras efter SetBufferSize, annars ger den en IOException
            ConsoleFont.SetFont(stdOutputHandle, (short)fontW, (short)fontH);
        }
Exemple #3
0
 /// <summary> Blits the screenbuffer to the Console window. </summary>
 public void DisplayBuffer()
 {
     ConsoleBuffer.SetBuffer(CharBuffer, ColorBuffer, Background);
     ConsoleBuffer.Blit();
 }
Exemple #4
0
 /// <summary> Blits the screenbuffer to the Console window. </summary>
 public void DisplayBuffer()
 {
     ConsoleBuffer.SetBuffer(GlyphBuffer, Background);
     ConsoleBuffer.Blit();
 }