Files
@ 4778889395e8
Branch filter:
Location: ATITD-Tools/Desert-Paint-Codex/Converters/PaintToBrushConverter.cs - annotation
4778889395e8
1.3 KiB
text/x-csharp
Change the displayed permeutation count to display using locale-specific number formatting (with comma / dot separators). Fix a crash when starting a new round of recipe generation after recipe generation completed during a previous run.
40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 | using System;
using System.Collections.Generic;
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;
using DesertPaintCodex.Models;
namespace DesertPaintCodex.Converters
{
/// <summary>
/// Converts PaintColor to a SolidColorBrush.
/// </summary>
public class PaintToBrushConverter : IValueConverter
{
private static readonly SolidColorBrush NoColor = new();
private static readonly Dictionary<PaintColor, SolidColorBrush> BrushPool = new();
/// <inheritdoc/>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not PaintColor paintColor) return NoColor;
if (BrushPool.TryGetValue(paintColor, out SolidColorBrush? brush)) return brush;
brush = new SolidColorBrush(new Color(0xFF, paintColor.Red, paintColor.Green, paintColor.Blue));
BrushPool.Add(paintColor, brush);
return brush;
}
/// <inheritdoc/>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not SolidColorBrush brush) return new PaintColor(0, 0, 0);
Color color = brush.Color;
return new PaintColor(color.R, color.G, color.B);
}
}
}
|