using Dashboard.Drawing; using System.Drawing; using System.Text; using Dashboard; using Dashboard.Drawing.OpenGL; using Dashboard.Drawing.OpenGL.Text; using Dashboard.ImmediateUI; using OpenTK.Graphics; using OpenTK.Platform; using OpenTK.Graphics.OpenGL; using OpenTK.Mathematics; using Box2d = Dashboard.Box2d; using TK = OpenTK.Platform.Toolkit; using sys = System.Numerics; using otk = OpenTK.Mathematics; TK.Init(new ToolkitOptions() { ApplicationName = "DashTerm", Windows = new ToolkitOptions.WindowsOptions() { EnableVisualStyles = true, IsDPIAware = true, } }); WindowHandle wnd = TK.Window.Create(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, }); TK.Window.SetTitle(wnd, "DashTerm"); TK.Window.SetMinClientSize(wnd, 300, 200); TK.Window.SetClientSize(wnd, new Vector2i(320, 240)); TK.Window.SetBorderStyle(wnd, WindowBorderStyle.ResizableBorder); // TK.Window.SetTransparencyMode(wnd, WindowTransparencyMode.TransparentFramebuffer, 0.1f); OpenGLContextHandle context = TK.OpenGL.CreateFromWindow(wnd); TK.OpenGL.SetCurrentContext(context); TK.OpenGL.SetSwapInterval(1); GLLoader.LoadBindings(new Pal2BindingsContext(TK.OpenGL, context)); DrawQueue queue = new DrawQueue(); SolidBrush fg = new SolidBrush(Color.FromArgb(0, 0, 0, 0)); SolidBrush bg = new SolidBrush(Color.Black); bool shouldExit = false; GLEngine engine = new GLEngine(); engine.Initialize(); GlContext dbGlContext = new GlContext(wnd, context); ContextExecutor executor = engine.GetExecutor(dbGlContext); DimUI dimUI = new DimUI(new DimUIConfig() { Font = new NamedFont("Noto Sans", 9f), }); Vector2 mousePos = Vector2.Zero; Random r = new Random(); EventQueue.EventRaised += (handle, type, eventArgs) => { if (handle != wnd) return; switch (type) { case PlatformEventType.Close: shouldExit = true; break; case PlatformEventType.MouseMove: mousePos = ((MouseMoveEventArgs)eventArgs).ClientPosition; break; } }; TK.Window.SetMode(wnd, WindowMode.Normal); List points = new List(); IFont font = Typesetter.LoadFont("Nimbus Mono", 12f); StringBuilder builder = new StringBuilder(); while (!shouldExit) { TK.Window.ProcessEvents(true); TK.Window.GetFramebufferSize(wnd, out Vector2i framebufferSize); executor.BeginFrame(); dimUI.Begin(new Box2d(0, 0, framebufferSize.X, framebufferSize.Y), queue); 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(queue); executor.EndFrame(); queue.Clear(); TK.OpenGL.SwapBuffers(context); } class GlContext : IGLContext { public WindowHandle Window { get; } public OpenGLContextHandle Context { get; } public int ContextGroup { get; } = -1; public Size FramebufferSize { get { TK.Window.GetFramebufferSize(Window, out Vector2i framebufferSize); return new Size(framebufferSize.X, framebufferSize.Y); } } public event Action? Disposed; public GlContext(WindowHandle window, OpenGLContextHandle context) { Window = window; Context = context; OpenGLContextHandle? shared = TK.OpenGL.GetSharedContext(context); if (shared != null) { ContextGroup = _contexts.IndexOf(shared); } else { _contexts.Add(context); } } private static readonly List _contexts = new List(); }