Dashboard/Quik.OpenTK/OpenTKPlatform.cs

91 lines
3.0 KiB
C#
Raw Normal View History

2023-07-28 21:37:49 +02:00
using System;
using System.Collections.Generic;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.GraphicsLibraryFramework;
2024-04-11 18:09:00 +02:00
using Quik.CommandMachine;
2023-07-28 21:37:49 +02:00
using Quik.Media;
using Quik.OpenGL;
using Quik.PAL;
namespace Quik.OpenTK
{
public class OpenTKPlatform : IQuikPlatform
{
private readonly List<OpenTKPort> _ports = new List<OpenTKPort>();
// These shall remain a sad nop for now.
public string Title { get; set; }
public QImage Icon { get; set; }
public event EventHandler EventRaised;
public NativeWindowSettings DefaultSettings { get; set; } = NativeWindowSettings.Default;
public IReadOnlyList<OpenTKPort> Ports => _ports;
private bool IsGLInitialized = false;
2024-04-11 18:09:00 +02:00
public IQuikPortHandle CreatePort()
2023-07-28 21:37:49 +02:00
{
NativeWindow window = new NativeWindow(DefaultSettings);
OpenTKPort port = new OpenTKPort(window);
_ports.Add(port);
if (!IsGLInitialized)
{
window.Context.MakeCurrent();
2024-04-11 18:09:00 +02:00
GL.LoadBindings(GLFW.GetProcAddress);
2023-07-28 21:37:49 +02:00
IsGLInitialized = true;
}
2024-03-04 19:41:16 +01:00
window.Closing += (ea) =>
{
Environment.Exit(0);
};
2023-07-28 21:37:49 +02:00
return port;
}
public void Dispose()
{
// FIXME: dispose pattern here!
// Copy the array to prevent collection modification exceptions.
foreach (OpenTKPort port in _ports.ToArray())
{
port.Dispose();
}
}
public void ProcessEvents(bool block)
{
NativeWindow.ProcessWindowEvents(block);
}
2024-04-11 18:09:00 +02:00
public void DestroyPort(IQuikPortHandle port) => ((OpenTKPort)port).Dispose();
public string PortGetTitle(IQuikPortHandle port) => ((OpenTKPort)port).Title;
public void PortSetTitle(IQuikPortHandle port, string title) => ((OpenTKPort)port).Title = title;
public QVec2 PortGetSize(IQuikPortHandle port) => ((OpenTKPort)port).Size;
public void PortSetSize(IQuikPortHandle port, QVec2 size) => ((OpenTKPort)port).Size = size;
public QVec2 PortGetPosition(IQuikPortHandle port) => ((OpenTKPort)port).Position;
public void PortSetPosition(IQuikPortHandle port, QVec2 position) => ((OpenTKPort)port).Position = position;
public bool PortIsValid(IQuikPortHandle port) => ((OpenTKPort)port).IsValid;
public void PortSubscribeEvent(IQuikPortHandle port, EventHandler handler) => ((OpenTKPort)port).EventRaised += handler;
public void PortUnsubscribeEvent(IQuikPortHandle port, EventHandler handler) => ((OpenTKPort)port).EventRaised -= handler;
public void PortFocus(IQuikPortHandle port) => ((OpenTKPort)port).Focus();
public void PortShow(IQuikPortHandle port, bool shown = true) => ((OpenTKPort)port).Show(shown);
public void PortPaint(IQuikPortHandle port, CommandList commands) => ((OpenTKPort)port).Paint(commands);
2023-07-28 21:37:49 +02:00
}
}