using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
namespace SpdUp.Converters;
/// Bool → Visibility converter.
public sealed class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> value is true ? Visibility.Visible : Visibility.Collapsed;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> value is Visibility.Visible;
}
/// Inverted Bool → Visibility converter.
public sealed class InverseBoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> value is true ? Visibility.Collapsed : Visibility.Visible;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> value is Visibility.Collapsed;
}
/// Float percentage (0–100) to a progress bar width or colour.
public sealed class PercentToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var pct = System.Convert.ToSingle(value);
if (pct > 90) return new SolidColorBrush(Color.FromRgb(255, 69, 58)); // red
if (pct > 70) return new SolidColorBrush(Color.FromRgb(255, 159, 10)); // orange
return new SolidColorBrush(Color.FromRgb(48, 209, 88)); // green
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotSupportedException();
}
/// Null → Visibility (collapsed when null).
public sealed class NullToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> value is null ? Visibility.Collapsed : Visibility.Visible;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotSupportedException();
}
/// Format float to one decimal.
public sealed class FloatFormatConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var fmt = parameter as string ?? "F1";
return System.Convert.ToSingle(value).ToString(fmt);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotSupportedException();
}
/// Bool to boost button text.
public sealed class BoostButtonTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> value is true ? "⏹ STOP BOOST" : "🚀 BOOST GAME";
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotSupportedException();
}
/// Bool to brush (boost active colour).
public sealed class BoostButtonColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> value is true
? new SolidColorBrush(Color.FromRgb(255, 69, 58))
: new SolidColorBrush(Color.FromRgb(48, 209, 88));
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotSupportedException();
}