215 lines
6.4 KiB
C#
215 lines
6.4 KiB
C#
using System.Drawing;
|
|
using System.Text;
|
|
using BlurgText;
|
|
using Dashboard.BlurgText;
|
|
using Dashboard.BlurgText.OpenGL;
|
|
using Dashboard.Controls;
|
|
using Dashboard.Drawing;
|
|
using Dashboard.Events;
|
|
using Dashboard.OpenGL;
|
|
using Dashboard.OpenTK.PAL2;
|
|
using Dashboard.Pal;
|
|
using Dashboard.StbImage;
|
|
using OpenTK.Graphics.OpenGL;
|
|
using OpenTK.Mathematics;
|
|
using OpenTK.Platform;
|
|
using Image = Dashboard.Drawing.Image;
|
|
using MouseMoveEventArgs = OpenTK.Platform.MouseMoveEventArgs;
|
|
using TK = OpenTK.Platform.Toolkit;
|
|
using Vector4 = System.Numerics.Vector4;
|
|
|
|
TK.Init(new ToolkitOptions()
|
|
{
|
|
ApplicationName = "DashTerm",
|
|
Windows = new ToolkitOptions.WindowsOptions()
|
|
{
|
|
EnableVisualStyles = true,
|
|
IsDPIAware = true,
|
|
},
|
|
FeatureFlags = ToolkitFlags.EnableOpenGL,
|
|
});
|
|
|
|
Application app = new Pal2Application()
|
|
{
|
|
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<Vector3> points = new List<Vector3>();
|
|
// IFont font;
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
app.Initialize();
|
|
app.ExtensionRequire<StbImageLoader>();
|
|
app.ExtensionLoad(new BlurgTextExtension(new BlurgTextExtensionFactory()));
|
|
|
|
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);
|
|
|
|
GLDeviceContext context = (GLDeviceContext)window.DeviceContext;
|
|
|
|
context.GLContext.MakeCurrent();
|
|
context.GLContext.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);
|
|
|
|
foreach (string str in typeof(Image).Assembly.GetManifestResourceNames()) Console.WriteLine(str);
|
|
|
|
BlurgFont font = context.ExtensionRequire<BlurgDcExtension>().Blurg
|
|
.QueryFont("Recursive Mono", FontWeight.Regular, false) ?? throw new Exception("Font not found");
|
|
|
|
window.EventRaised += (sender, ea) => {
|
|
if (ea is not PaintEventArgs)
|
|
return;
|
|
|
|
TK.Window.GetSize(window.WindowHandle, out Vector2i size);
|
|
// executor.BeginFrame();
|
|
//
|
|
// dimUI.Begin(new Box2d(0, 0, size.X, size.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, size.X, size.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);
|
|
|
|
ITexture texture = MessageBox.s_questionIcon.InternTexture(context);
|
|
|
|
// executor.Draw(window.DrawQueue, new RectangleF(0, 0, size.X, size.Y), 1.5f /*(window as IDpiAwareWindow)?.Scale ?? 1*/);
|
|
// executor.EndFrame();
|
|
|
|
context.Begin();
|
|
|
|
IImmediateMode imm = context.ExtensionRequire<IImmediateMode>();
|
|
imm.ClearColor(Color.Magenta);
|
|
imm.Line(new System.Numerics.Vector2(10, 10), new System.Numerics.Vector2(50, 50), 3, 0, new Vector4(0.2f, 0.2f, 1.0f, 1.0f));
|
|
|
|
BlurgDcExtension blurg = context.ExtensionRequire<BlurgDcExtension>();
|
|
blurg.DrawBlurgFormattedText(new BlurgFormattedText("Hello world!", font) { DefaultSize = 64f }, new System.Numerics.Vector3(24, 24, 1));
|
|
|
|
context.End();
|
|
};
|
|
|
|
app.Run(true, source.Token);
|
|
|
|
|
|
class BlurgTextExtensionFactory : IBlurgDcExtensionFactory
|
|
{
|
|
public BlurgDcExtension CreateExtension(BlurgTextExtension appExtension, DeviceContext dc)
|
|
{
|
|
return new BlurgGLExtension();
|
|
}
|
|
};
|