2024-12-13 19:57:07 +01:00
|
|
|
|
using Dashboard.Drawing;
|
|
|
|
|
using System.Drawing;
|
2025-01-25 13:39:18 +01:00
|
|
|
|
using System.Text;
|
2025-01-14 18:34:47 +01:00
|
|
|
|
using Dashboard.Drawing.OpenGL;
|
2025-01-25 10:34:37 +01:00
|
|
|
|
using Dashboard.ImmediateUI;
|
2025-02-02 19:58:49 +01:00
|
|
|
|
using Dashboard.OpenTK.PAL2;
|
2025-01-14 18:34:47 +01:00
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using OpenTK.Platform;
|
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
|
using OpenTK.Mathematics;
|
2025-01-25 10:34:37 +01:00
|
|
|
|
using Box2d = Dashboard.Box2d;
|
2025-01-14 18:34:47 +01:00
|
|
|
|
using TK = OpenTK.Platform.Toolkit;
|
2025-02-11 21:29:26 +01:00
|
|
|
|
using Dashboard;
|
2024-12-13 19:57:07 +01:00
|
|
|
|
|
2025-01-14 18:34:47 +01:00
|
|
|
|
TK.Init(new ToolkitOptions()
|
|
|
|
|
{
|
2025-01-25 10:34:37 +01:00
|
|
|
|
ApplicationName = "DashTerm",
|
2025-01-14 18:34:47 +01:00
|
|
|
|
Windows = new ToolkitOptions.WindowsOptions()
|
|
|
|
|
{
|
|
|
|
|
EnableVisualStyles = true,
|
|
|
|
|
IsDPIAware = true,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
Application app = new Application(new Pal2DashboardBackend()
|
|
|
|
|
{
|
|
|
|
|
GraphicsApiHints = new OpenGLGraphicsApiHints()
|
|
|
|
|
{
|
|
|
|
|
Version = new Version(3, 2),
|
|
|
|
|
ForwardCompatibleFlag = true,
|
|
|
|
|
DebugFlag = true,
|
|
|
|
|
Profile = OpenGLProfile.Core,
|
|
|
|
|
sRGBFramebuffer = true,
|
2025-01-14 18:34:47 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
SwapMethod = ContextSwapMethod.Undefined,
|
2025-01-14 18:34:47 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
RedColorBits = 8,
|
|
|
|
|
GreenColorBits = 8,
|
|
|
|
|
BlueColorBits = 8,
|
|
|
|
|
AlphaColorBits = 8,
|
|
|
|
|
Multisamples = 0,
|
2025-01-14 18:34:47 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
SupportTransparentFramebufferX11 = true,
|
|
|
|
|
}
|
2025-01-14 18:34:47 +01:00
|
|
|
|
});
|
2025-02-02 19:58:49 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
PhysicalWindow window;
|
2025-01-18 21:30:56 +01:00
|
|
|
|
SolidBrush fg = new SolidBrush(Color.FromArgb(0, 0, 0, 0));
|
|
|
|
|
SolidBrush bg = new SolidBrush(Color.Black);
|
2025-02-11 21:29:26 +01:00
|
|
|
|
CancellationTokenSource source = new CancellationTokenSource();
|
|
|
|
|
GLEngine engine;
|
|
|
|
|
ContextExecutor executor;
|
|
|
|
|
DimUI dimUI;
|
2025-01-18 21:30:56 +01:00
|
|
|
|
Vector2 mousePos = Vector2.Zero;
|
|
|
|
|
Random r = new Random();
|
|
|
|
|
List<Vector3> points = new List<Vector3>();
|
2025-02-11 21:29:26 +01:00
|
|
|
|
IFont font;
|
2025-01-25 13:39:18 +01:00
|
|
|
|
StringBuilder builder = new StringBuilder();
|
2025-01-22 20:42:43 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
app.PostInitializing += (sender, ea) => {
|
|
|
|
|
window = (PhysicalWindow)app.CreatePhysicalWindow();
|
2025-01-14 18:34:47 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
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);
|
2025-01-25 13:39:18 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
OpenGLDeviceContext context = (OpenGLDeviceContext)window.DeviceContext;
|
2025-01-25 10:34:37 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
context.MakeCurrent();
|
|
|
|
|
context.SwapGroup.SwapInterval = 1;
|
2025-01-25 10:34:37 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
engine = new GLEngine();
|
|
|
|
|
engine.Initialize();
|
|
|
|
|
|
|
|
|
|
executor = engine.GetExecutor(context);
|
|
|
|
|
|
|
|
|
|
dimUI = new DimUI(new DimUIConfig()
|
2025-01-25 10:34:37 +01:00
|
|
|
|
{
|
2025-02-11 21:29:26 +01:00
|
|
|
|
Font = new NamedFont("Noto Sans", 9f),
|
|
|
|
|
});
|
2025-01-25 10:34:37 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
EventQueue.EventRaised += (handle, type, eventArgs) =>
|
2025-01-25 10:34:37 +01:00
|
|
|
|
{
|
2025-02-11 21:29:26 +01:00
|
|
|
|
if (handle != window.WindowHandle)
|
|
|
|
|
return;
|
2025-01-25 10:34:37 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
switch (type)
|
2025-01-25 10:34:37 +01:00
|
|
|
|
{
|
2025-02-11 21:29:26 +01:00
|
|
|
|
case PlatformEventType.Close:
|
|
|
|
|
source.Cancel();
|
|
|
|
|
break;
|
|
|
|
|
case PlatformEventType.MouseMove:
|
|
|
|
|
mousePos = ((MouseMoveEventArgs)eventArgs).ClientPosition;
|
|
|
|
|
break;
|
2025-01-25 10:34:37 +01:00
|
|
|
|
}
|
2025-02-11 21:29:26 +01:00
|
|
|
|
};
|
2025-01-25 10:34:37 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
TK.Window.SetMode(window.WindowHandle, WindowMode.Normal);
|
|
|
|
|
font = Typesetter.LoadFont("Nimbus Mono", 12f);
|
2025-01-25 10:34:37 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
window.Painting += (sender, ea) => {
|
|
|
|
|
TK.Window.GetFramebufferSize(context.WindowHandle, out Vector2i framebufferSize);
|
|
|
|
|
executor.BeginFrame();
|
2025-01-25 10:34:37 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
dimUI.Begin(new Box2d(0, 0, framebufferSize.X, framebufferSize.Y), window.DrawQueue);
|
|
|
|
|
dimUI.Text("Hello World!");
|
|
|
|
|
dimUI.Button("Cancel"); dimUI.SameLine();
|
|
|
|
|
dimUI.Button("OK");
|
2025-01-25 10:34:37 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
dimUI.Input("type me!", builder);
|
2025-01-14 18:34:47 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
dimUI.BeginMenu();
|
2025-01-14 18:34:47 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
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();
|
|
|
|
|
};
|
|
|
|
|
};
|
2025-01-14 18:34:47 +01:00
|
|
|
|
|
2025-02-11 21:29:26 +01:00
|
|
|
|
app.Run(true, source.Token);
|