Dashboard/Quik/QuikApplication.cs

113 lines
2.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2023-07-28 21:37:49 +02:00
using Quik.CommandMachine;
using Quik.Controls;
using Quik.Media;
using Quik.PAL;
2024-04-11 18:09:00 +02:00
using Quik.Typography;
namespace Quik
{
2023-07-28 21:37:49 +02:00
/// <summary>
/// Main class for Quik applications.
/// </summary>
public class QuikApplication
{
2023-07-28 21:37:49 +02:00
/// <summary>
/// The application platform driver.
/// </summary>
public IQuikPlatform Platform { get; }
2023-07-28 21:37:49 +02:00
/// <summary>
/// Title of the application.
/// </summary>
public string Title
{
get => Platform.Title;
set => Platform.Title = value;
}
/// <summary>
/// Application icon.
/// </summary>
public QImage Icon
{
get => Platform.Icon;
set => Platform.Icon = value;
}
2024-04-11 18:09:00 +02:00
public QuikPort MainPort { get; private set; } = null;
public FontProvider FontProvider { get; }
2023-07-28 21:37:49 +02:00
/// <summary>
/// List of media loaders, drivers that load media such as images and fonts.
/// </summary>
public List<MediaLoader> MediaLoaders { get; } = new List<MediaLoader>();
public QuikApplication(IQuikPlatform platform)
{
Platform = platform;
2024-04-11 18:09:00 +02:00
FontProvider = new FontProvider(this);
Current = this;
2024-04-11 18:09:00 +02:00
}
public IDisposable GetMedia(object key, MediaHint hint)
{
IDisposable disposable = null;
foreach (MediaLoader loader in MediaLoaders)
{
disposable = loader.GetMedia(key, hint);
if (disposable != null)
break;
}
return disposable;
}
public IDisposable GetMedia<T>(T key, MediaHint hint)
{
IDisposable disposable = null;
foreach (MediaLoader loader in MediaLoaders)
{
if (loader is MediaLoader<T> typedLoader)
{
disposable = typedLoader.GetMedia(key, hint);
if (disposable != null)
break;
}
}
return disposable;
2023-07-28 21:37:49 +02:00
}
public void Run(View mainView)
{
2024-04-11 18:09:00 +02:00
MainPort = new QuikPort(Platform) { UIElement = mainView };
CommandList cmd = new CommandList();
2023-07-28 21:37:49 +02:00
2024-04-11 18:09:00 +02:00
MainPort.EventRaised += (sender, ea) => mainView.NotifyEvent(sender, ea);
2023-07-28 21:37:49 +02:00
2024-04-11 18:09:00 +02:00
while (MainPort.IsValid)
2023-07-28 21:37:49 +02:00
{
Platform.ProcessEvents(false);
2024-04-11 18:09:00 +02:00
if (MainPort.IsValid)
2023-07-28 21:37:49 +02:00
{
cmd.Clear();
2024-04-11 18:09:00 +02:00
MainPort.Paint(cmd);
2023-07-28 21:37:49 +02:00
}
}
}
public static QuikApplication Current { get; private set; }
public static void SetCurrentApplication(QuikApplication application)
{
Current = application;
}
}
}