change UI to UI.WinForms
This commit is contained in:
12
Pilz.UI.WinForms/Symbols/ISymbolFactory.cs
Normal file
12
Pilz.UI.WinForms/Symbols/ISymbolFactory.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Pilz.UI.WinForms.Symbols;
|
||||
|
||||
public interface ISymbolFactory<TSymbols>
|
||||
{
|
||||
Image? GetImage(TSymbols svgImage, Size size);
|
||||
Image? GetImage(TSymbols svgImage, SymbolSize size);
|
||||
Assembly GetImageResourceAssembly();
|
||||
string GetImageRessourcePath(TSymbols svgImage);
|
||||
Stream? GetImageRessourceStream(TSymbols svgImage);
|
||||
}
|
||||
54
Pilz.UI.WinForms/Symbols/SymbolFactory.cs
Normal file
54
Pilz.UI.WinForms/Symbols/SymbolFactory.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Pilz.UI.WinForms.Symbols;
|
||||
|
||||
public abstract class SymbolFactory<TSymbols> : ISymbolFactory<TSymbols>
|
||||
{
|
||||
public abstract string GetImageRessourcePath(TSymbols svgImage);
|
||||
public abstract Assembly GetImageResourceAssembly();
|
||||
|
||||
protected virtual Size ResolveCommonSize(SymbolSize size)
|
||||
{
|
||||
return size switch
|
||||
{
|
||||
SymbolSize.Default => Size.Empty,
|
||||
SymbolSize.Small => new Size(16, 16),
|
||||
SymbolSize.Medium => new Size(20, 20),
|
||||
SymbolSize.Large => new Size(32, 32),
|
||||
_ => new Size((int)size, (int)size),
|
||||
};
|
||||
}
|
||||
|
||||
public virtual Stream? GetImageRessourceStream(TSymbols svgImage)
|
||||
{
|
||||
var asm = GetImageResourceAssembly();
|
||||
var path = GetImageRessourcePath(svgImage);
|
||||
return asm.GetManifestResourceStream(path);
|
||||
}
|
||||
|
||||
public virtual Image? GetImage(TSymbols svgImage, SymbolSize size)
|
||||
{
|
||||
return GetImage(svgImage, ResolveCommonSize(size));
|
||||
}
|
||||
|
||||
public virtual Image? GetImage(TSymbols svgImage, Size size)
|
||||
{
|
||||
using var stream = GetImageRessourceStream(svgImage);
|
||||
|
||||
if (stream is null)
|
||||
return null;
|
||||
|
||||
var img = Image.FromStream(stream);
|
||||
|
||||
if (!size.IsEmpty)
|
||||
{
|
||||
var img2 = new Bitmap(size.Width, size.Height);
|
||||
using var g = Graphics.FromImage(img2);
|
||||
g.DrawImage(img2, 0, 0, size.Width, size.Height);
|
||||
img.Dispose();
|
||||
img = img2;
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
}
|
||||
72
Pilz.UI.WinForms/Symbols/SymbolSize.cs
Normal file
72
Pilz.UI.WinForms/Symbols/SymbolSize.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
namespace Pilz.UI.WinForms.Symbols;
|
||||
|
||||
public enum SymbolSize
|
||||
{
|
||||
/// <summary>
|
||||
/// Don't resize and just returns the original size.
|
||||
/// </summary>
|
||||
Default,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 16 x 16 pixels.
|
||||
/// <br/><b>Deprecated!</b> This is just present due legacy reasons. Use <see cref="x16"/> instead.
|
||||
/// </summary>
|
||||
Small,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 20 x 20 pixels.
|
||||
/// <br/><b>Deprecated!</b> This is just present due legacy reasons. Use <see cref="x20"/> instead.
|
||||
/// </summary>
|
||||
Medium,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 32 x 32 pixels.
|
||||
/// <br/><b>Deprecated!</b> This is just present due legacy reasons. Use <see cref="x32"/> instead.
|
||||
/// </summary>
|
||||
Large,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 8 x 8 pixels.
|
||||
/// </summary>
|
||||
x8 = 8,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 12 x 12 pixels.
|
||||
/// </summary>
|
||||
x12 = 12,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 16 x 16 pixels.
|
||||
/// </summary>
|
||||
x16 = 16,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 20 x 20 pixels.
|
||||
/// </summary>
|
||||
x20 = 20,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 32 x 32 pixels.
|
||||
/// </summary>
|
||||
x32 = 32,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 48 x 48 pixels.
|
||||
/// </summary>
|
||||
x48 = 48,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 64 x 64 pixels.
|
||||
/// </summary>
|
||||
x64 = 64,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 96 x 96 pixels.
|
||||
/// </summary>
|
||||
x96 = 96,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 128 x 128 pixels.
|
||||
/// </summary>
|
||||
x128 = 128,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 192 x 192 pixels.
|
||||
/// </summary>
|
||||
x192 = 192,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 256 x 256 pixels.
|
||||
/// </summary>
|
||||
x256 = 256,
|
||||
/// <summary>
|
||||
/// Resizes the symbol to 512 x 512 pixels.
|
||||
/// </summary>
|
||||
x512 = 512,
|
||||
}
|
||||
Reference in New Issue
Block a user