Dashboard/tests/Dashboard.TestApplication/Program.cs

170 lines
4.3 KiB
C#

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;
TK.Init(new ToolkitOptions()
{
ApplicationName = "DashTerm",
Windows = new ToolkitOptions.WindowsOptions()
{
EnableVisualStyles = true,
IsDPIAware = true,
}
});
PhysicalWindow window = new PhysicalWindow(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,
});
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;
GLLoader.LoadBindings(new Pal2BindingsContext(TK.OpenGL, context.ContextHandle));
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();
ContextExecutor executor = engine.GetExecutor(context);
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 != window.WindowHandle)
return;
switch (type)
{
case PlatformEventType.Close:
shouldExit = true;
break;
case PlatformEventType.MouseMove:
mousePos = ((MouseMoveEventArgs)eventArgs).ClientPosition;
break;
}
};
TK.Window.SetMode(window.WindowHandle, WindowMode.Normal);
List<Vector3> points = new List<Vector3>();
IFont font = Typesetter.LoadFont("Nimbus Mono", 12f);
StringBuilder builder = new StringBuilder();
while (!shouldExit)
{
TK.Window.ProcessEvents(true);
TK.Window.GetFramebufferSize(context.WindowHandle, 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();
context.SwapGroup.Swap();
}