Browse Source

Merge branch 'fixes/textProcessingBugs' of https://github.com/Gillibald/Avalonia into fixes/textProcessingBugs

pull/7746/head
Benedikt Stebner 4 years ago
parent
commit
b7df896fbc
  1. 6
      src/Avalonia.Diagnostics/Diagnostics/DevTools.cs
  2. 10
      src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs
  3. 62
      src/Avalonia.Visuals/Media/ExperimentalAcrylicMaterial.cs

6
src/Avalonia.Diagnostics/Diagnostics/DevTools.cs

@ -105,13 +105,15 @@ namespace Avalonia.Diagnostics
private static IDisposable Open(Application? application, DevToolsOptions options, Window? owner = default)
{
var focussedControl = KeyboardDevice.Instance?.FocusedElement as IControl;
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
if (s_open.TryGetValue(application, out var window))
{
{
window.Activate();
window.SelectedControl(focussedControl);
}
else
{
@ -122,7 +124,7 @@ namespace Avalonia.Diagnostics
Height = options.Size.Height,
};
window.SetOptions(options);
window.SelectedControl(focussedControl);
window.Closed += DevToolsClosed;
s_open.Add(application, window);
if (options.ShowAsChildWindow && owner is { })

10
src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs

@ -110,7 +110,7 @@ namespace Avalonia.Diagnostics.Views
{
#pragma warning disable CS0618 // Type or member is obsolete
var point = (topLevel as IInputRoot)?.MouseDevice?.GetPosition(topLevel) ?? default;
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore CS0618 // Type or member is obsolete
return (IControl?)topLevel.GetVisualsAt(point, x =>
{
@ -255,5 +255,13 @@ namespace Avalonia.Diagnostics.Views
}
}
}
internal void SelectedControl(IControl? control)
{
if (control is { })
{
(DataContext as MainViewModel)?.SelectControl(control);
}
}
}
}

62
src/Avalonia.Visuals/Media/ExperimentalAcrylicMaterial.cs

@ -142,52 +142,6 @@ namespace Avalonia.Media
Color IExperimentalAcrylicMaterial.TintColor => _effectiveTintColor;
private struct HsvColor
{
public float Hue { get; set; }
public float Saturation { get; set; }
public float Value { get; set; }
}
private static HsvColor RgbToHsv(Color color)
{
var r = color.R / 255.0f;
var g = color.G / 255.0f;
var b = color.B / 255.0f;
var max = Math.Max(r, Math.Max(g, b));
var min = Math.Min(r, Math.Min(g, b));
float h, s, v;
h = v = max;
var d = max - min;
s = max == 0 ? 0 : d / max;
if (max == min)
{
h = 0; // achromatic
}
else
{
if (max == r)
{
h = (g - b) / d + (g < b ? 6 : 0);
}
else if (max == g)
{
h = (b - r) / d + 2;
}
else if (max == b)
{
h = (r - g) / d + 4;
}
h /= 6;
}
return new HsvColor { Hue = h, Saturation = s, Value = v };
}
private static Color GetEffectiveTintColor(Color tintColor, double tintOpacity)
{
// Update tintColor's alpha with the combined opacity value
@ -198,7 +152,7 @@ namespace Avalonia.Media
private static double GetTintOpacityModifier(Color tintColor)
{
// This method supresses the maximum allowable tint opacity depending on the luminosity and saturation of a color by
// This method suppresses the maximum allowable tint opacity depending on the luminosity and saturation of a color by
// compressing the range of allowable values - for example, a user-defined value of 100% will be mapped to 45% for pure
// white (100% luminosity), 85% for pure black (0% luminosity), and 90% for pure gray (50% luminosity). The intensity of
// the effect increases linearly as luminosity deviates from 50%. After this effect is calculated, we cancel it out
@ -210,22 +164,22 @@ namespace Avalonia.Media
const double midPointMaxOpacity = 0.45; // 50% luminosity
const double blackMaxOpacity = 0.45; // 0% luminosity
var hsv = RgbToHsv(tintColor);
var hsv = tintColor.ToHsv();
double opacityModifier = midPointMaxOpacity;
if (hsv.Value != midPoint)
if (hsv.V != midPoint)
{
// Determine maximum suppression amount
double lowestMaxOpacity = midPointMaxOpacity;
double maxDeviation = midPoint;
if (hsv.Value > midPoint)
if (hsv.V > midPoint)
{
lowestMaxOpacity = whiteMaxOpacity; // At white (100% hsvV)
maxDeviation = 1 - maxDeviation;
}
else if (hsv.Value < midPoint)
else if (hsv.V < midPoint)
{
lowestMaxOpacity = blackMaxOpacity; // At black (0% hsvV)
}
@ -233,14 +187,14 @@ namespace Avalonia.Media
double maxOpacitySuppression = midPointMaxOpacity - lowestMaxOpacity;
// Determine normalized deviation from the midpoint
double deviation = Math.Abs(hsv.Value - midPoint);
double deviation = Math.Abs(hsv.V - midPoint);
double normalizedDeviation = deviation / maxDeviation;
// If we have saturation, reduce opacity suppression to allow that color to come through more
if (hsv.Saturation > 0)
if (hsv.S > 0)
{
// Dampen opacity suppression based on how much saturation there is
maxOpacitySuppression *= Math.Max(1 - (hsv.Saturation * 2), 0.0);
maxOpacitySuppression *= Math.Max(1 - (hsv.S * 2), 0.0);
}
double opacitySuppression = maxOpacitySuppression * normalizedDeviation;

Loading…
Cancel
Save