H. Utku Maden a1f4e6a4dc Rename from QUIK to Dashboard
Due to unforseen naming conflicts, the project has been rebranded under the ReFuel
umbrealla and will now be referred to as Dashboard from now on. Other changes will
occur to suit the library more for the engine whilst keeping the freestanding
nature of the library.

Rename folder.

Rename to Dashboard.OpenTK

Rename to Dashboard.Media.Defaults.

Do the last renames and path fixes.
2024-07-17 23:26:58 +03:00

102 lines
2.4 KiB
C#

using System;
using Dashboard.CommandMachine;
namespace Dashboard.Controls
{
/// <summary>
/// Bases for all UI elements.
/// </summary>
public abstract class UIBase
{
private QVec2 size;
public UIBase? Parent { get; protected set; }
public string? Id { get; set; }
public QRectangle Bounds
{
get => new QRectangle(Position + Size, Position);
set
{
Size = value.Size;
Position = value.Min;
}
}
public QVec2 Position { get; set; }
public QVec2 Size
{
get => size;
set
{
QVec2 oldSize = size;
size = value;
OnResized(this, new ResizedEventArgs(size, oldSize));
}
}
public QRectangle AbsoluteBounds
{
get
{
if (Parent == null)
{
return Bounds;
}
else
{
return new QRectangle(Bounds.Max + Parent.Position, Bounds.Min + Parent.Position);
}
}
}
public QVec2 MaximumSize { get; set; } = new QVec2(-1, -1);
public QVec2 MinimumSize { get; set; } = new QVec2(-1, -1);
public bool IsMaximumSizeSet => MaximumSize != new QVec2(-1, -1);
public bool IsMinimumSizeSet => MinimumSize != new QVec2(-1, -1);
public virtual void NotifyEvent(object? sender, EventArgs args)
{
}
protected virtual void PaintBegin(CommandList cmd)
{
cmd.PushViewport();
cmd.StoreViewport(AbsoluteBounds);
cmd.PushZ();
}
protected virtual void PaintEnd(CommandList cmd)
{
cmd.PopViewport();
}
public void Paint(CommandList cmd)
{
PaintBegin(cmd);
PaintEnd(cmd);
}
public event EventHandler<ResizedEventArgs>? Resized;
public virtual void OnResized(object sender, ResizedEventArgs ea)
{
Resized?.Invoke(sender, ea);
}
}
public class ResizedEventArgs : EventArgs
{
public QVec2 NewSize { get; }
public QVec2 OldSize { get; }
public ResizedEventArgs(QVec2 newSize, QVec2 oldSize)
{
NewSize = newSize;
OldSize = oldSize;
}
}
}