Пример #1
0
        private static void Program_KeyDown(ConsoleRenderProgram sender, ConsoleRenderProgramKeyEventArgs e)
        {
            // DEBUG: Print key to the general log
            string value = e.GetAssociatedString(CapsLockState);
            string cval  = ((int)e.Key).ToString("X2");

            Log.WriteLine($"0x{cval} {e.Key} -> {value}");
            // End of Debug print

            e.Intercept = true;

            if (e.Key == OpenToolkit.Windowing.Common.Input.Key.Escape)
            {
                sender.Stop();
            }

            if (e.Key == OpenToolkit.Windowing.Common.Input.Key.F11)
            {
                restartGraphicsProgram = true;
                sender.Stop();
                sender.Renderer.Fullscreen = !sender.Renderer.Fullscreen;

                if (sender.Renderer.Fullscreen)
                {
                    sender.Renderer.InternalResolution = new Size(1280, 1024);
                    sender.ConsoleSize = new Size(300, 75);
                }
                else
                {
                    sender.Renderer.InternalResolution = new Size(960, 480);
                    sender.ConsoleSize = new Size(120, 30);
                }
            }

            if (e.Key == OpenToolkit.Windowing.Common.Input.Key.F1)
            {
                sender.ForeColor = Color.Cyan;
                Log.WriteLine("Colored line sample here");
                sender.ForeColor = sender.DefaultForeColor;
            }

            if (e.Key == OpenToolkit.Windowing.Common.Input.Key.CapsLock)
            {
                CapsLockState = !CapsLockState;
            }
        }
Пример #2
0
        public static int Main(string[] args)
        {
            Log.Initialize(false);
            Log.Console.Enabled      = true;
            Log.Console.MinimumLevel = LogLevel.Debug;

            Log.WriteLine("Console3D Test App");
            Log.WriteLine("Running on %@ %@ (%@)",
                          LogLevel.Message,
                          GetPlatformName(),
                          RuntimeInformation.ProcessArchitecture,
                          RuntimeInformation.OSDescription);
            Log.WriteLine();

            Log.WriteLine("Checking custom fonts...");
            CheckRasterFonts();

            Log.WriteLine("Starting Render Thread...");

            RenderThread renderThread = new RenderThread(new Size(960, 480), new Size(960, 480));

            renderThread.Asynchronous = false;
            renderThread.WindowTitle  = "Console3D - OpenGL";
            renderThread.Initialize();

            KeyConverter.Default = new KeyConverter("en-US");
            KeyConverter.Default.IgnoreLoadErrors = false;
            using (FileStream fs = new FileStream("./res/layout_en-US.txt", FileMode.Open, FileAccess.Read, FileShare.Read))
                KeyConverter.Default.LoadLayout(fs);

            ConsoleRenderProgram program;

            program          = new ConsoleRenderProgram(renderThread);
            program.FontName = "Unifont";
            program.KeyDown += Program_KeyDown;

            Log.WriteLine("Starting render thread in %@ mode...",
                          LogLevel.Message,
                          renderThread.Asynchronous ? "Asynchronous" : "Synchronous");

            RzSwLogAdapter adapter = new RzSwLogAdapter(program);

            Log.AttachOutput(adapter);

            program.Run();

            // Main thread is free

            while (restartGraphicsProgram && !renderThread.Asynchronous)
            {
                restartGraphicsProgram = false;
                program.Stop();
                program.Run();
            }
            while (renderThread.Asynchronous && !Console.KeyAvailable && renderThread.IsRunning)
            {
                if (!renderThread.AutoEventPolling)
                {
                    renderThread.ProcessEvents();
                    if (renderThread.TimeSinceLastFrame > 1000)
                    {
                        int amount = (int)(renderThread.TimeSinceLastFrame / 2000.0f);
                        if (amount >= 3)
                        {
                            Thread.Sleep(amount);
                        }
                    }
                }
                else
                {
                    Thread.Sleep(1000);
                }
            }

            program.Stop();
            Log.WriteLine("Render thread has been stopped.");

            Log.WriteLine("Shutting down Render thread...");
            program.Dispose();

            return(0);
        }