mirror of
https://github.com/DarthAffe/RGBSyncPlus
synced 2026-11-11 13:06:28 +00:00
Initial implementation
This commit is contained in:
1 parent
278e22020e
commit
fd662dcf34
63 files changed
+4881
No files matched your search
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace RGBSyncPlus.Converter
|
||||
{
|
||||
[ValueConversion(typeof(bool), typeof(Visibility))]
|
||||
public class BoolToVisibilityConverter : IValueConverter
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
=> (value as bool?) == true ? Visibility.Visible
|
||||
: (string.Equals(parameter?.ToString(), "true", StringComparison.OrdinalIgnoreCase) ? Visibility.Hidden : Visibility.Collapsed);
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => value as Visibility? == Visibility.Visible;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace RGBSyncPlus.Converter
|
||||
{
|
||||
[ValueConversion(typeof(object), typeof(bool))]
|
||||
public class EqualsToBoolConverter : IValueConverter
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => Equals(value, parameter);
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotSupportedException();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace RGBSyncPlus.Converter
|
||||
{
|
||||
[ValueConversion(typeof(object), typeof(Visibility))]
|
||||
public class NullToVisibilityConverter : IValueConverter
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
=> (value == null) == (string.Equals(parameter?.ToString(), "true", StringComparison.OrdinalIgnoreCase)) ? Visibility.Visible : Visibility.Hidden;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotSupportedException();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace RGBSyncPlus.Converter
|
||||
{
|
||||
public class ScrollOffsetToOpacityMaskConverter : IMultiValueConverter
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private static readonly Color TRANSPARENT = Color.FromArgb(0, 0, 0, 0);
|
||||
private static readonly Color OPAQUE = Color.FromArgb(255, 0, 0, 0);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double offset = double.Parse(values[0].ToString());
|
||||
double maxHeight = double.Parse(values[1].ToString());
|
||||
double height = double.Parse(values[2].ToString());
|
||||
|
||||
double transparencyHeight = double.Parse(parameter.ToString());
|
||||
double transparencyFactor = (transparencyHeight - 6) / height;
|
||||
double transparencyFadeFactor = (transparencyHeight + 4) / height;
|
||||
|
||||
bool top = !(Math.Abs(offset) < float.Epsilon);
|
||||
bool bot = !(Math.Abs(offset - maxHeight) < float.Epsilon);
|
||||
|
||||
if (!top && !bot) return new SolidColorBrush(OPAQUE);
|
||||
|
||||
GradientStopCollection gradientStops = new GradientStopCollection();
|
||||
if (top)
|
||||
{
|
||||
gradientStops.Add(new GradientStop(TRANSPARENT, 0.0));
|
||||
gradientStops.Add(new GradientStop(TRANSPARENT, transparencyFactor));
|
||||
gradientStops.Add(new GradientStop(OPAQUE, transparencyFadeFactor));
|
||||
}
|
||||
else
|
||||
gradientStops.Add(new GradientStop(OPAQUE, 0.0));
|
||||
|
||||
if (bot)
|
||||
{
|
||||
gradientStops.Add(new GradientStop(OPAQUE, 1.0 - transparencyFadeFactor));
|
||||
gradientStops.Add(new GradientStop(TRANSPARENT, 1.0 - transparencyFactor));
|
||||
gradientStops.Add(new GradientStop(TRANSPARENT, 1.0));
|
||||
}
|
||||
else
|
||||
gradientStops.Add(new GradientStop(OPAQUE, 1.0));
|
||||
|
||||
return new LinearGradientBrush(gradientStops, new Point(0.5, 0.0), new Point(0.5, 1.0));
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotSupportedException();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace RGBSyncPlus.Converter
|
||||
{
|
||||
// Based on: http://stackoverflow.com/a/28679767
|
||||
public class ScrollOffsetToVisibilityConverter : IMultiValueConverter
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
bool top = "top".Equals(parameter?.ToString(), StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
double offset = double.Parse(values[0].ToString());
|
||||
double maxHeight = double.Parse(values[1].ToString());
|
||||
|
||||
return (top && Math.Abs(offset) < float.Epsilon) || (!top && Math.Abs(offset - maxHeight) < float.Epsilon)
|
||||
? Visibility.Collapsed
|
||||
: Visibility.Visible;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotSupportedException();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user