add Pilz.UI & Pilz.UI.Gtk
This commit is contained in:
23
Pilz.UI.Gtk/Dialogs/MessageBox.cs
Normal file
23
Pilz.UI.Gtk/Dialogs/MessageBox.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Gtk;
|
||||
|
||||
namespace Pilz.UI.Gtk.Dialogs;
|
||||
|
||||
public static class MessageBox
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Nicht verwendete Parameter entfernen", Justification = "Can be used for easier migration from WinForms. However, the title get ignored as Gtk has no title parameter.")]
|
||||
public static ResponseType Show(Window window, string message, string title, ButtonsType buttons, MessageType type)
|
||||
{
|
||||
var msgBox = new MessageDialog(window, DialogFlags.DestroyWithParent, type, buttons, message);
|
||||
var result = msgBox.Run();
|
||||
msgBox.Destroy();
|
||||
return (ResponseType)result;
|
||||
}
|
||||
|
||||
public static ResponseType Show(Window window, ButtonsType buttons, MessageType type, string format, params object[] args)
|
||||
{
|
||||
var msgBox = new MessageDialog(window, DialogFlags.DestroyWithParent, type, buttons, format, args);
|
||||
var result = msgBox.Run();
|
||||
msgBox.Destroy();
|
||||
return (ResponseType)result;
|
||||
}
|
||||
}
|
||||
22
Pilz.UI.Gtk/Pilz.UI.Gtk.csproj
Normal file
22
Pilz.UI.Gtk/Pilz.UI.Gtk.csproj
Normal file
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GtkSharp" Version="3.24.24.95" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pilz.UI\Pilz.UI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
35
Pilz.UI.Gtk/Symbols/GtkSymbolFactory.cs
Normal file
35
Pilz.UI.Gtk/Symbols/GtkSymbolFactory.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
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 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;
|
||||
|
||||
Pixbuf pixbuf;
|
||||
if (size.IsEmpty)
|
||||
pixbuf = new(stream);
|
||||
else
|
||||
pixbuf = new(stream, size.Width, size.Height);
|
||||
|
||||
return GetImageFromPixbuf(pixbuf);
|
||||
}
|
||||
|
||||
public virtual Image GetImageFromPixbuf(Pixbuf pixbuf)
|
||||
{
|
||||
return new Image(pixbuf);
|
||||
}
|
||||
}
|
||||
12
Pilz.UI.Gtk/Symbols/IGtkSymbolFactory.cs
Normal file
12
Pilz.UI.Gtk/Symbols/IGtkSymbolFactory.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Gtk;
|
||||
using Pilz.UI.Symbols;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Pilz.UI.Gtk.Symbols;
|
||||
|
||||
public interface IGtkSymbolFactory<TSymbols> : IBaseSymbolFactory<TSymbols>
|
||||
{
|
||||
Image? GetImage(TSymbols svgImage, Size size);
|
||||
Image? GetImage(TSymbols svgImage, SymbolSize size);
|
||||
Image GetImageFromPixbuf(Gdk.Pixbuf pixbuf);
|
||||
}
|
||||
Reference in New Issue
Block a user