67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
using System;
|
|
using Quik.CommandMachine;
|
|
|
|
namespace Quik.Controls
|
|
{
|
|
public abstract class Control : UIBase
|
|
{
|
|
private readonly CommandList drawCommands = new CommandList();
|
|
|
|
public Style Style { get; set; } = new Style();
|
|
public float Padding
|
|
{
|
|
get => (float)(Style["padding"] ?? 0.0f);
|
|
set => Style["padding"] = value;
|
|
}
|
|
|
|
public bool IsVisualsValid { get; private set; }
|
|
|
|
public void InvalidateVisual()
|
|
{
|
|
IsVisualsValid = false;
|
|
OnVisualsInvalidated(this, EventArgs.Empty);
|
|
}
|
|
|
|
protected abstract void ValidateVisual(CommandList cmd);
|
|
protected override void PaintBegin(CommandList cmd)
|
|
{
|
|
base.PaintBegin(cmd);
|
|
|
|
if (!IsVisualsValid)
|
|
{
|
|
ValidateVisual(drawCommands);
|
|
OnVisualsValidated(this, EventArgs.Empty);
|
|
IsVisualsValid = true;
|
|
}
|
|
|
|
cmd.PushStyle(Style);
|
|
cmd.PushViewport();
|
|
cmd.StoreViewport(AbsoluteBounds);
|
|
|
|
cmd.Splice(drawCommands);
|
|
|
|
cmd.PopViewport();
|
|
cmd.PopStyle();
|
|
}
|
|
|
|
public event EventHandler StyleChanged;
|
|
public event EventHandler VisualsInvalidated;
|
|
public event EventHandler VisualsValidated;
|
|
|
|
protected virtual void OnStyleChanged(object sender, EventArgs ea)
|
|
{
|
|
StyleChanged?.Invoke(sender, ea);
|
|
InvalidateVisual();
|
|
}
|
|
|
|
protected virtual void OnVisualsInvalidated(object sender, EventArgs ea)
|
|
{
|
|
VisualsInvalidated?.Invoke(sender, ea);
|
|
}
|
|
|
|
protected virtual void OnVisualsValidated(object sender, EventArgs ea)
|
|
{
|
|
VisualsValidated?.Invoke(sender, ea);
|
|
}
|
|
}
|
|
} |