timelapsenow/TimelapseExtensions/ClockExtension/Extension.cs

52 lines
1.7 KiB
C#
Raw Normal View History

2022-05-21 15:37:43 +00:00
using TimelapseApi;
using Eto.Forms;
using System;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Fonts;
using SixLabors.ImageSharp.Drawing.Processing;
namespace ClockExtension
{
public class ClockExtension : TimelapseExtension
{
FontCollection collection = new FontCollection();
public ClockExtension()
{
collection.AddSystemFonts();
Data=new ClockData();
}
public ClockData Data {get;set;}
public override string Name => "Clock Extension";
public override Guid Id => Guid.Parse("{1cb8b576-e2e8-44d5-a8e1-e25a47eb0564}"); //https://duckduckgo.com/?q=guid&t=ffab&ia=answer
protected override void OnCreate(ExtensionFeatures features)
{
Data=ClockData.Load(GetExtensionFolder(),collection);
features.RegisterFrameHandler(ImageHandler,"Draw Clock").RegisterSettingsDialog(()=>{
return new ClockDialog(Data,collection,GetExtensionFolder());
},"Clock Settings");
}
private bool ImageHandler(Image<Rgb24> arg)
{
if(Data.EnableClock)
{
string nowTime=DateTime.Now.ToString(Data.DateFormat.Replace("\\n","\n"));
arg.Mutate((e)=>{
var font=collection.Families.Skip(Data.FontIndex).FirstOrDefault();
var f=font.CreateFont(Data.FontSize);
e.DrawText(nowTime,f,Data.ForeColor,new PointF(Data.X,Data.Y));
});
}
return true;
}
}
}