using Dashboard.Drawing; using System.Drawing; using System.Text; using Dashboard.Drawing.OpenGL; using Dashboard.ImmediateUI; using Dashboard.OpenTK.PAL2; using OpenTK.Graphics; using OpenTK.Platform; using OpenTK.Graphics.OpenGL; using OpenTK.Mathematics; using Box2d = Dashboard.Box2d; using TK = OpenTK.Platform.Toolkit; using Dashboard; TK.Init(new ToolkitOptions() { ApplicationName = "DashTerm", Windows = new ToolkitOptions.WindowsOptions() { EnableVisualStyles = true, IsDPIAware = true, } }); Application app = new Application(new Pal2DashboardBackend() { GraphicsApiHints = new OpenGLGraphicsApiHints() { Version = new Version(3, 2), ForwardCompatibleFlag = true, DebugFlag = true, Profile = OpenGLProfile.Core, sRGBFramebuffer = true, SwapMethod = ContextSwapMethod.Undefined, RedColorBits = 8, GreenColorBits = 8, BlueColorBits = 8, AlphaColorBits = 8, Multisamples = 0, SupportTransparentFramebufferX11 = true, } }); PhysicalWindow window; SolidBrush fg = new SolidBrush(Color.FromArgb(0, 0, 0, 0)); SolidBrush bg = new SolidBrush(Color.Black); CancellationTokenSource source = new CancellationTokenSource(); GLEngine engine; ContextExecutor executor; DimUI dimUI; Vector2 mousePos = Vector2.Zero; Random r = new Random(); List points = new List(); IFont font; StringBuilder builder = new StringBuilder(); app.PostInitializing += (sender, ea) => { window = (PhysicalWindow)app.CreatePhysicalWindow(); window.Title = "DashTerm"; TK.Window.SetMinClientSize(window.WindowHandle, 300, 200); TK.Window.SetClientSize(window.WindowHandle, new Vector2i(320, 240)); TK.Window.SetBorderStyle(window.WindowHandle, WindowBorderStyle.ResizableBorder); // TK.Window.SetTransparencyMode(wnd, WindowTransparencyMode.TransparentFramebuffer, 0.1f); OpenGLDeviceContext context = (OpenGLDeviceContext)window.DeviceContext; context.MakeCurrent(); context.SwapGroup.SwapInterval = 1; engine = new GLEngine(); engine.Initialize(); executor = engine.GetExecutor(context); dimUI = new DimUI(new DimUIConfig() { Font = new NamedFont("Noto Sans", 9f), }); EventQueue.EventRaised += (handle, type, eventArgs) => { if (handle != window.WindowHandle) return; switch (type) { case PlatformEventType.Close: source.Cancel(); break; case PlatformEventType.MouseMove: mousePos = ((MouseMoveEventArgs)eventArgs).ClientPosition; break; } }; TK.Window.SetMode(window.WindowHandle, WindowMode.Normal); font = Typesetter.LoadFont("Nimbus Mono", 12f); window.Painting += (sender, ea) => { TK.Window.GetFramebufferSize(context.WindowHandle, out Vector2i framebufferSize); executor.BeginFrame(); dimUI.Begin(new Box2d(0, 0, framebufferSize.X, framebufferSize.Y), window.DrawQueue); dimUI.Text("Hello World!"); dimUI.Button("Cancel"); dimUI.SameLine(); dimUI.Button("OK"); dimUI.Input("type me!", builder); dimUI.BeginMenu(); if (dimUI.MenuItem("File")) { dimUI.BeginMenu(); dimUI.MenuItem("New Window"); dimUI.MenuItem("Preferences"); dimUI.MenuItem("Exit"); dimUI.EndMenu(); } if (dimUI.MenuItem("Edit")) { dimUI.BeginMenu(); dimUI.MenuItem("Cut"); dimUI.MenuItem("Copy"); dimUI.MenuItem("Paste"); if (dimUI.MenuItem("Send Char")) { dimUI.BeginMenu(); dimUI.EndMenu(); } dimUI.EndMenu(); } if (dimUI.MenuItem("View")) { dimUI.BeginMenu(); dimUI.MenuItem("Clear"); if (dimUI.MenuItem("Set Size")) { dimUI.BeginMenu(); dimUI.MenuItem("24 x 40"); dimUI.MenuItem("25 x 40"); dimUI.MenuItem("24 x 80"); dimUI.MenuItem("25 x 80"); dimUI.MenuItem("25 x 120"); dimUI.EndMenu(); } dimUI.EndMenu(); } dimUI.Finish(); GL.Viewport(0, 0, framebufferSize.X, framebufferSize.Y); GL.ClearColor(0.3f, 0.3f, 0.3f, 1.0f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Disable(EnableCap.DepthTest); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.ColorMask(true, true, true, true); executor.Draw(window.DrawQueue); executor.EndFrame(); context.SwapGroup.Swap(); }; }; app.Run(true, source.Token);