Compare commits
8 Commits
e30e50e860
...
dashboard2
| Author | SHA1 | Date | |
|---|---|---|---|
| 5bcc2d8214 | |||
| 804a3979fd | |||
| d299084db5 | |||
| d20d929515 | |||
| 3b9fa5c9fb | |||
| 027ebe8dbd | |||
| 36dbcac8d9 | |||
| 7c3141822a |
@@ -155,6 +155,10 @@ namespace Dashboard.BlurgText
|
|||||||
protected BlurgFontProxy InternFont(IFont font)
|
protected BlurgFontProxy InternFont(IFont font)
|
||||||
{
|
{
|
||||||
BlurgTextExtension appExtension = Application.ExtensionRequire<BlurgTextExtension>();
|
BlurgTextExtension appExtension = Application.ExtensionRequire<BlurgTextExtension>();
|
||||||
|
|
||||||
|
if (font is Font xfont)
|
||||||
|
font = xfont.Base;
|
||||||
|
|
||||||
if (font is FontInfo fontInfo)
|
if (font is FontInfo fontInfo)
|
||||||
{
|
{
|
||||||
return (BlurgFontProxy)appExtension.Load(fontInfo);
|
return (BlurgFontProxy)appExtension.Load(fontInfo);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
namespace Dashboard.Drawing
|
namespace Dashboard.Drawing
|
||||||
{
|
{
|
||||||
@@ -10,4 +11,15 @@ namespace Dashboard.Drawing
|
|||||||
{
|
{
|
||||||
public Color Color { get; } = color;
|
public Color Color { get; } = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ImageBrush(Image image) : Brush
|
||||||
|
{
|
||||||
|
public Box2d TextureCoordinates { get; set; } = new Box2d(0, 0, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NinePatchImageBrush(Image image) : Brush
|
||||||
|
{
|
||||||
|
public Box2d CenterCoordinates { get; set; } = new Box2d(0, 0, 1, 1);
|
||||||
|
public Vector4 Extents { get; set; } = Vector4.Zero;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,161 @@ namespace Dashboard.Events
|
|||||||
|
|
||||||
public enum ScanCode
|
public enum ScanCode
|
||||||
{
|
{
|
||||||
// TODO:
|
// This scan code table is based on the Win32 scan code table.
|
||||||
|
// See https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input
|
||||||
|
Error = 0xFF,
|
||||||
|
SystemPowerDown = 0xE05E,
|
||||||
|
SystemSleep = 0xE05F,
|
||||||
|
SystemWakeUp = 0xE063,
|
||||||
|
|
||||||
|
A = 0x1E,
|
||||||
|
B = 0x30,
|
||||||
|
C = 0x2E,
|
||||||
|
D = 0x20,
|
||||||
|
E = 0x12,
|
||||||
|
F = 0x21,
|
||||||
|
G = 0x22,
|
||||||
|
H = 0x23,
|
||||||
|
I = 0x17,
|
||||||
|
J = 0x24,
|
||||||
|
K = 0x25,
|
||||||
|
L = 0x26,
|
||||||
|
M = 0x32,
|
||||||
|
N = 0x31,
|
||||||
|
O = 0x18,
|
||||||
|
P = 0x19,
|
||||||
|
Q = 0x10,
|
||||||
|
R = 0x13,
|
||||||
|
S = 0x1F,
|
||||||
|
T = 0x14,
|
||||||
|
U = 0x16,
|
||||||
|
V = 0x2F,
|
||||||
|
W = 0x11,
|
||||||
|
X = 0x2D,
|
||||||
|
Y = 0x15,
|
||||||
|
Z = 0x2C,
|
||||||
|
|
||||||
|
D1 = 0x02,
|
||||||
|
D2 = 0x03,
|
||||||
|
D3 = 0x04,
|
||||||
|
D4 = 0x05,
|
||||||
|
D5 = 0x06,
|
||||||
|
D6 = 0x07,
|
||||||
|
D7 = 0x08,
|
||||||
|
D8 = 0x09,
|
||||||
|
D9 = 0x0A,
|
||||||
|
D0 = 0x0B,
|
||||||
|
|
||||||
|
Return = 0x1C,
|
||||||
|
Esc = 0x01,
|
||||||
|
Delete = 0x0E,
|
||||||
|
Tab = 0x0F,
|
||||||
|
Space = 0x39,
|
||||||
|
Dash = 0x0C,
|
||||||
|
Equals = 0x0D,
|
||||||
|
LBracket = 0x1A,
|
||||||
|
RBracket = 0x1B,
|
||||||
|
Backslash = 0x2B,
|
||||||
|
Semicolon = 0x27,
|
||||||
|
Apostrophe = 0x28,
|
||||||
|
Grave = 0x29,
|
||||||
|
Comma = 0x33,
|
||||||
|
Period = 0x34,
|
||||||
|
ForwardSlash = 0x35,
|
||||||
|
CapsLock = 0x3A,
|
||||||
|
F1 = 0x3B,
|
||||||
|
F2 = 0x3C,
|
||||||
|
F3 = 0x3D,
|
||||||
|
F4 = 0x3E,
|
||||||
|
F5 = 0x3F,
|
||||||
|
F6 = 0x40,
|
||||||
|
F7 = 0x41,
|
||||||
|
F8 = 0x42,
|
||||||
|
F9 = 0x43,
|
||||||
|
F10 = 0x44,
|
||||||
|
F11 = 0x45,
|
||||||
|
F12 = 0x46,
|
||||||
|
PrintScr = 0xE037,
|
||||||
|
ScrollLock = 0x46,
|
||||||
|
Pause = 0xE046,
|
||||||
|
Insert = 0xE052,
|
||||||
|
Home = 0xE047,
|
||||||
|
PageUp = 0xE049,
|
||||||
|
Backspace = 0xE053,
|
||||||
|
End = 0xE04F,
|
||||||
|
PageDown = 0xE051,
|
||||||
|
RightArrow = 0xE04D,
|
||||||
|
LeftArrow = 0xE04B,
|
||||||
|
DownArrow = 0xE050,
|
||||||
|
UpArrow = 0xE048,
|
||||||
|
NumLock = 0xE045,
|
||||||
|
NumDiv = 0xE035,
|
||||||
|
NumMul = 0x37,
|
||||||
|
NumSub = 0x4A,
|
||||||
|
NumAdd = 0x4E,
|
||||||
|
NumEnter = 0xE01C,
|
||||||
|
Num1 = 0x4F,
|
||||||
|
Num2 = 0x50,
|
||||||
|
Num3 = 0x51,
|
||||||
|
Num4 = 0x4B,
|
||||||
|
Num5 = 0x4C,
|
||||||
|
Num6 = 0x4D,
|
||||||
|
Num7 = 0x47,
|
||||||
|
Num8 = 0x48,
|
||||||
|
Num9 = 0x49,
|
||||||
|
Num0 = 0x52,
|
||||||
|
NumDecimal = 0x53,
|
||||||
|
NumBackslash = 0x56,
|
||||||
|
NumEquals = 0x59,
|
||||||
|
Application = 0xE05D,
|
||||||
|
F13 = 0x64,
|
||||||
|
F14 = 0x65,
|
||||||
|
F15 = 0x66,
|
||||||
|
F16 = 0x67,
|
||||||
|
F17 = 0x68,
|
||||||
|
F18 = 0x69,
|
||||||
|
F19 = 0x6A,
|
||||||
|
F20 = 0x6B,
|
||||||
|
F21 = 0x6C,
|
||||||
|
F22 = 0x6D,
|
||||||
|
F23 = 0x6E,
|
||||||
|
F24 = 0x76,
|
||||||
|
NumComma = 0x7E,
|
||||||
|
International1 = 0x73,
|
||||||
|
International2 = 0x70,
|
||||||
|
International3 = 0x7D,
|
||||||
|
International4 = 0x79,
|
||||||
|
International5 = 0x7B,
|
||||||
|
International6 = 0x5C,
|
||||||
|
Lang1 = 0x72,
|
||||||
|
Lang2 = 0x71,
|
||||||
|
Lang3 = 0x78,
|
||||||
|
Lang4 = 0x77,
|
||||||
|
LCtrl = 0x1D,
|
||||||
|
LShift = 0x2A,
|
||||||
|
LWin = 0xE05B,
|
||||||
|
LAlt = 0x38,
|
||||||
|
RAlt = 0xE038,
|
||||||
|
RWin = 0xE05C,
|
||||||
|
RCtrl = 0xE01D,
|
||||||
|
RShift = 0x36,
|
||||||
|
NextTrack = 0xE019,
|
||||||
|
PrevTrack = 0xE010,
|
||||||
|
Stop = 0xE024,
|
||||||
|
PlayPause = 0xE022,
|
||||||
|
VolUp = 0xE030,
|
||||||
|
VolDown = 0xE029,
|
||||||
|
Configuration = 0xE06D,
|
||||||
|
Email = 0xE06C,
|
||||||
|
Calculator = 0xE021,
|
||||||
|
Browser = 0xE06B,
|
||||||
|
Search = 0xE065,
|
||||||
|
HomePage = 0xE032,
|
||||||
|
Back = 0xE06A,
|
||||||
|
Forward = 0xE69,
|
||||||
|
Halt = 0xE068,
|
||||||
|
Refresh = 0xE67,
|
||||||
|
Bookmarks = 0xE066,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class KeyboardButtonEventArgs(KeyCode keyCode, ScanCode scanCode, ModifierKeys modifierKeys, bool up)
|
public class KeyboardButtonEventArgs(KeyCode keyCode, ScanCode scanCode, ModifierKeys modifierKeys, bool up)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
using System.Numerics;
|
||||||
using Dashboard.Collections;
|
using Dashboard.Collections;
|
||||||
using Dashboard.Windowing;
|
using Dashboard.Windowing;
|
||||||
using BindingFlags = System.Reflection.BindingFlags;
|
|
||||||
|
|
||||||
namespace Dashboard.Pal
|
namespace Dashboard.Pal
|
||||||
{
|
{
|
||||||
public abstract class DeviceContext : IContextBase<DeviceContext, IDeviceContextExtension>
|
public abstract class DeviceContext : IContextBase<DeviceContext, IDeviceContextExtension>, IDeviceContext
|
||||||
{
|
{
|
||||||
private readonly TypeDictionary<IDeviceContextExtension> _extensions =
|
private readonly TypeDictionary<IDeviceContextExtension> _extensions =
|
||||||
new TypeDictionary<IDeviceContextExtension>(true);
|
new TypeDictionary<IDeviceContextExtension>(true);
|
||||||
@@ -19,6 +19,9 @@ namespace Dashboard.Pal
|
|||||||
public abstract string DriverName { get; }
|
public abstract string DriverName { get; }
|
||||||
public abstract string DriverVendor { get; }
|
public abstract string DriverVendor { get; }
|
||||||
public abstract Version DriverVersion { get; }
|
public abstract Version DriverVersion { get; }
|
||||||
|
public abstract ISwapGroup SwapGroup { get; }
|
||||||
|
public abstract Vector2 FramebufferSize { get; }
|
||||||
|
public virtual bool DoubleBuffered { get; } = false;
|
||||||
|
|
||||||
public bool IsDisposed { get; private set; }
|
public bool IsDisposed { get; private set; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
using System.Numerics;
|
||||||
using Dashboard.Drawing;
|
using Dashboard.Drawing;
|
||||||
using Dashboard.OpenGL.Drawing;
|
using Dashboard.OpenGL.Drawing;
|
||||||
using Dashboard.Pal;
|
using Dashboard.Pal;
|
||||||
@@ -27,6 +28,9 @@ namespace Dashboard.OpenGL
|
|||||||
public override string DriverName => "Dashboard OpenGL Device Context";
|
public override string DriverName => "Dashboard OpenGL Device Context";
|
||||||
public override string DriverVendor => "Dashboard";
|
public override string DriverVendor => "Dashboard";
|
||||||
public override Version DriverVersion => new Version(0, 1, 0);
|
public override Version DriverVersion => new Version(0, 1, 0);
|
||||||
|
public override ISwapGroup SwapGroup { get; }
|
||||||
|
public override Vector2 FramebufferSize => GLContext.FramebufferSize;
|
||||||
|
public override bool DoubleBuffered { get; } = true;
|
||||||
|
|
||||||
public Version GLVersion { get; }
|
public Version GLVersion { get; }
|
||||||
public string GLRenderer { get; }
|
public string GLRenderer { get; }
|
||||||
@@ -39,9 +43,11 @@ namespace Dashboard.OpenGL
|
|||||||
private readonly ConcurrentQueue<Task> _beforeDrawActions = new ConcurrentQueue<Task>();
|
private readonly ConcurrentQueue<Task> _beforeDrawActions = new ConcurrentQueue<Task>();
|
||||||
private readonly ConcurrentQueue<Task> _afterDrawActions = new ConcurrentQueue<Task>();
|
private readonly ConcurrentQueue<Task> _afterDrawActions = new ConcurrentQueue<Task>();
|
||||||
|
|
||||||
public GLDeviceContext(Application app, IWindow? window, IGLContext context) : base(app, window)
|
public GLDeviceContext(Application app, IWindow? window, IGLContext context, ISwapGroup swap) : base(app, window)
|
||||||
{
|
{
|
||||||
GLContext = context;
|
GLContext = context;
|
||||||
|
SwapGroup = swap;
|
||||||
|
|
||||||
context.MakeCurrent();
|
context.MakeCurrent();
|
||||||
GLLoader.LoadBindings(new GLContextBindingsContext(context));
|
GLLoader.LoadBindings(new GLContextBindingsContext(context));
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,6 @@ namespace Dashboard.OpenGL
|
|||||||
/// <remarks>-1 assigns no group.</remarks>
|
/// <remarks>-1 assigns no group.</remarks>
|
||||||
public int ContextGroup { get; }
|
public int ContextGroup { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The size of the framebuffer in pixels.
|
|
||||||
/// </summary>
|
|
||||||
public Vector2 FramebufferSize { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the context is disposed.
|
/// Called when the context is disposed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using DB = Dashboard.Events;
|
|||||||
|
|
||||||
namespace Dashboard.OpenTK.PAL2
|
namespace Dashboard.OpenTK.PAL2
|
||||||
{
|
{
|
||||||
public class Pal2Application : Application
|
public class Pal2Application(ToolkitOptions? options = null) : Application
|
||||||
{
|
{
|
||||||
public override string DriverName => "Dashboard OpenTK PAL2.0 Driver";
|
public override string DriverName => "Dashboard OpenTK PAL2.0 Driver";
|
||||||
public override string DriverVendor => "Dashboard";
|
public override string DriverVendor => "Dashboard";
|
||||||
@@ -50,6 +50,8 @@ namespace Dashboard.OpenTK.PAL2
|
|||||||
});
|
});
|
||||||
|
|
||||||
EventQueue.EventRaised += OnEventRaised;
|
EventQueue.EventRaised += OnEventRaised;
|
||||||
|
|
||||||
|
Toolkit.Init(options ?? new ToolkitOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void RemoveWindow(PhysicalWindow window)
|
internal void RemoveWindow(PhysicalWindow window)
|
||||||
@@ -275,6 +277,47 @@ namespace Dashboard.OpenTK.PAL2
|
|||||||
|
|
||||||
private static ScanCode GetScanCode(Scancode scanCode) => scanCode switch
|
private static ScanCode GetScanCode(Scancode scanCode) => scanCode switch
|
||||||
{
|
{
|
||||||
|
// TODO: Revise this array.
|
||||||
|
Scancode.A => ScanCode.A,
|
||||||
|
Scancode.B => ScanCode.B,
|
||||||
|
Scancode.C => ScanCode.C,
|
||||||
|
Scancode.D => ScanCode.D,
|
||||||
|
Scancode.E => ScanCode.E,
|
||||||
|
Scancode.F => ScanCode.F,
|
||||||
|
Scancode.G => ScanCode.G,
|
||||||
|
Scancode.H => ScanCode.H,
|
||||||
|
Scancode.I => ScanCode.I,
|
||||||
|
Scancode.J => ScanCode.J,
|
||||||
|
Scancode.K => ScanCode.K,
|
||||||
|
Scancode.L => ScanCode.L,
|
||||||
|
Scancode.M => ScanCode.M,
|
||||||
|
Scancode.N => ScanCode.N,
|
||||||
|
Scancode.O => ScanCode.O,
|
||||||
|
Scancode.P => ScanCode.P,
|
||||||
|
Scancode.Q => ScanCode.Q,
|
||||||
|
Scancode.R => ScanCode.R,
|
||||||
|
Scancode.S => ScanCode.S,
|
||||||
|
Scancode.T => ScanCode.T,
|
||||||
|
Scancode.U => ScanCode.U,
|
||||||
|
Scancode.V => ScanCode.V,
|
||||||
|
Scancode.W => ScanCode.W,
|
||||||
|
Scancode.X => ScanCode.X,
|
||||||
|
Scancode.Y => ScanCode.Y,
|
||||||
|
Scancode.Z => ScanCode.Z,
|
||||||
|
Scancode.D0 => ScanCode.D0,
|
||||||
|
Scancode.D1 => ScanCode.D1,
|
||||||
|
Scancode.D2 => ScanCode.D2,
|
||||||
|
Scancode.D3 => ScanCode.D3,
|
||||||
|
Scancode.D4 => ScanCode.D4,
|
||||||
|
Scancode.D5 => ScanCode.D5,
|
||||||
|
Scancode.D6 => ScanCode.D6,
|
||||||
|
Scancode.D7 => ScanCode.D7,
|
||||||
|
Scancode.D8 => ScanCode.D8,
|
||||||
|
Scancode.D9 => ScanCode.D9,
|
||||||
|
Scancode.UpArrow => ScanCode.UpArrow,
|
||||||
|
Scancode.DownArrow => ScanCode.DownArrow,
|
||||||
|
Scancode.LeftArrow => ScanCode.LeftArrow,
|
||||||
|
Scancode.RightArrow => ScanCode.RightArrow,
|
||||||
_ => (ScanCode)0,
|
_ => (ScanCode)0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace Dashboard.OpenTK.PAL2
|
|||||||
{
|
{
|
||||||
Application = app;
|
Application = app;
|
||||||
WindowHandle = window;
|
WindowHandle = window;
|
||||||
DeviceContext = new GLDeviceContext(app, this, new Pal2GLContext(window, context));
|
DeviceContext = new GLDeviceContext(app, this, new Pal2GLContext(window, context), new DummySwapGroup(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PhysicalWindow(Application app, GraphicsApiHints hints)
|
public PhysicalWindow(Application app, GraphicsApiHints hints)
|
||||||
@@ -81,7 +81,8 @@ namespace Dashboard.OpenTK.PAL2
|
|||||||
{
|
{
|
||||||
case GraphicsApi.OpenGL:
|
case GraphicsApi.OpenGL:
|
||||||
case GraphicsApi.OpenGLES:
|
case GraphicsApi.OpenGLES:
|
||||||
return new GLDeviceContext(app, window, new Pal2GLContext(handle, TK.OpenGL.CreateFromWindow(handle)));
|
OpenGLContextHandle context = TK.OpenGL.CreateFromWindow(handle);
|
||||||
|
return new GLDeviceContext(app, window, new Pal2GLContext(handle, context), new DummySwapGroup(context));
|
||||||
default:
|
default:
|
||||||
throw new Exception($"Unknown graphics API {hints.Api}.");
|
throw new Exception($"Unknown graphics API {hints.Api}.");
|
||||||
}
|
}
|
||||||
@@ -146,5 +147,28 @@ namespace Dashboard.OpenTK.PAL2
|
|||||||
return Math.Max(x, y);
|
return Math.Max(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class DummySwapGroup(OpenGLContextHandle context) : ISwapGroup
|
||||||
|
{
|
||||||
|
public int SwapInterval
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
TK.OpenGL.SetCurrentContext(context);
|
||||||
|
return TK.OpenGL.GetSwapInterval();
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
TK.OpenGL.SetCurrentContext(context);
|
||||||
|
TK.OpenGL.SetSwapInterval(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Swap()
|
||||||
|
{
|
||||||
|
TK.OpenGL.SwapBuffers(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ namespace Dashboard.Controls
|
|||||||
foreach (Control child in this)
|
foreach (Control child in this)
|
||||||
child.SendEvent(this, new PaintEventArgs(dc));
|
child.SendEvent(this, new PaintEventArgs(dc));
|
||||||
|
|
||||||
|
base.OnPaint(dc);
|
||||||
|
|
||||||
dc.End();
|
dc.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ using OpenTK.Graphics.OpenGL;
|
|||||||
using OpenTK.Mathematics;
|
using OpenTK.Mathematics;
|
||||||
using OpenTK.Platform;
|
using OpenTK.Platform;
|
||||||
using TK = OpenTK.Platform.Toolkit;
|
using TK = OpenTK.Platform.Toolkit;
|
||||||
|
Application app = new Pal2Application(new ToolkitOptions()
|
||||||
TK.Init(new ToolkitOptions()
|
|
||||||
{
|
{
|
||||||
ApplicationName = "DashTerm",
|
ApplicationName = "DashTerm",
|
||||||
Windows = new ToolkitOptions.WindowsOptions()
|
Windows = new ToolkitOptions.WindowsOptions()
|
||||||
@@ -20,9 +19,7 @@ TK.Init(new ToolkitOptions()
|
|||||||
IsDPIAware = true,
|
IsDPIAware = true,
|
||||||
},
|
},
|
||||||
FeatureFlags = ToolkitFlags.EnableOpenGL,
|
FeatureFlags = ToolkitFlags.EnableOpenGL,
|
||||||
});
|
})
|
||||||
|
|
||||||
Application app = new Pal2Application()
|
|
||||||
{
|
{
|
||||||
GraphicsApiHints = new OpenGLGraphicsApiHints()
|
GraphicsApiHints = new OpenGLGraphicsApiHints()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user