Example #1
0
        public static void CreateScreen()
        {
            if (Surface != IntPtr.Zero)
            {
                SDL_FreeSurface(Surface);
                Surface = IntPtr.Zero;
            }

            Surface = SDL_CreateRGBSurface(0, Eight.RealWidth,
                                           Eight.RealHeight, 32,
                                           0xff000000,
                                           0x00ff0000,
                                           0x0000ff00,
                                           0x000000ff);

            if (Surface == IntPtr.Zero)
            {
                Console.WriteLine("SDL_CreateRGBSurface() failed: " + SDL_GetError());
                Eight.Quit();
            }

            TextGrid  = new ulong[Eight.WindowWidth * Eight.WindowHeight];
            TextFlags = new byte[Eight.WindowWidth * Eight.WindowHeight];

            Dirty = true;
        }
Example #2
0
        public static string ReadLine(int?maxLen, string regex = "*")
        {
            string input = "";
            int    ox    = X;
            int    oy    = Y;

            var redraw = new Action(() => {
                X = ox;
                Y = oy;
                Print(input + " ");
                Render();
            });

            Render();
            bool exit = false;

            while (SDL_WaitEvent(out var _ev) != 0 && !exit)
            {
                if (_ev.type == SDL_EventType.SDL_QUIT)
                {
                    Eight.Quit();
                    break;
                }

                if (_ev.type == SDL_EventType.SDL_TEXTINPUT)
                {
                    byte[] c;
                    unsafe {
                        c = Utils.CString(_ev.text.text);
                    }
                    var chunk = Encoding.UTF8.GetString(c);

                    if (Regex.IsMatch(chunk, regex))
                    {
                        input += chunk;
                    }

                    if (maxLen != null)
                    {
                        input = input.Substring(0, Math.Min((int)maxLen, input.Length));
                    }
                    redraw();
                }

                if (_ev.type == SDL_EventType.SDL_KEYDOWN)
                {
                    switch (_ev.key.keysym.sym)
                    {
                    case SDL_Keycode.SDLK_RETURN:
                        exit = true;
                        break;

                    case SDL_Keycode.SDLK_BACKSPACE:
                        if (input.Length > 0)
                        {
                            input = input.Substring(0, input.Length - 1);
                            redraw();
                        }
                        break;
                    }
                }
            }

            return(input);
        }