Dashboard/Quik/PAL/QuikPort.cs

92 lines
2.1 KiB
C#
Raw Normal View History

2024-07-17 22:18:20 +02:00
using Dashboard.CommandMachine;
using Dashboard.Controls;
2024-04-11 18:09:00 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2024-07-17 22:18:20 +02:00
namespace Dashboard.PAL
2024-04-11 18:09:00 +02:00
{
/// <summary>
/// An abstraction layer over the UI input and output.
/// </summary>
public class QuikPort
{
private readonly IQuikPortHandle handle;
private readonly IQuikPlatform platform;
public string Title
{
get => platform.PortGetTitle(handle);
set => platform.PortSetTitle(handle, value);
}
public QVec2 Size
{
get => platform.PortGetSize(handle);
set => platform.PortSetSize(handle, value);
}
public QVec2 Position
{
get => platform.PortGetPosition(handle);
set => platform.PortSetPosition(handle, value);
}
2024-06-09 21:54:33 +02:00
public UIBase? UIElement { get; set; }
2024-04-11 18:09:00 +02:00
public bool IsValid => platform.PortIsValid(handle);
public event EventHandler EventRaised
{
add
{
platform.PortSubscribeEvent(handle, value);
}
remove
{
platform.PortUnsubscribeEvent(handle, value);
}
}
public QuikPort(IQuikPlatform platform)
{
this.platform = platform;
handle = platform.CreatePort();
}
bool isDisposed = false;
public void Dispose()
{
if (isDisposed) return;
platform.DestroyPort(handle);
isDisposed = true;
}
public void Focus()
{
platform.PortFocus(handle);
}
2024-06-09 21:54:33 +02:00
public void Paint(CommandList? list = null)
2024-04-11 18:09:00 +02:00
{
if (UIElement == null)
return;
2024-06-09 21:54:33 +02:00
list ??= new CommandList();
2024-04-11 18:09:00 +02:00
list.Clear();
UIElement.Bounds = new QRectangle(Size, new QVec2(0,0));
UIElement.Paint(list);
platform.PortPaint(handle, list);
}
public void Show(bool shown = true)
{
platform.PortShow(handle, shown);
}
}
}