Files
Pilz/Pilz.UI.Gtk/Symbols/GtkSymbolFactory.cs
2025-06-16 19:28:34 +02:00

48 lines
1.2 KiB
C#

using Gdk;
using Gtk;
using Pilz.UI.Symbols;
using Size = System.Drawing.Size;
namespace Pilz.UI.Gtk.Symbols;
public abstract class GtkSymbolFactory<TSymbols> : BaseSymbolFactory<TSymbols>, IGtkSymbolFactory<TSymbols>
{
public virtual Pixbuf? GetPixbuf(TSymbols svgImage, SymbolSize size)
{
return GetPixbuf(svgImage, ResolveCommonSize(size));
}
public virtual Pixbuf? GetPixbuf(TSymbols svgImage, Size size)
{
using var stream = GetImageRessourceStream(svgImage);
if (stream is null)
return null;
Pixbuf pixbuf;
if (size.IsEmpty)
pixbuf = new(stream);
else
pixbuf = new(stream, size.Width, size.Height);
return pixbuf;
}
public virtual Image? GetImage(TSymbols svgImage, SymbolSize size)
{
return GetImage(svgImage, ResolveCommonSize(size));
}
public virtual Image? GetImage(TSymbols svgImage, Size size)
{
if (GetPixbuf(svgImage, size) is Pixbuf pixbuf)
return GetImageFromPixbuf(pixbuf);
return null;
}
public virtual Image GetImageFromPixbuf(Pixbuf pixbuf)
{
return new Image(pixbuf);
}
}