Пример #1
0
 //initializes the page simply
 public unsafe void Initialize(bool _cursor = false)
 {
     Handle = XConsole.CreateConsoleScreenBuffer(
         XConsole.GENERIC_READ | XConsole.GENERIC_WRITE, XConsole.FILE_SHARE_READ | XConsole.FILE_SHARE_WRITE,
         IntPtr.Zero, XConsole.CONSOLE_TEXTMODE_BUFFER, IntPtr.Zero);
     XConsole.SetCursor(Handle, _cursor);
     cursor = _cursor;
 }
Пример #2
0
 //draws a surface to the region marked as a viewport.
 //the viewport cuts the
 public unsafe void Draw(Viewport vp, Surface surf)
 {
     XConsole.SMALL_RECT temp = vp.transform;
     fixed(XConsole.CHAR_INFO *p = &surf.Buffer[0])
     {
         XConsole.WriteConsoleOutput(
             Handle,                         // screen buffer to write to
             p,                              // buffer to copy from
             surf.size,                      // col-row size of Buffer
             vp.scroll,                      // top left src cell in Buffer
             &temp);                         // dest. screen buffer rectangle
         //return XConsole.GetLastError();
     };
 }
Пример #3
0
        //initializes the page and sets the palette
        public unsafe void Initialize(XConsole.PALETTE palette, bool _cursor = false)
        {
            Initialize(_cursor);
            XConsole.CONSOLE_SCREEN_BUFFER_INFO_EX sbi = new XConsole.CONSOLE_SCREEN_BUFFER_INFO_EX();
            sbi.cbSize = sizeof(XConsole.CONSOLE_SCREEN_BUFFER_INFO_EX);
            IntPtr sbiptr = new IntPtr(&sbi);

            XConsole.GetConsoleScreenBufferInfoEx(Handle, sbiptr);
            for (int n = 0; n < XConsole.PALETTE_SIZE; n++)
            {
                sbi.Palette[n] = new XConsole.RGBXConverter(palette.rgbx[n]).UINT;
            }
            XConsole.SetConsoleScreenBufferInfoEx(Handle, sbiptr);
        }
Пример #4
0
        //y2 is in bitmap's coordinates.
        //for example y2=13 means 6 row bground color
        public void SetPixel(int x, int y2, byte color16)
        {
            int y = y2 >> 1;

            if (x < 0 || y < 0 || x > surf.size.x - 1 || y > surf.size.y - 1)
            {
                return;
            }
            if ((y2 & 1) == 1)
            {
                surf.Buffer[y * surf.size.x + x].Color = XConsole.ColorXor(surf.Buffer[y * surf.size.x + x].Color, color16);
            }
            else
            {
                surf.Buffer[y * surf.size.x + x].Color = XConsole.ColorXor((byte)(color16 << 4), surf.Buffer[y * surf.size.x + x].Color);
            }
        }
Пример #5
0
 public static int Initialize(int width, int height, string lpConsoleTitle = "XConsole", XConsole.PALETTE palette = null, bool cursor = false)
 {
     XConsole.SetConsoleTitle(lpConsoleTitle);
     Console.SetWindowSize(width, height);
     Console.SetBufferSize(width, height);
     if (palette != null)
     {
         page.Initialize(palette, cursor);
     }
     else
     {
         page.Initialize(cursor);
     }
     bgroundsurface = new Surface(new XConsole.SMALL_COORD(width, height));
     bgroundsurface.Clear(XConsole.DEFAULT_STYLE);
     page.Active();
     bgroundviewport = new Viewport(new XConsole.SMALL_RECT(0, 0, width, height));
     return(XConsole.GetLastError());
 }
Пример #6
0
        static unsafe void Main(string[] args)
        {
            //create custom palette
            XConsole.PALETTE pal = new XConsole.PALETTE();
            pal.rgbx[1]  = new XConsole.RGBX(35, 1, 5);
            pal.rgbx[2]  = new XConsole.RGBX(60, 7, 3);
            pal.rgbx[3]  = new XConsole.RGBX(100, 22, 2);
            pal.rgbx[4]  = new XConsole.RGBX(143, 44, 0);
            pal.rgbx[5]  = new XConsole.RGBX(181, 61, 1);
            pal.rgbx[6]  = new XConsole.RGBX(224, 60, 0);
            pal.rgbx[7]  = new XConsole.RGBX(200, 60, 80);
            pal.rgbx[8]  = new XConsole.RGBX(170, 60, 130);
            pal.rgbx[9]  = new XConsole.RGBX(150, 78, 155);
            pal.rgbx[10] = new XConsole.RGBX(118, 95, 188);
            pal.rgbx[11] = new XConsole.RGBX(100, 170, 200);
            pal.rgbx[12] = new XConsole.RGBX(157, 227, 236);
            pal.rgbx[13] = new XConsole.RGBX(0x7F, 0x7F, 0x7F);
            pal.rgbx[14] = new XConsole.RGBX(0x3F, 0x0, 0x0);
            pal.rgbx[15] = new XConsole.RGBX(0x0, 0xFF, 0x0);

            //create a crutch and set the console title and console's window size
            Window.Initialize(129, 59, "XConsole", pal);

            //a pair of styles
            Style s  = new Style(1, 4, true);
            Style s2 = new Style(0, 13, true);

            //separate surface ans viewport
            Surface  simpletext   = new Surface(new XConsole.SMALL_COORD(64, 40));
            Viewport simpletextvp = new Viewport(new XConsole.SMALL_RECT(80, 27, 115, 45));

            //write text till the surface is filled
            //the text wraps and has different colors
            for (int n = 0; n < 100; n++)
            {
                s.color = (byte)(n);
                simpletext.Write(XConsole.EncodeASCII(" HELLO WORLD " + n.ToString()), s);
            }

            //three percentage scales
            PercentScale ps  = new PercentScale(10, 50, 100);
            PercentScale ps2 = new PercentScale(10, 52, 100);
            PercentScale ps3 = new PercentScale(10, 54, 100);

            //fire effect
            Fire fire = new Fire(5, 0, 72, 48);

            //sprite with 4 frames
            Sprite bm = new Sprite(80, 3, 35, 20, 4);

            for (int l = 0; l < 4; l++)
            {
                for (int n = 0; n < 40; n++)
                {
                    for (int i = 0; i < bm.surface.size.x; i++)
                    {
                        bm.SetPixel(i, n + l * 40, (byte)((l * 3) + 6));
                        bm.SetPixel(0, 0 + l * 40, 13);
                        bm.SetPixel(34, 39 + l * 40, 13);
                    }
                }
            }

            int   unknown = 0;
            int   frame   = 0;
            float k       = 0;

            //the cycle
            do
            {
                Window.Clear(); //clear the screen with black
                Window.Draw(ps);
                Window.Draw(ps2);
                Window.Draw(ps3);
                Window.Draw(fire);
                bm.SetFrame(frame >> 4); //sets a frame
                Window.Draw(bm);
                Window.Draw(simpletextvp, simpletext);

                Thread.Sleep(10);  //relaxes the system, prevent the screen flashing

                //updates the elements
                ps.Update(k, s2);
                ps2.Update((int)(100 - k), 100, s2);
                ps3.Update(ref unknown, s2);
                fire.Update(2000);
                if (k < 100)
                {
                    k += 0.1f;
                }
                else
                {
                    k = 0;
                }
                if (frame++ == 64)
                {
                    frame = 0;
                }
            } while (!Console.KeyAvailable);
            Console.ReadKey();
        }
Пример #7
0
 //writes a text. If the text is longer than a buffer it trims.
 //no scroll. The cursor position is at the end of the line or out of the limits
 public void Write(string text, Style style)
 {
     Write(XConsole.EncodeASCII(text), style);
 }
Пример #8
0
 public Style(byte bgcolor, byte textcolor, bool _frame = false)
 {
     color = XConsole.ColorConverter(bgcolor, textcolor);
     frame = _frame;
 }
Пример #9
0
 //Every page must be active before writing to it.
 //Unfirtunately avtive=visible so there is no pageflipping
 public int Active()
 {
     XConsole.SetConsoleActiveScreenBuffer(Handle);
     return(XConsole.GetLastError());
 }