60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
using System;
|
|
using Dashboard.Drawing;
|
|
using Dashboard.Events;
|
|
using Dashboard.Pal;
|
|
using Dashboard.Windowing;
|
|
|
|
namespace Dashboard.Controls
|
|
{
|
|
public class Form : Control, IForm
|
|
{
|
|
public IWindow Window { get; }
|
|
|
|
public Image? WindowIcon { get; set; }
|
|
public string? Title { get; set; } = "Untitled Form";
|
|
public Control? Root { get; set; } = null;
|
|
public Control? FocusedControl { get; private set; } = null;
|
|
|
|
public override Box2d ClientArea
|
|
{
|
|
get => new Box2d(0, 0, Window.ClientSize.Width, Window.ClientSize.Height);
|
|
set { }
|
|
}
|
|
|
|
public event EventHandler<WindowCloseEvent>? Closing;
|
|
|
|
public Form(IWindow window)
|
|
{
|
|
Window = window;
|
|
window.Form = this;
|
|
}
|
|
|
|
public void Focus(Control control)
|
|
{
|
|
if (FocusedControl != null)
|
|
InvokeFocusLost(this, FocusedControl);
|
|
|
|
FocusedControl = control;
|
|
InvokeFocusGained(this, control);
|
|
}
|
|
|
|
public override void OnPaint(DeviceContext dc)
|
|
{
|
|
dc.Begin();
|
|
Root?.SendEvent(this, new PaintEventArgs(dc));
|
|
dc.End();
|
|
}
|
|
|
|
protected virtual void OnClosing(WindowCloseEvent ea)
|
|
{
|
|
Closing?.Invoke(this, ea);
|
|
|
|
if (ea.Cancel)
|
|
return;
|
|
|
|
Dispose();
|
|
Window.Dispose();
|
|
}
|
|
}
|
|
}
|